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"
61 Algorithm(name, pSvcLocator)
63 declareProperty(
"debug",
m_debug = 0);
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.);
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);
86 if(
NULL == m_gm)
return StatusCode::FAILURE;
87 return StatusCode::SUCCESS;
94 MsgStream log(
msgSvc(), name());
95 log << MSG::INFO <<
"in initialize()" << endreq;
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;
106 m_bfield =
new BField(m_pIMF);
108 return StatusCode::SUCCESS;
113 MsgStream log(
msgSvc(), name());
114 log << MSG::INFO <<
"in execute()" << endreq;
115 setFilterPassed(
false);
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;
124 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
125 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
126 m_bunchT0 = (*iter_evt)->getTest();
133 std::cout<<name()<<
": Merged "<<nMerged <<
" track "<< std::endl;
137 return StatusCode::SUCCESS;
142 MsgStream log(
msgSvc(), name());
143 log << MSG::INFO <<
"in finalize()" << endreq;
145 return StatusCode::SUCCESS;
154 if (!trackList)
return -1;
159 RecMdcTrackCol::iterator iterRefTk = trackList->begin();
160 for (; iterRefTk != trackList->end(); iterRefTk++) {
162 if (refTk->
stat()<0)
continue;
163 std::vector<RecMdcTrack*> mergeTkList;
164 mergeTkList.push_back(refTk);
169 RecMdcTrackCol::iterator iterTestTk = trackList->begin();
170 for (; iterTestTk != trackList->end(); iterTestTk++) {
172 if (iterRefTk == iterTestTk || (testTk->
stat()<0))
continue;
176 if(m_debug>0)std::cout<<__FILE__<<
" overlape tk:" <<refTk->
trackId()<<
" with "<<testTk->
trackId()<< std::endl;
177 mergeTkList.push_back(testTk);
182 if(m_debug>0) std::cout<<__FILE__<<
" same param tk:" <<refTk->
trackId()<<
" with "<<testTk->
trackId()<< std::endl;
183 mergeTkList.push_back(testTk);
186 if (mergeTkList.size()>1 && curl) needMerge =
doMergeCurl(mergeTkList);
187 if ((needMerge < 999) && mergeTkList.size()>1 ) needMerge =
doMergeLong(mergeTkList);
192 if( needMerge <=0 )
return 0;
195 iterRefTk = trackList->begin();
198 for (; iterRefTk != trackList->end(); ) {
199 if ( (*iterRefTk)->stat() >= 0 ){
200 (*iterRefTk)->setTrackId(iTk);
204 int id = (*iterRefTk)->trackId();
208 if(m_debug>0)std::cout<<__FILE__<<
" erase track No."<<
id<< std::endl;
210 if(m_debug>0)std::cout<<__FILE__<<
" erase failed !"<< std::endl;
215 if(m_debug>0) std::cout<<__FILE__<<
" After merge save "<<iTk<<
" tracks"<< std::endl;
229 double Bz = m_bfield->
bFieldZ();
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;
244 if (fabs(omega1)>0.00001) r1 = 1.0/fabs(omega1);
245 if (fabs(omega2)>0.00001) r2 = 1.0/fabs(omega2);
246 double pdrad = fabs((r1-r2)/(r1+r2)) ;
249 std::cout <<
" fabs(d01 - d02) " << fabs(d01 - d02) << std::endl;
250 std::cout <<
" fabs(phi01-phi02) " << fabs(phi01-phi02) << std::endl;
253 if ( (prodo > 0.) && (dd0 < m_maxDd0InMerge) && (dphi0 < m_maxDphi0InMerge) &&
254 (pdrad < m_maxPdradInMerge)) {
259 if ( (prodo < 0.) && (fabs(d01+d02) < 4.0) && (dd0 > 47.0) &&
261 && (pdrad < m_maxPdradInMerge)) {
277 std::vector<RecMdcTrack*>::iterator itTk = mergeTkList.begin();
278 for (
int iTk=0; itTk != mergeTkList.end(); itTk++,iTk++){
280 double chi2 = tk->
chi2();
281 double ndf = tk->
ndof();
282 if(chi2/ndf < minRcs) {
287 if (minRcs < m_maxRcsInMerge)
return bestTkId;
352 if ((testTk->
pxy() >= m_mergePt) || (refTk->
pxy() >= m_mergePt))
return overlaped;
355 int nHit = testHits.size();
358 HitRefVec::iterator iterHit = testHits.begin();
359 for (; iterHit != testHits.end(); iterHit++) {
363 double load = m_mergeLoadAx;
365 if(isStLayer) load = m_mergeLoadSt;
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();
375 double dz = refTk->
helix(3);
376 double tanl = refTk->
helix(4);
379 double xc = vx0 + (dr + r) *
cos(phi0);
380 double yc = vy0 + (dr + r) *
sin(phi0);
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));
389 double dx = xc - xHit;
390 double dy = yc - yHit;
391 double dHit2Center = sqrt(dx * dx + dy * dy);
392 double rTk = fabs(r);
395 if ( (dHit2Center>(rTk - load)) && (dHit2Center<(rTk + load))) nOverlap++;
398 if ( nOverlap<=0 )
return overlaped;
400 double overlapRatio = double(nOverlap) / double(nHit);
402 if (overlapRatio > m_mergeOverlapRatio) overlaped = 1;
410 int innerMostTkId = 999;
412 unsigned innerMostLayerOfTk = 999;
413 std::vector<RecMdcTrack*>::iterator itTk = mergeTkList.begin();
414 for (
int iTk=0; itTk != mergeTkList.end(); itTk++,iTk++){
416 unsigned innerMostLayer = 999;
417 for (
unsigned iHit = 0; iHit < tk->
getVecHits().size(); iHit++) {
419 if (layer < innerMostLayer) innerMostLayer=layer;
422 if(m_debug>0)std::cout<<__FILE__<<
" to be merged track id="<<tk->
trackId()<< std::endl;
424 if(innerMostLayer < innerMostLayerOfTk){
427 }
else if (innerMostLayer == innerMostLayerOfTk) {
437 return innerMostTkId;
442 if (!trackList)
return;
444 if (!hitList)
return;
446 assert (aTrack !=
NULL);
449 if(m_debug>1)std::cout<<__FILE__<<
" STORED"<< std::endl;
453 mdcTrack.
storeTrack(-1, trackList, hitList, tkStat);
458 if (!trackList)
return false;
460 if (!hitList)
return false;
462 HitRefVec::iterator iterHit = hits.begin();
463 for (; iterHit != hits.end(); iterHit++) {
466 trackList->erase(tk);
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++){
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)
487 std::cout<<
" q "<<tk->
charge()
488 <<
" theta "<<tk->
theta()
495 std::cout <<
" p "<<tk->
p()
501 std::cout<<
" tkStat "<<tk->
stat()
502 <<
" chi2 "<<tk->
chi2()
503 <<
" ndof "<<tk->
ndof()
505 <<
" nst "<<tk->
nster()
512 std::cout<<
nhits <<
" Hits: " << std::endl;
513 for(
int ii=0; ii <
nhits ; ii++){
517 cout<<
"("<< layer <<
","<<wire<<
","<<tk->
getVecHits()[ii]->getStat()
518 <<
",lr:"<<tk->
getVecHits()[ii]->getFlagLR()<<
") ";
520 std::cout <<
" "<< std::endl;
522 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)
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