6 #include "TClonesArray.h"
8 #include "TGeoManager.h"
10 #include "FairRootManager.h"
12 #include "FairRuntimeDb.h"
17 #include "TStopwatch.h"
23 FairTask(
"LMD Track Finding Task"), nSensPP(innSensPP)
59 InitStatus stat=kERROR;
78 FairRootManager* ioman = FairRootManager::Instance();
82 std::cout <<
"-E- PndStraightLineTrackFinderTask::Init: "
83 <<
"RootManager not instantiated!" << std::endl;
90 std::cout <<
"-W- PndStraightLineTrackFinderTask::Init: " <<
"No fStripHitArray!" << std::endl;
96 std::cout <<
"-W- PndStraightLineTrackFinderTask::Init: " <<
"No StripclusterArray!" << std::endl;
102 std::cout <<
"-W- PndStraightLineTrackFinderTask::Init: " <<
"No StripdigiArray!" << std::endl;
107 ioman->Register(
"MVDTestBeamTrackCand",
"Mvd",
fTrackCandArray, kTRUE);
113 std::cout <<
"-I- PndStraightLineTrackFinderTask: Initialisation successfull" << std::endl;
124 for(Int_t iHit = 0; iHit < nStripHits; iHit++){
129 Int_t planeid = floor((sensid)/(
double)
nSensPP);
130 hitsd.at(planeid).push_back( make_pair (iHit,
false) );
133 for(Int_t iPlane = 0; iPlane < 4; iPlane++){
134 if(hitsd.at(iPlane).size()>0) nPlanes++;
139 cout <<
"Hits: " << nStripHits <<
" in " << nPlanes <<
" plane(s)." << endl;
140 for(Int_t idet = 0; idet < 4; idet++)
141 cout <<
"Plane: "<< idet <<
" DiscHits: "<< hitsd.at(idet).size() <<endl;
144 if(nPlanes>2)
return true;
155 for(Int_t iHit = 0; iHit < nStripHits; iHit++){
162 hitsd.at(sensid).push_back( make_pair (iHit,
false) );
168 for(Int_t iPlane = 0; iPlane < 4; iPlane++){
169 if(hitsd.at(iPlane).size()>0) nPlanes++;
174 cout <<
"Hits: " << nStripHits <<
" in " << nPlanes <<
" plane(s)." << endl;
175 for(Int_t idet = 0; idet < 4; idet++)
176 cout <<
"Plane: "<< idet <<
" DiscHits: "<< hitsd.at(idet).size() <<endl;
179 if(nPlanes>2)
return true;
187 std::vector<Double_t> detZ;
190 for (Int_t iHit = 0; iHit < nStripHits; iHit++){
193 for(Int_t idet = 0; idet < detZ.size(); idet++){
197 if(
fabs(tmp-detZ.at(idet))<9.){
206 for(Int_t idet = detZ.size()-1; idet >= 0; idet--){
207 if(tmp < detZ.at(idet))
214 for(Int_t
i=pos+1;
i<detZ.size();
i++){
225 for(Int_t iHit = 0; iHit < nStripHits; iHit++){
229 for(Int_t idet = 0; idet < detZ.size(); idet++){
232 if(
fabs(z-detZ.at(idet))<9. ){
233 hitsd.at(idet).push_back( make_pair (iHit,
false) );
241 cout <<
"Hits: " << nStripHits <<
" in " << detZ.size() <<
" plane(s)." << endl;
242 for(Int_t idet = 0; idet < detZ.size(); idet++)
243 cout <<
"Plane: "<< idet <<
" DiscHits: "<< hitsd.at(idet).size() <<endl;
246 if(detZ.size()>3)
return true;
255 std::vector<TVector3> trackStart, trackVec;
256 std::vector<TVector3> trackStartd, trackVecd;
257 std::vector< Int_t > trackID2, trackID3;
260 TVector3 start, tmp,
vec, dstart, dvec;
262 if(hitsd.size()<3)
return;
263 for (Int_t
i=0;
i<hitsd.at(1).size();
i++)
265 if(hitsd.at(1).at(
i).second)
continue;
267 start.SetXYZ(hit1->GetX(), hit1->GetY(), hit1->GetZ());
268 dstart.SetXYZ(hit1->GetDx(), hit1->GetDy(), hit1->GetDz());
269 for (Int_t k=0; k<hitsd.at(2).size(); k++)
271 if(hitsd.at(2).at(k).second)
continue;
273 tmp.SetXYZ(hit2->GetX(), hit2->GetY(), hit2->GetZ());
275 dvec.SetXYZ(hit2->GetDx(), hit2->GetDy(), hit2->GetDz());
276 if(vec.Theta()>0.03 && vec.Theta()<0.05 && vec.Phi()>-0.25 && vec.Phi()<0.25){
279 trackStart.push_back(start);
280 trackStartd.push_back(dstart);
281 trackVec.push_back(vec);
282 trackVecd.push_back(dvec);
285 trackID2.push_back(
i);
286 trackID3.push_back(k);
291 if(
fVerbose>1) cout <<
"Pseudos L2L3: "<< trackStart.size() <<endl;
293 std::vector<Int_t> ids;
296 for (Int_t
i=0;
i<trackStart.size();
i++)
301 start = trackStart.at(
i);
302 dstart = trackStartd.at(
i);
303 vec = trackVec.at(
i);
304 dvec = trackVecd.at(
i);
305 ids.push_back(hitsd.at(1).at(trackID2.at(
i)).first);
306 ids.push_back(hitsd.at(2).at(trackID3.at(
i)).first);
307 std::vector< std::pair<Int_t,Int_t> > otherIDs;
309 for (Int_t idet=3; idet < 4; idet++){
312 for (Int_t ihit=0; ihit<hitsd.at(idet).size(); ihit++)
315 Double_t scale = (hit->GetZ()-start.z())/vec.z();
316 tmp = start + scale*
vec;
317 Double_t distTmp =
sqrt((tmp.x()-hit->GetX())*(tmp.x()-hit->GetX()) + (tmp.y()-hit->GetY())*(tmp.y()-hit->GetY()));
318 if( distTmp<(idet*dXY) ){
321 ids.push_back(hitsd.at(idet).at(ihit).first);
322 otherIDs.push_back( make_pair (idet,ihit) );
326 if(distTmp<distClosest){
329 ids.push_back(hitsd.at(idet).at(ihit).first);
330 otherIDs.push_back( make_pair (idet,ihit) );
337 if(
fVerbose>2) cout <<
" Track L2L3: "<<
i <<
"#Planes: " << ids.size() <<endl;
343 for (Int_t
id=0;
id<ids.size();
id++){
357 hitsd.at(1).at(trackID2.at(
i)).second=
true;
358 hitsd.at(2).at(trackID3.at(
i)).second=
true;
359 for(Int_t
id=0;
id<otherIDs.size();
id++){
360 hitsd.at(otherIDs.at(
id).first).at(otherIDs.at(
id).second).second=
true;
378 tofill.push_back(*(myTCand));
391 std::vector<TVector3> trackStart, trackVec;
392 std::vector<TVector3> trackStartd, trackVecd;
393 std::vector< Int_t > trackID1, trackID3;
396 TVector3 start, tmp,
vec, dstart, dvec;
398 if(hitsd.size()<3)
return;
399 for (Int_t
i=0;
i<hitsd.at(0).size();
i++)
401 if(hitsd.at(0).at(
i).second)
continue;
403 start.SetXYZ(hit1->GetX(), hit1->GetY(), hit1->GetZ());
404 dstart.SetXYZ(hit1->GetDx(), hit1->GetDy(), hit1->GetDz());
405 for (Int_t k=0; k<hitsd.at(2).size(); k++)
407 if(hitsd.at(2).at(k).second)
continue;
409 tmp.SetXYZ(hit2->GetX(), hit2->GetY(), hit2->GetZ());
411 dvec.SetXYZ(hit2->GetDx(), hit2->GetDy(), hit2->GetDz());
412 if(vec.Theta()>0.03 && vec.Theta()<0.05 && vec.Phi()>-0.25 && vec.Phi()<0.25){
415 trackStart.push_back(start);
416 trackStartd.push_back(dstart);
417 trackVec.push_back(vec);
418 trackVecd.push_back(dvec);
421 trackID1.push_back(
i);
422 trackID3.push_back(k);
427 if(
fVerbose>1) cout <<
"Pseudos L1L3: "<< trackStart.size() <<endl;
429 std::vector<Int_t> ids;
432 for (Int_t
i=0;
i<trackStart.size();
i++)
437 start = trackStart.at(
i);
438 dstart = trackStartd.at(
i);
439 vec = trackVec.at(
i);
440 dvec = trackVecd.at(
i);
441 ids.push_back(hitsd.at(0).at(trackID1.at(
i)).first);
442 ids.push_back(hitsd.at(2).at(trackID3.at(
i)).first);
443 std::vector< std::pair<Int_t,Int_t> > otherIDs;
445 for (Int_t idet=3; idet < 4; idet++){
448 for (Int_t ihit=0; ihit<hitsd.at(idet).size(); ihit++)
451 Double_t scale = (hit->GetZ()-start.z())/vec.z();
452 tmp = start + scale*
vec;
453 Double_t distTmp =
sqrt((tmp.x()-hit->GetX())*(tmp.x()-hit->GetX()) + (tmp.y()-hit->GetY())*(tmp.y()-hit->GetY()));
454 if( distTmp<(idet*dXY) ){
457 ids.push_back(hitsd.at(idet).at(ihit).first);
458 otherIDs.push_back( make_pair (idet,ihit) );
462 if(distTmp<distClosest){
465 ids.push_back(hitsd.at(idet).at(ihit).first);
466 otherIDs.push_back( make_pair (idet,ihit) );
473 if(
fVerbose>2) cout <<
" Track L1L3: "<<
i <<
"#Planes: " << ids.size() <<endl;
479 for (Int_t
id=0;
id<ids.size();
id++){
493 hitsd.at(0).at(trackID1.at(
i)).second=
true;
494 hitsd.at(2).at(trackID3.at(
i)).second=
true;
495 for(Int_t
id=0;
id<otherIDs.size();
id++){
496 hitsd.at(otherIDs.at(
id).first).at(otherIDs.at(
id).second).second=
true;
514 tofill.push_back(*(myTCand));
527 std::vector<TVector3> trackStart, trackVec;
528 std::vector<TVector3> trackStartd, trackVecd;
529 std::vector< Int_t > trackID1, trackID2;
532 TVector3 start, tmp,
vec, dstart, dvec;
534 if(hitsd.size()<2)
return;
535 for (Int_t
i=0;
i<hitsd.at(0).size();
i++)
538 start.SetXYZ(hit1->GetX(), hit1->GetY(), hit1->GetZ());
539 dstart.SetXYZ(hit1->GetDx(), hit1->GetDy(), hit1->GetDz());
540 for (Int_t k=0; k<hitsd.at(1).size(); k++)
543 tmp.SetXYZ(hit2->GetX(), hit2->GetY(), hit2->GetZ());
545 dvec.SetXYZ(hit2->GetDx(), hit2->GetDy(), hit2->GetDz());
548 trackStart.push_back(start);
549 trackStartd.push_back(dstart);
550 trackVec.push_back(vec);
551 trackVecd.push_back(dvec);
554 trackID1.push_back(
i);
555 trackID2.push_back(k);
560 if(
fVerbose>1) cout <<
"Pseudos L1L2: "<< trackStart.size() <<endl;
562 std::vector<Int_t> ids;
565 for (Int_t
i=0;
i<trackStart.size();
i++)
570 start = trackStart.at(
i);
571 dstart = trackStartd.at(
i);
572 vec = trackVec.at(
i);
573 dvec = trackVecd.at(
i);
574 ids.push_back(hitsd.at(0).at(trackID1.at(
i)).first);
575 ids.push_back(hitsd.at(1).at(trackID2.at(
i)).first);
576 std::vector< std::pair<Int_t,Int_t> > otherIDs;
578 for (Int_t idet=2; idet < 4; idet++){
581 for (Int_t ihit=0; ihit<hitsd.at(idet).size(); ihit++)
584 Double_t scale = (hit->GetZ()-start.z())/vec.z();
585 tmp = start + scale*
vec;
586 Double_t distTmp =
sqrt((tmp.x()-hit->GetX())*(tmp.x()-hit->GetX()) + (tmp.y()-hit->GetY())*(tmp.y()-hit->GetY()));
587 if( distTmp<(idet*dXY) ){
590 ids.push_back(hitsd.at(idet).at(ihit).first);
591 otherIDs.push_back( make_pair (idet,ihit) );
595 if(distTmp<distClosest){
598 ids.push_back(hitsd.at(idet).at(ihit).first);
599 otherIDs.push_back( make_pair (idet,ihit) );
606 if(
fVerbose>2) cout <<
" Track L1L2: "<<
i <<
"#Planes: " << ids.size() <<endl;
615 if(
fVerbose>2) cout <<
" Track: "<<
i <<
"#Planes: " << ids.size() <<endl;
618 for (Int_t
id=0;
id<ids.size();
id++){
628 hitsd.at(0).at(trackID1.at(
i)).second=
true;
629 hitsd.at(1).at(trackID2.at(
i)).second=
true;
630 for(Int_t
id=0;
id<otherIDs.size();
id++){
631 hitsd.at(otherIDs.at(
id).first).at(otherIDs.at(
id).second).second=
true;
672 tofill.push_back(*(myTCand));
684 TStopwatch *timer_exec =
new TStopwatch();
686 if(
fVerbose>2) cout <<
"Evt " << FairRootManager::Instance()->GetEntryNr() <<
" started--------------"<<endl<<endl;
693 Fatal(
"Exec",
"No trackCandArray");
697 if(
fVerbose>2) cout <<
"# Hits: \t"<< nStripHits <<endl<<endl;
698 bool usedFlag[nStripHits];
699 for(Int_t seti=0; seti<nStripHits; seti++)
700 usedFlag[seti]=
false;
703 if(
fVerbose>2) cout <<
"Evt finsihed: too less hits-----"<<endl<<endl;
708 std::vector< std::vector< std::pair<int,bool> > > hitsd(4);
714 std::cout<<
"Algorithm is needed sensor type! Please, set it via SetSensStripFlag(bool fS) or SetSensPixelFlag(bool fS)"<<std::endl;
719 if(
fVerbose>2) cout <<
"Evt finsihed: too less planes-----"<<endl<<endl;
725 cout<<
"HitMap size: "<< hitsd.size() <<endl;
727 for (Int_t
i=0;
i<hitsd.at(0).size();
i++){
729 cout<<
"Plane0 Hit=("<<hit->GetX()<<
", "<<hit->GetY()<<
", "<<hit->GetZ()<<
")"<<endl;
733 for (Int_t
i=0;
i<hitsd.at(1).size();
i++){
735 cout<<
"Plane1 Hit=("<<hit->GetX()<<
", "<<hit->GetY()<<
", "<<hit->GetZ()<<
")"<<endl;
739 for (Int_t
i=0;
i<hitsd.at(2).size();
i++){
741 cout<<
"Plane2 Hit=("<<hit->GetX()<<
", "<<hit->GetY()<<
", "<<hit->GetZ()<<
")"<<endl;
745 for (Int_t
i=0;
i<hitsd.at(3).size();
i++){
747 cout<<
"Plane3 Hit=("<<hit->GetX()<<
", "<<hit->GetY()<<
", "<<hit->GetZ()<<
")"<<endl;
752 std::vector<PndTrackCand> theCands;
762 for(
int t=0;
t<theCands.size();
t++)
765 if(
fVerbose>2) cout <<
"Evt finsihed--------------"<<endl<<endl;
768 Double_t rtime_exec = timer_exec->RealTime();
769 Double_t ctime_exec = timer_exec->CpuTime();
770 cout <<
"Real time for Exec:" << rtime_exec <<
" s, CPU time " << ctime_exec <<
" s" << endl;
779 return (2/
TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py()));
786 return (p.Mag()/
TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py()));
TVector3 GetPosition() const
friend F32vec4 sqrt(const F32vec4 &a)
static T Sqrt(const T &x)
Class for digitised strip hits.
TVector3 GetMomentum() const
void FindHitsII(std::vector< PndTrackCand > &tofill, std::vector< std::vector< std::pair< Int_t, bool > > > &hitsd, Int_t nStripHits)
bool SortHitsByDet2(std::vector< std::vector< std::pair< Int_t, bool > > > &hitsd, Int_t nStripHits)
ClassImp(PndStraightLineTrackFinderTask)
Int_t GetDigiIndex(Int_t i) const
void FindHitsIII(std::vector< PndTrackCand > &tofill, std::vector< std::vector< std::pair< Int_t, bool > > > &hitsd, Int_t nStripHits)
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
virtual void SetParContainers()
TClonesArray * fStripClusterArray
Double_t GetTrackDip(PndMCTrack *myTrack)
TClonesArray * fStripHitArray
virtual ~PndStraightLineTrackFinderTask()
friend F32vec4 fabs(const F32vec4 &a)
bool SortHitsByDet(std::vector< std::vector< std::pair< Int_t, bool > > > &hitsd, Int_t nStripHits)
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Double_t GetTrackCurvature(PndMCTrack *myTrack)
virtual void Exec(Option_t *opt)
TString fClusterBranchStrip
TClonesArray * fStripDigiArray
TClonesArray * fTrackCandArray
void FindHitsI(std::vector< PndTrackCand > &tofill, std::vector< std::vector< std::pair< Int_t, bool > > > &hitsd, Int_t nStripHits)
Int_t GetClusterIndex() const
bool SortHitsByZ(std::vector< std::vector< std::pair< Int_t, bool > > > &hitsd, Int_t nStripHits)
Int_t GetSensorID() const
virtual InitStatus Init()
virtual InitStatus ReInit()
PndStraightLineTrackFinderTask(Int_t inFinderMode=0, TString hitBranch="LMDHitsStrip", TString clusterBranch="LMDStripClusterCand", TString digiBranch="LMDStripDigis", Int_t innSensPP=8)