29#include "GaudiKernel/MsgStream.h"
30#include "GaudiKernel/AlgFactory.h"
31#include "GaudiKernel/ISvcLocator.h"
32#include "GaudiKernel/DataSvc.h"
33#include "GaudiKernel/SmartDataPtr.h"
34#include "GaudiKernel/IDataProviderSvc.h"
35#include "GaudiKernel/IDataManagerSvc.h"
36#include "GaudiKernel/PropertyMgr.h"
38#include "MagneticField/IMagneticFieldSvc.h"
60 Algorithm(name, pSvcLocator)
62 declareProperty(
"debug", m_debug = 0);
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.);
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);
85 if(NULL == m_gm)
return StatusCode::FAILURE;
86 return StatusCode::SUCCESS;
93 MsgStream log(
msgSvc(), name());
94 log << MSG::INFO <<
"in initialize()" << endreq;
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;
105 m_bfield =
new BField(m_pIMF);
107 return StatusCode::SUCCESS;
112 MsgStream log(
msgSvc(), name());
113 log << MSG::INFO <<
"in execute()" << endreq;
114 setFilterPassed(
false);
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;
123 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
124 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
125 m_bunchT0 = (*iter_evt)->getTest();
132 std::cout<<name()<<
": Merged "<<nMerged <<
" track "<< std::endl;
136 return StatusCode::SUCCESS;
141 MsgStream log(
msgSvc(), name());
142 log << MSG::INFO <<
"in finalize()" << endreq;
144 return StatusCode::SUCCESS;
153 if (!trackList)
return -1;
158 RecMdcTrackCol::iterator iterRefTk = trackList->begin();
159 for (; iterRefTk != trackList->end(); iterRefTk++) {
161 if (refTk->
stat()<0)
continue;
162 std::vector<RecMdcTrack*> mergeTkList;
163 mergeTkList.push_back(refTk);
168 RecMdcTrackCol::iterator iterTestTk = trackList->begin();
169 for (; iterTestTk != trackList->end(); iterTestTk++) {
171 if (iterRefTk == iterTestTk || (testTk->
stat()<0))
continue;
175 if(m_debug>0)std::cout<<__FILE__<<
" overlape tk:" <<refTk->
trackId()<<
" with "<<testTk->
trackId()<< std::endl;
176 mergeTkList.push_back(testTk);
181 if(m_debug>0) std::cout<<__FILE__<<
" same param tk:" <<refTk->
trackId()<<
" with "<<testTk->
trackId()<< std::endl;
182 mergeTkList.push_back(testTk);
185 if (mergeTkList.size()>1 && curl) needMerge =
doMergeCurl(mergeTkList);
186 if ((needMerge < 999) && mergeTkList.size()>1 ) needMerge =
doMergeLong(mergeTkList);
191 if( needMerge <=0 )
return 0;
194 iterRefTk = trackList->begin();
197 for (; iterRefTk != trackList->end(); ) {
198 if ( (*iterRefTk)->stat() >= 0 ){
199 (*iterRefTk)->setTrackId(iTk);
203 int id = (*iterRefTk)->trackId();
207 if(m_debug>0)std::cout<<__FILE__<<
" erase track No."<<
id<< std::endl;
209 if(m_debug>0)std::cout<<__FILE__<<
" erase failed !"<< std::endl;
214 if(m_debug>0) std::cout<<__FILE__<<
" After merge save "<<iTk<<
" tracks"<< std::endl;
228 double Bz = m_bfield->
bFieldZ();
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;
243 if (fabs(omega1)>0.00001) r1 = 1.0/fabs(omega1);
244 if (fabs(omega2)>0.00001) r2 = 1.0/fabs(omega2);
245 double pdrad = fabs((r1-r2)/(r1+r2)) ;
248 std::cout <<
" fabs(d01 - d02) " << fabs(d01 - d02) << std::endl;
249 std::cout <<
" fabs(phi01-phi02) " << fabs(phi01-phi02) << std::endl;
252 if ( (prodo > 0.) && (dd0 < m_maxDd0InMerge) && (dphi0 < m_maxDphi0InMerge) &&
253 (pdrad < m_maxPdradInMerge)) {
258 if ( (prodo < 0.) && (fabs(d01+d02) < 4.0) && (dd0 > 47.0) &&
260 && (pdrad < m_maxPdradInMerge)) {
276 std::vector<RecMdcTrack*>::iterator itTk = mergeTkList.begin();
277 for (
int iTk=0; itTk != mergeTkList.end(); itTk++,iTk++){
279 double chi2 = tk->
chi2();
280 double ndf = tk->
ndof();
281 if(chi2/ndf < minRcs) {
286 if (minRcs < m_maxRcsInMerge)
return bestTkId;
351 if ((testTk->
pxy() >= m_mergePt) || (refTk->
pxy() >= m_mergePt))
return overlaped;
354 int nHit = testHits.size();
357 HitRefVec::iterator iterHit = testHits.begin();
358 for (; iterHit != testHits.end(); iterHit++) {
362 double load = m_mergeLoadAx;
364 if(isStLayer) load = m_mergeLoadSt;
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();
374 double dz = refTk->
helix(3);
375 double tanl = refTk->
helix(4);
378 double xc = vx0 + (dr + r) *
cos(phi0);
379 double yc = vy0 + (dr + r) *
sin(phi0);
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));
388 double dx = xc - xHit;
389 double dy = yc - yHit;
390 double dHit2Center = sqrt(dx * dx + dy * dy);
391 double rTk = fabs(r);
394 if ( (dHit2Center>(rTk - load)) && (dHit2Center<(rTk + load))) nOverlap++;
397 if ( nOverlap<=0 )
return overlaped;
399 double overlapRatio = double(nOverlap) / double(nHit);
401 if (overlapRatio > m_mergeOverlapRatio) overlaped = 1;
409 int innerMostTkId = 999;
411 unsigned innerMostLayerOfTk = 999;
412 std::vector<RecMdcTrack*>::iterator itTk = mergeTkList.begin();
413 for (
int iTk=0; itTk != mergeTkList.end(); itTk++,iTk++){
415 unsigned innerMostLayer = 999;
416 for (
unsigned iHit = 0; iHit < tk->
getVecHits().size(); iHit++) {
418 if (layer < innerMostLayer) innerMostLayer=layer;
421 if(m_debug>0)std::cout<<__FILE__<<
" to be merged track id="<<tk->
trackId()<< std::endl;
423 if(innerMostLayer < innerMostLayerOfTk){
426 }
else if (innerMostLayer == innerMostLayerOfTk) {
436 return innerMostTkId;
441 if (!trackList)
return;
443 if (!hitList)
return;
445 assert (aTrack != NULL);
448 if(m_debug>1)std::cout<<__FILE__<<
" STORED"<< std::endl;
452 mdcTrack.
storeTrack(-1, trackList, hitList, tkStat);
457 if (!trackList)
return false;
459 if (!hitList)
return false;
461 HitRefVec::iterator iterHit = hits.begin();
462 for (; iterHit != hits.end(); iterHit++) {
465 trackList->erase(tk);
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++){
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)
486 std::cout<<
" q "<<tk->
charge()
487 <<
" theta "<<tk->
theta()
494 std::cout <<
" p "<<tk->
p()
500 std::cout<<
" tkStat "<<tk->
stat()
501 <<
" chi2 "<<tk->
chi2()
502 <<
" ndof "<<tk->
ndof()
504 <<
" nst "<<tk->
nster()
511 std::cout<<
nhits <<
" Hits: " << std::endl;
512 for(
int ii=0; ii <
nhits ; ii++){
516 cout<<
"("<< layer <<
","<<wire<<
","<<tk->
getVecHits()[ii]->getStat()
517 <<
",lr:"<<tk->
getVecHits()[ii]->getFlagLR()<<
") ";
519 std::cout <<
" "<< std::endl;
521 std::cout <<
" "<< std::endl;
double sin(const BesAngle a)
double cos(const BesAngle a)
SmartRefVector< RecMdcHit > HitRefVec
static const double twoPi
const double theta() const
const double chi2() const
void setStat(const int stat)
const int trackId() const
const HepVector helix() const
......
const MdcLayer * Layer(unsigned id) const
static MdcDetector * instance()
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
int doMergeLong(std::vector< RecMdcTrack * > mergeTkList)
int testByParam(RecMdcTrack *refTk, RecMdcTrack *testTk)
void store(TrkRecoTrk *aTrack)
bool eraseTdsTrack(RecMdcTrackCol::iterator tk)
int testByOverlapHit(RecMdcTrack *refTk, RecMdcTrack *testTk)
int doMergeCurl(std::vector< RecMdcTrack * > mergeTkList)
MdcMergeDups(const std::string &name, ISvcLocator *pSvcLocator)
void storeTrack(int trackId, RecMdcTrackCol *trackList, RecMdcHitCol *hitList, int tkStat)
const double getZhit(void) const
const Identifier getMdcId(void) const
const double getVZ0() const
const HitRefVec getVecHits(void) const
const double getVY0() const
const int getNhits() const
const double getVX0() const
virtual TrkExchangePar helix(double fltL) const =0
const TrkFit * fitResult() const
_EXTERN_ std::string RecMdcTrackCol
_EXTERN_ std::string RecMdcHitCol