CGEM BOSS 6.6.5.g
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 59 of file MdcMergeDups.cxx.

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

◆ ~MdcMergeDups()

MdcMergeDups::~MdcMergeDups ( )
virtual

Definition at line 78 of file MdcMergeDups.cxx.

78 {
79 delete m_bfield;
80}

Member Function Documentation

◆ beginRun()

StatusCode MdcMergeDups::beginRun ( )

Definition at line 82 of file MdcMergeDups.cxx.

82 {
83 //Detector geometry
84 m_gm = MdcDetector::instance();
85 if(NULL == m_gm) return StatusCode::FAILURE;
86 return StatusCode::SUCCESS;
87}
static MdcDetector * instance()
Definition: MdcDetector.cxx:21

◆ doMergeCurl()

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

Definition at line 407 of file MdcMergeDups.cxx.

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

Referenced by mergeCurl().

◆ doMergeLong()

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

Definition at line 270 of file MdcMergeDups.cxx.

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

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

Referenced by execute().

◆ eraseTdsTrack()

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

Definition at line 455 of file MdcMergeDups.cxx.

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

Referenced by mergeCurl().

◆ execute()

StatusCode MdcMergeDups::execute ( )

Definition at line 111 of file MdcMergeDups.cxx.

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

◆ finalize()

StatusCode MdcMergeDups::finalize ( )

Definition at line 140 of file MdcMergeDups.cxx.

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

◆ initialize()

StatusCode MdcMergeDups::initialize ( )

Definition at line 92 of file MdcMergeDups.cxx.

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

◆ mergeCurl()

int MdcMergeDups::mergeCurl ( void  )

Definition at line 149 of file MdcMergeDups.cxx.

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

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

◆ testByOverlapHit()

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

Definition at line 348 of file MdcMergeDups.cxx.

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

Referenced by mergeCurl().

◆ testByParam()

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

Definition at line 222 of file MdcMergeDups.cxx.

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