BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcMergeDups Class Reference

#include <MdcMergeDups.h>

+ Inheritance diagram for MdcMergeDups:

Public Member Functions

 MdcMergeDups (const std::string &name, ISvcLocator *pSvcLocator)
 
virtual ~MdcMergeDups ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
StatusCode beginRun ()
 
int mergeDups (void)
 
int mergeCurl (void)
 
int testByOverlapHit (RecMdcTrack *refTk, RecMdcTrack *testTk)
 
int testByParam (RecMdcTrack *refTk, RecMdcTrack *testTk)
 
int doMergeLong (std::vector< RecMdcTrack * > mergeTkList)
 
int doMergeCurl (std::vector< RecMdcTrack * > mergeTkList)
 
void store (TrkRecoTrk *aTrack)
 
bool eraseTdsTrack (RecMdcTrackCol::iterator tk)
 
void dumpRecMdcTrack ()
 

Detailed Description

Definition at line 46 of file MdcMergeDups.h.

Constructor & Destructor Documentation

◆ MdcMergeDups()

MdcMergeDups::MdcMergeDups ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 60 of file MdcMergeDups.cxx.

60 :
61 Algorithm(name, pSvcLocator)
62{
63 declareProperty("debug", m_debug = 0);
64 //cuts for mergeDups()
65 declareProperty("maxDd0InMerge", m_maxDd0InMerge = 2.7);
66 declareProperty("maxDphi0InMerge", m_maxDphi0InMerge = 0.15);
67 declareProperty("maxDPdradInMerge", m_maxPdradInMerge= 0.22);
68 declareProperty("maxRcsInMerge", m_maxRcsInMerge = 18.);
69 //cuts for mergeCurl()
70 declareProperty("mergePt", m_mergePt = 0.13);
71 declareProperty("mergeLoadAx", m_mergeLoadAx = 3.);
72 declareProperty("mergeLoadSt", m_mergeLoadSt = 4.);
73 declareProperty("mergeOverlapRatio", m_mergeOverlapRatio = 0.7);
74}

◆ ~MdcMergeDups()

MdcMergeDups::~MdcMergeDups ( )
virtual

Definition at line 79 of file MdcMergeDups.cxx.

79 {
80 delete m_bfield;
81}

Member Function Documentation

◆ beginRun()

StatusCode MdcMergeDups::beginRun ( )

Definition at line 83 of file MdcMergeDups.cxx.

83 {
84 //Detector geometry
85 m_gm = MdcDetector::instance();
86 if(NULL == m_gm) return StatusCode::FAILURE;
87 return StatusCode::SUCCESS;
88}
#define NULL
static MdcDetector * instance()

◆ doMergeCurl()

int MdcMergeDups::doMergeCurl ( std::vector< RecMdcTrack * > mergeTkList)

Definition at line 408 of file MdcMergeDups.cxx.

408 {
409 //-------------------------------------------------------------------
410 int innerMostTkId = 999;
411 RecMdcTrack* innerMostTk = NULL;
412 unsigned innerMostLayerOfTk = 999;
413 std::vector<RecMdcTrack*>::iterator itTk = mergeTkList.begin();
414 for (int iTk=0; itTk != mergeTkList.end(); itTk++,iTk++){
415 RecMdcTrack* tk = (*itTk);
416 unsigned innerMostLayer = 999;
417 for (unsigned iHit = 0; iHit < tk->getVecHits().size(); iHit++) {
418 unsigned layer = MdcID::layer(tk->getVecHits()[iHit]->getMdcId());
419 if (layer < innerMostLayer) innerMostLayer=layer;
420 }
421
422 if(m_debug>0)std::cout<<__FILE__<<" to be merged track id="<<tk->trackId()<< std::endl;
423 // test inner most layer id; if same, test dz
424 if(innerMostLayer < innerMostLayerOfTk){
425 innerMostTkId = iTk;
426 innerMostTk = tk;
427 }else if (innerMostLayer == innerMostLayerOfTk) {
428 // test by dz
429 if (tk->helix(3) < innerMostTk->helix(3)){
430 innerMostTkId = iTk;
431 innerMostTk = tk;
432 }
433 }
434 }//end of for mergeTkList
435 innerMostTk->setStat(-1);
436
437 return innerMostTkId;
438}
void setStat(const int stat)
Definition DstMdcTrack.h:95
const int trackId() const
Definition DstMdcTrack.h:52
const HepVector helix() const
......
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition MdcID.cxx:49
const HitRefVec getVecHits(void) const
Definition RecMdcTrack.h:60

Referenced by mergeCurl().

◆ doMergeLong()

int MdcMergeDups::doMergeLong ( std::vector< RecMdcTrack * > mergeTkList)

Definition at line 271 of file MdcMergeDups.cxx.

271 {
272 //-------------------------------------------------------------------
273 //merge hitlist
274 double minRcs=999.;
275 int bestTkId=999;
276 RecMdcTrack* bestTk=NULL;
277 std::vector<RecMdcTrack*>::iterator itTk = mergeTkList.begin();
278 for (int iTk=0; itTk != mergeTkList.end(); itTk++,iTk++){
279 RecMdcTrack* tk = (*itTk);
280 double chi2 = tk->chi2();
281 double ndf = tk->ndof();
282 if(chi2/ndf < minRcs) {
283 bestTkId = tk->trackId();
284 bestTk = tk;
285 }
286 }
287 if (minRcs < m_maxRcsInMerge) return bestTkId;
288 bestTk->setStat(-1);
289
290 return 999;
291 //FIXME
292 /*
293 //fit with track parameter respectively
294 MdcxFittedHel fit1(dcxhlist, *iptr);
295 MdcxFittedHel fit2(dcxhlist, *trkl[j]);
296 int uf = 0;
297 //get a best fit
298 if ( !fit1.Fail() && (fit1.Rcs()<m_maxRcsInMerge) ) uf = 1;
299 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
300
301 if (uf) {//two fit all ok
302 //delete bad track
303 MdcxHel fitme = (uf == 1) ? fit1 : fit2;
304 }
305 */
306}
const double chi2() const
Definition DstMdcTrack.h:66
const int ndof() const
Definition DstMdcTrack.h:67

Referenced by mergeCurl().

◆ dumpRecMdcTrack()

void MdcMergeDups::dumpRecMdcTrack ( )

Definition at line 471 of file MdcMergeDups.cxx.

471 {
472 SmartDataPtr<RecMdcTrackCol> trackList(eventSvc(),EventModel::Recon::RecMdcTrackCol);
473 if (!trackList) return;
474 if (trackList->size() != 4 ) setFilterPassed(true);
475 std::cout<<"N track after Merged = "<<trackList->size() << std::endl;
476 if (m_debug <=1) return;
477 RecMdcTrackCol::iterator it = trackList->begin();
478 for (;it!= trackList->end();it++){
479 RecMdcTrack *tk = *it;
480 std::cout<< "//====RecMdcTrack "<<tk->trackId()<<"====:" << std::endl;
481 cout <<" d0 "<<tk->helix(0)
482 <<" phi0 "<<tk->helix(1)
483 <<" cpa "<<tk->helix(2)
484 <<" z0 "<<tk->helix(3)
485 <<" tanl "<<tk->helix(4)
486 <<endl;
487 std::cout<<" q "<<tk->charge()
488 <<" theta "<<tk->theta()
489 <<" phi "<<tk->phi()
490 <<" x0 "<<tk->x()
491 <<" y0 "<<tk->y()
492 <<" z0 "<<tk->z()
493 <<" r0 "<<tk->r()
494 <<endl;
495 std::cout <<" p "<<tk->p()
496 <<" pt "<<tk->pxy()
497 <<" px "<<tk->px()
498 <<" py "<<tk->py()
499 <<" pz "<<tk->pz()
500 <<endl;
501 std::cout<<" tkStat "<<tk->stat()
502 <<" chi2 "<<tk->chi2()
503 <<" ndof "<<tk->ndof()
504 <<" nhit "<<tk->getNhits()
505 <<" nst "<<tk->nster()
506 <<endl;
507 //std::cout<< "errmat " << std::endl;
508 //for (int i=0; i<15; i++){ std::cout<< " "<<tk->err(i); }
509 //std::cout<< " " << std::endl;
510
511 int nhits = tk->getVecHits().size();
512 std::cout<<nhits <<" Hits: " << std::endl;
513 for(int ii=0; ii <nhits ; ii++){
514 Identifier id(tk->getVecHits()[ii]->getMdcId());
515 int layer = MdcID::layer(id);
516 int wire = MdcID::wire(id);
517 cout<<"("<< layer <<","<<wire<<","<<tk->getVecHits()[ii]->getStat()
518 <<",lr:"<<tk->getVecHits()[ii]->getFlagLR()<<") ";
519 }//end of hit list
520 std::cout << " "<< std::endl;
521 }//end of tk list
522 std::cout << " "<< std::endl;
523}
const double theta() const
Definition DstMdcTrack.h:59
const double r() const
Definition DstMdcTrack.h:64
const double py() const
Definition DstMdcTrack.h:56
const int charge() const
Definition DstMdcTrack.h:53
const double px() const
Definition DstMdcTrack.h:55
const double phi() const
Definition DstMdcTrack.h:60
const double pz() const
Definition DstMdcTrack.h:57
const double pxy() const
Definition DstMdcTrack.h:54
const int stat() const
Definition DstMdcTrack.h:65
const double z() const
Definition DstMdcTrack.h:63
const double p() const
Definition DstMdcTrack.h:58
const int nster() const
Definition DstMdcTrack.h:68
const double y() const
Definition DstMdcTrack.h:62
const double x() const
Definition DstMdcTrack.h:61
static int wire(const Identifier &id)
Definition MdcID.cxx:54
const int getNhits() const
Definition RecMdcTrack.h:49
_EXTERN_ std::string RecMdcTrackCol
Definition EventModel.h:86
int nhits

Referenced by execute().

◆ eraseTdsTrack()

bool MdcMergeDups::eraseTdsTrack ( RecMdcTrackCol::iterator tk)

Definition at line 456 of file MdcMergeDups.cxx.

456 {
457 SmartDataPtr<RecMdcTrackCol> trackList(eventSvc(),EventModel::Recon::RecMdcTrackCol);
458 if (!trackList) return false;
459 SmartDataPtr<RecMdcHitCol> hitList(eventSvc(),EventModel::Recon::RecMdcHitCol);
460 if (!hitList) return false;
461 HitRefVec hits = (*tk)->getVecHits();
462 HitRefVec::iterator iterHit = hits.begin();
463 for (; iterHit != hits.end(); iterHit++) {
464 //hitList->erase(iterHit);
465 }
466 trackList->erase(tk);
467 return true;
468}
SmartRefVector< RecMdcHit > HitRefVec
Definition RecMdcTrack.h:22
_EXTERN_ std::string RecMdcHitCol
Definition EventModel.h:85

Referenced by mergeCurl().

◆ execute()

StatusCode MdcMergeDups::execute ( )

Definition at line 112 of file MdcMergeDups.cxx.

112 {
113 MsgStream log(msgSvc(), name());
114 log << MSG::INFO << "in execute()" << endreq;
115 setFilterPassed(false);
116
117 m_bunchT0 = -999.;
118 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
119 if (!aevtimeCol || aevtimeCol->size()==0) {
120 log << MSG::WARNING<< " Could not find RecEsTimeCol"<< endreq;
121 return StatusCode::SUCCESS;
122 }
123
124 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
125 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
126 m_bunchT0 = (*iter_evt)->getTest();
127 }
128
129
130 int nMerged = mergeCurl();
131
132 if(m_debug>0) {
133 std::cout<<name()<<": Merged "<<nMerged << " track "<< std::endl;
135 }
136
137 return StatusCode::SUCCESS;
138}
IMessageSvc * msgSvc()
void dumpRecMdcTrack()
int mergeCurl(void)

◆ finalize()

StatusCode MdcMergeDups::finalize ( )

Definition at line 141 of file MdcMergeDups.cxx.

141 {
142 MsgStream log(msgSvc(), name());
143 log << MSG::INFO << "in finalize()" << endreq;
144
145 return StatusCode::SUCCESS;
146}

◆ initialize()

StatusCode MdcMergeDups::initialize ( )

Definition at line 93 of file MdcMergeDups.cxx.

93 {
94 MsgStream log(msgSvc(), name());
95 log << MSG::INFO << "in initialize()" << endreq;
96 StatusCode sc;
97
98
99 //Initailize magnetic filed
100 IMagneticFieldSvc* m_pIMF;
101 sc = service ("MagneticFieldSvc",m_pIMF);
102 if(sc != StatusCode::SUCCESS) {
103 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
104 return StatusCode::FAILURE;
105 }
106 m_bfield = new BField(m_pIMF);
107
108 return StatusCode::SUCCESS;
109}

◆ mergeCurl()

int MdcMergeDups::mergeCurl ( void )

Definition at line 150 of file MdcMergeDups.cxx.

150 {
151 //-------------------------------------------------------------------
152
153 SmartDataPtr<RecMdcTrackCol> trackList(eventSvc(),EventModel::Recon::RecMdcTrackCol);
154 if (!trackList) return -1;
155
156 int needMerge = 0;
157
158 //...Merging. Search a track to be merged...
159 RecMdcTrackCol::iterator iterRefTk = trackList->begin();
160 for (; iterRefTk != trackList->end(); iterRefTk++) {
161 RecMdcTrack* refTk = *iterRefTk;
162 if (refTk->stat()<0) continue;
163 std::vector<RecMdcTrack*> mergeTkList;
164 mergeTkList.push_back(refTk);
165
166
167 bool curl = false;
168 int sameParm = 0;
169 RecMdcTrackCol::iterator iterTestTk = trackList->begin();
170 for (; iterTestTk != trackList->end(); iterTestTk++) {
171 RecMdcTrack* testTk = *iterTestTk;
172 if (iterRefTk == iterTestTk || (testTk->stat()<0)) continue;
173
174 //-- overlapRatio cut 0.7 by jialk, original is 0.8
175 if (testByOverlapHit(refTk,testTk)){
176 if(m_debug>0)std::cout<<__FILE__<<" overlape tk:" <<refTk->trackId()<<" with "<<testTk->trackId()<< std::endl;
177 mergeTkList.push_back(testTk);
178 curl = true;
179 }
180 sameParm = testByParam(refTk,testTk);
181 if(sameParm >0) {
182 if(m_debug>0) std::cout<<__FILE__<<" same param tk:" <<refTk->trackId()<<" with "<<testTk->trackId()<< std::endl;
183 mergeTkList.push_back(testTk);
184 }
185 }
186 if (mergeTkList.size()>1 && curl) needMerge = doMergeCurl(mergeTkList);
187 if ((needMerge < 999) && mergeTkList.size()>1 ) needMerge = doMergeLong(mergeTkList);
188 //if ((needMerge <999) && mergeTkList.size()==2 && (sameParm==2) ) needMerge = doMergeOdd(mergeTkList); //FIXME
189 }
190
191 //return 0 if No track need merged
192 if( needMerge <=0 ) return 0;
193
194 // reset track Id
195 iterRefTk = trackList->begin();
196 int iTk=0;
197 int nDeleted = 0;
198 for (; iterRefTk != trackList->end(); ) {
199 if ( (*iterRefTk)->stat() >= 0 ){
200 (*iterRefTk)->setTrackId(iTk);
201 iterRefTk++;
202 iTk++;
203 }else {
204 int id = (*iterRefTk)->trackId();
205 bool erased = eraseTdsTrack(iterRefTk);
206 if ( erased ){
207 nDeleted++;
208 if(m_debug>0)std::cout<<__FILE__<<" erase track No."<<id<< std::endl;
209 }else {
210 if(m_debug>0)std::cout<<__FILE__<<" erase failed !"<< std::endl;
211 }
212 }
213
214 }
215 if(m_debug>0) std::cout<<__FILE__<<" After merge save "<<iTk<<" tracks"<< std::endl;
216
217 return nDeleted;
218}
int doMergeLong(std::vector< RecMdcTrack * > mergeTkList)
int testByParam(RecMdcTrack *refTk, RecMdcTrack *testTk)
bool eraseTdsTrack(RecMdcTrackCol::iterator tk)
int testByOverlapHit(RecMdcTrack *refTk, RecMdcTrack *testTk)
int doMergeCurl(std::vector< RecMdcTrack * > mergeTkList)

Referenced by execute().

◆ mergeDups()

int MdcMergeDups::mergeDups ( void )

◆ store()

void MdcMergeDups::store ( TrkRecoTrk * aTrack)

Definition at line 440 of file MdcMergeDups.cxx.

440 {
441 SmartDataPtr<RecMdcTrackCol> trackList(eventSvc(),EventModel::Recon::RecMdcTrackCol);
442 if (!trackList) return;
443 SmartDataPtr<RecMdcHitCol> hitList(eventSvc(),EventModel::Recon::RecMdcHitCol);
444 if (!hitList) return;
445
446 assert (aTrack != NULL);
447 TrkExchangePar helix = aTrack->fitResult()->helix(0.);
448
449 if(m_debug>1)std::cout<<__FILE__<<" STORED"<< std::endl;
450 MdcTrack mdcTrack(aTrack);//aTrack have been deleted in ~MdcTrack()
451 //tkStat: 0,Tsf 1,CurlFinder 2,PatRec 3,MdcxReco 4,MergeCurl
452 int tkStat = 4;
453 mdcTrack.storeTrack(-1, trackList, hitList, tkStat);
454}
virtual TrkExchangePar helix(double fltL) const =0
const TrkFit * fitResult() const

◆ testByOverlapHit()

int MdcMergeDups::testByOverlapHit ( RecMdcTrack * refTk,
RecMdcTrack * testTk )

Definition at line 349 of file MdcMergeDups.cxx.

349 {
350 //-------------------------------------------------------------------
351 int overlaped = 0;
352 if ((testTk->pxy() >= m_mergePt) || (refTk->pxy() >= m_mergePt)) return overlaped;
353
354 HitRefVec testHits = testTk->getVecHits();
355 int nHit = testHits.size();
356 int nOverlap = 0;
357
358 HitRefVec::iterator iterHit = testHits.begin();
359 for (; iterHit != testHits.end(); iterHit++) {
360 RecMdcHit* hit = *iterHit;
361
362 //-- load for Axial and Stereo layer are 3,4 by jialk, original is 2,3
363 double load = m_mergeLoadAx;
364 bool isStLayer = (m_gm->Layer(MdcID::layer(hit->getMdcId()))->view() != 0);
365 if(isStLayer) load = m_mergeLoadSt;
366
367 //helix parameters
368 double vx0 = refTk->getVX0();
369 double vy0 = refTk->getVY0();
370 double vz0 = refTk->getVZ0();
371 double dr = refTk->helix(0);
372 double phi0 = refTk->helix(1);
373 double Bz = m_bfield->bFieldZ();
374 double r = 10000./ (Constants::c * Bz*refTk->helix(2));
375 double dz = refTk->helix(3);
376 double tanl = refTk->helix(4);
377
378 //center of circle
379 double xc = vx0 + (dr + r) * cos(phi0);
380 double yc = vy0 + (dr + r) * sin(phi0);
381
382 //position of hit
383 double zHit = hit->getZhit();
384 double phi = (vz0 + dz - zHit) / (r * tanl);
385 double xHit = vx0 + dr*cos(phi0) + r*(cos(phi0) - cos(phi0+phi));
386 double yHit = vy0 + dr*sin(phi0) + r*(sin(phi0) - sin(phi0+phi));
387
388 //distance from center of circle to hit
389 double dx = xc - xHit;
390 double dy = yc - yHit;
391 double dHit2Center = sqrt(dx * dx + dy * dy);
392 double rTk = fabs(r);
393
394 //is this hit overlaped ?
395 if ( (dHit2Center>(rTk - load)) && (dHit2Center<(rTk + load))) nOverlap++;
396 }
397
398 if ( nOverlap<=0 ) return overlaped;
399
400 double overlapRatio = double(nOverlap) / double(nHit);
401
402 if (overlapRatio > m_mergeOverlapRatio) overlaped = 1;
403
404 return overlaped;
405}
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
static const double c
Definition Constants.h:43
const MdcLayer * Layer(unsigned id) const
Definition MdcDetector.h:33
int view(void) const
Definition MdcLayer.h:28
const double getZhit(void) const
Definition RecMdcHit.h:55
const Identifier getMdcId(void) const
Definition RecMdcHit.h:49
const double getVZ0() const
Definition RecMdcTrack.h:45
const double getVY0() const
Definition RecMdcTrack.h:44
const double getVX0() const
Definition RecMdcTrack.h:43

Referenced by mergeCurl().

◆ testByParam()

int MdcMergeDups::testByParam ( RecMdcTrack * refTk,
RecMdcTrack * testTk )

Definition at line 223 of file MdcMergeDups.cxx.

223 {
224 //-------------------------------------------------------------------
225 int overlaped = 0;
226
227
228 //Convert to Babar track convension
229 double Bz = m_bfield->bFieldZ();
230 double omega1 = (Constants::c * Bz*refTk->helix(2))/10000.;
231 double omega2 = (Constants::c * Bz*testTk->helix(2))/10000.;
232 //phi0_babar = phi0_belle + pi/2 [0,2pi)
233 double phi01 = refTk->helix(1)+Constants::pi/2.;
234 double phi02 = testTk->helix(1)+Constants::pi/2.;
235 while(phi01>Constants::twoPi) phi01 -= Constants::twoPi;
236 while(phi02>Constants::twoPi) phi02 -= Constants::twoPi;
237 double d01 = -refTk->helix(0);
238 double d02 = -testTk->helix(0);
239 double dphi0 = fabs(phi01 - phi02);
240 double dd0 = fabs(d01 - d02);
241 double prodo = omega1*omega2;
242 double r1=100000.;
243 double r2=100000.;
244 if (fabs(omega1)>0.00001) r1 = 1.0/fabs(omega1);
245 if (fabs(omega2)>0.00001) r2 = 1.0/fabs(omega2); //FIXME
246 double pdrad = fabs((r1-r2)/(r1+r2)) ;
247
248 if (2==m_debug){
249 std::cout << " fabs(d01 - d02) " << fabs(d01 - d02) << std::endl;
250 std::cout << " fabs(phi01-phi02) " << fabs(phi01-phi02) << std::endl;
251 }
252 // Try to merge pair that looks like duplicates (same charge)
253 if ( (prodo > 0.) && (dd0 < m_maxDd0InMerge) && (dphi0 < m_maxDphi0InMerge) &&
254 (pdrad < m_maxPdradInMerge)) {
255 overlaped = 1;
256 }
257
258 // Try to merge pair that looks like albedo (opp charge, large d0)
259 if ( (prodo < 0.) && (fabs(d01+d02) < 4.0) && (dd0 > 47.0) &&
260 (fabs( dphi0 - Constants::pi) < m_maxDphi0InMerge)
261 && (pdrad < m_maxPdradInMerge)) {
262 overlaped = 2;
263 }
264
265 return overlaped;
266}
static const double pi
Definition Constants.h:38
static const double twoPi
Definition Constants.h:39

Referenced by mergeCurl().


The documentation for this class was generated from the following files: