12 #include "TClonesArray.h"
13 #include "TParticlePDG.h"
16 #include "FairRootManager.h"
18 #include "FairRunAna.h"
19 #include "FairRuntimeDb.h"
20 #include "FairField.h"
32 #include "TGeoManager.h"
66 PndPersistencyTask(name, iVerbose), fMCTracks(0), fTracks(0), fDoPerformance(0), fTracker(0), fPerfHistoFile(0)
73 string fts_geometry_str =
76 0 294.895 0.00044 0.0117 0 1 6\
77 1 295.77 0.00044 0.0117 0 1 6\
78 2 299.39 0.00044 0.0117 0.0871557 1 6\
79 3 300.265 0.00044 0.0117 0.0871557 1 6\
80 4 304.39 0.00044 0.0117 -0.0871557 1 6\
81 5 305.265 0.00044 0.0117 -0.0871557 1 6\
82 6 309.39 0.00044 0.0117 0 1 6\
83 7 310.265 0.00044 0.0117 0 1 6\
84 8 326.895 0.00044 0.0117 0 1 6\
85 9 327.77 0.00044 0.0117 0 1 6\
86 10 331.39 0.00044 0.0117 0.0871557 1 6\
87 11 332.265 0.00044 0.0117 0.0871557 1 6\
88 12 336.39 0.00044 0.0117 -0.0871557 1 6\
89 13 337.265 0.00044 0.0117 -0.0871557 1 6\
90 14 341.39 0.00044 0.0117 0 1 6\
91 15 342.265 0.00044 0.0117 0 1 6\
92 16 393.995 0.00044 0.0117 0 1 6\
93 17 394.87 0.00044 0.0117 0 1 6\
94 18 400.965 0.00044 0.0117 0.0871557 1 6\
95 19 401.84 0.00044 0.0117 0.0871557 1 6\
96 20 415.49 0.00044 0.0117 -0.0871557 1 6\
97 21 416.365 0.00044 0.0117 -0.0871557 1 6\
98 22 422.965 0.00044 0.0117 0 1 6\
99 23 423.84 0.00044 0.0117 0 1 6\
100 24 437.49 0.00044 0.0117 0 1 6\
101 25 438.365 0.00044 0.0117 0 1 6\
102 26 444.965 0.00044 0.0117 0.0871557 1 6\
103 27 445.84 0.00044 0.0117 0.0871557 1 6\
104 28 459.49 0.00044 0.0117 -0.0871557 1 6\
105 29 460.365 0.00044 0.0117 -0.0871557 1 6\
106 30 466.965 0.00044 0.0117 0 1 6\
107 31 467.84 0.00044 0.0117 0 1 6\
108 32 606.995 0.00044 0.0117 0 1 6\
109 33 607.87 0.00044 0.0117 0 1 6\
110 34 611.49 0.00044 0.0117 0.0871557 1 6\
111 35 612.365 0.00044 0.0117 0.0871557 1 6\
112 36 616.49 0.00044 0.0117 -0.0871557 1 6\
113 37 617.365 0.00044 0.0117 -0.0871557 1 6\
114 38 621.49 0.00044 0.0117 0 1 6\
115 39 622.365 0.00044 0.0117 0 1 6\
116 40 638.995 0.00044 0.0117 0 1 6\
117 41 639.87 0.00044 0.0117 0 1 6\
118 42 643.49 0.00044 0.0117 0.0871557 1 6\
119 43 644.365 0.00044 0.0117 0.0871557 1 6\
120 44 648.49 0.00044 0.0117 -0.0871557 1 6\
121 45 649.365 0.00044 0.0117 -0.0871557 1 6\
122 46 653.49 0.00044 0.0117 0 1 6\
123 47 654.365 0.00044 0.0117 0 1 6";
125 std::istringstream settings(fts_geometry_str);
133 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
136 TFile* curFile = gFile;
137 TDirectory* curDirectory = gDirectory;
140 string filePrefix =
"./CATrackerData";
145 fPerfHistoFile =
new TFile( (filePrefix +
"CATrackerPerformance.root").data(),
"RECREATE" );
147 gSystem->Exec(
"mkdir ./CATrackerData");
148 fPerfHistoFile =
new TFile( (filePrefix +
"CATrackerPerformance.root").data(),
"RECREATE" );
159 gDirectory = curDirectory;
174 if(
fVerbose>3) Info(
"Init",
"Start initialisation.");
176 FairRootManager *fManager = FairRootManager::Instance();
179 fMCTracks =
dynamic_cast<TClonesArray *
>(fManager->GetObject(
"MCTrack"));
181 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No MCTrack array! Needed for MC Truth" << std::endl;
185 fMCPoints =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"FTSPoint"));
187 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No FTSPoint array!" << std::endl;
190 fHits =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"FTSHit"));
192 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No FTSHit array!" << std::endl;
196 FairRuntimeDb*
rtdb = FairRunAna::Instance()->GetRuntimeDb();
204 fBranchID = FairRootManager::Instance()->GetBranchId(
"FTSHit");
207 fTracks =
new TClonesArray(
"PndTrack");
208 fManager->Register(
"FtsTrack",
"Fts",
fTracks, kTRUE);
214 FairRuntimeDb*
rtdb = FairRunAna::Instance()->GetRuntimeDb();
215 rtdb->getContainer(
"PndGeoSttPar");
216 rtdb->getContainer(
"PndGeoFtsPar");
234 vector <int> perStationCounts(6);
235 for (
int i=0;
i<NHits;
i++)
238 for (
int j=0; j<6; j++)
242 perStationCounts[j]++;
248 for (
unsigned int j=0; j<perStationCounts.size(); j++)
253 if (perStationCounts[j]>40)
268 if ((perStationCounts[j]+perStationCounts[j+1]+perStationCounts[j+2]+perStationCounts[j+3])<4)
274 if ((perStationCounts[j]+perStationCounts[j+1]+perStationCounts[j+2]+perStationCounts[j+3]+perStationCounts[j+4])<4)
280 PndFTSCAPerformance* perf = &PndFTSCAPerformance::Instance();
281 const int NMCTracks = perf->GetMCTracks()->Size();
289 for(
int iT=0; iT<NMCTracks; iT++)
291 int nFirstMC = (*perf->GetMCTracks())[iT].FirstMCPointID();
293 int nMCPoints = (*perf->GetMCTracks())[iT].NMCPoints();
300 for (
int iP1=0; iP1<nMCPoints-1; iP1++)
302 for (
int iP2=iP1+1; iP2<nMCPoints; iP2++)
310 if (points[iP1].
Z()>points[iP2].
Z())
311 (*perf->GetMCTracks())[iT].SetIsForwardTrack(
false);
336 for(
int i=0;
i<15;
i++)
337 cov[
i] = kfParam->
Cov(
i);
364 fairParam->SetTrackPar(x, y, tx, ty, qp, cov, TVector3(0,0,0), TVector3(-sA,cA,0), TVector3(cA,sA,0), TVector3(0,0,-1), q);
370 if (
fVerbose>0) std::cout<<
"PndFtsCATracking::Exec"<<std::endl;
376 static int iEvent = -1;
379 cout <<
"iEvent " << iEvent << endl;
383 std::map<Int_t, PndMCTrack*> mctracklist;
388 unsigned int nMCPoints=0;
392 map<int, unsigned int> nHitsInMCTrack, nMCPointsInMCTrack, FirstMCPointIDInMCTrack;
394 vector < vector <PndFtsPoint*> > MCTrackSortedArray(
fMCTracks->GetEntriesFast());
396 for (Int_t ih = 0; ih <
fHits->GetEntriesFast(); ih++)
401 Int_t mchitid=ghit->GetRefIndex();
402 if(mchitid<0)
continue;
404 if(!myPoint)
continue;
405 Int_t trackID = myPoint->GetTrackID();
406 if(trackID<0)
continue;
416 MCTrackSortedArray[myPoint->GetTrackID()].push_back(myPoint);
431 for (
int iTr = 0; iTr <
fMCTracks->GetEntriesFast(); iTr++ )
434 std::sort(MCTrackSortedArray[iTr].begin(), MCTrackSortedArray[iTr].end(),
compareFtsPoints);
438 for(
unsigned int iPFts=0; iPFts < MCTrackSortedArray[iTr].size(); iPFts++)
441 int trackID = point->GetTrackID();
448 TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(mcTr->
GetPdgCode());
451 q = part->Charge()/3.f;
473 if ( nMCPointsInMCTrack.find(trackID) != nMCPointsInMCTrack.end() ) {
474 nMCPointsInMCTrack[trackID]++;
476 nMCPointsInMCTrack[trackID] = 1;
477 FirstMCPointIDInMCTrack[trackID] = nMCPoints;
506 TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(pdg);
508 q = part->Charge()/3.f;
513 unsigned int nmcpimct = nMCPointsInMCTrack[iTr];
514 unsigned int fmcpidimct = FirstMCPointIDInMCTrack[iTr];
515 yyy.
SetMCTrack(mcTr, q, nmcpimct, fmcpidimct);
556 std::vector<PndFTSCAGBHit> vHits;
579 int kEvents = iEvent;
581 sprintf( buf,
"%d", kEvents );
610 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
614 std::cout <<
"Loading Monte-Carlo Data for Event " << kEvents <<
"..." << std::endl;
616 cout <<
"Monte-Carlo Data for Event " << kEvents <<
" can't be read." << std::endl;
635 cout<<
"Run CA trackfinder... "<<endl;
647 for(
int ih=0; ih<tr.
NHits(); ih++ )
655 FairTrackParP paramFirst;
656 FairTrackParP paramLast;
661 PndTrack *outTrack =
new((*fTracks)[nOutTracks])
PndTrack(paramFirst,paramLast,outCand);
663 outTrack->SetFlag(0);
668 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
671 if (fTrackerConst->
NHits() > 0) {
676 cout <<
"Event " << kEvents <<
" contains 0 hits." << std::endl;
683 const bool ifAvarageTime = 1;
685 std::cout <<
"Reconstruction Time"
686 <<
" Real = " << std::setw( 10 ) << (fTrackerConst->
SliceTrackerTime() + fTrackerConst->
StatTime( 9 )) * 1.e3 <<
" ms,"
691 const int NTimers = fTrackerConst->
NTimers();
692 static int statIEvent = 0;
693 static double *statTime =
new double[NTimers];
694 static double statTime_SliceTrackerTime = 0;
695 static double statTime_SliceTrackerCpuTime = 0;
698 for (
int i = 0;
i < NTimers;
i++){
704 for (
int i = 0;
i < NTimers;
i++){
710 std::cout <<
"Reconstruction Time"
711 <<
" Real = " << std::setw( 10 ) << 1./statIEvent*(statTime_SliceTrackerTime+statTime[ 9 ]) * 1.e3 <<
" ms,"
712 <<
" CPU = " << std::setw( 10 ) << 1./statIEvent*(statTime_SliceTrackerCpuTime+statTime[ 10 ]) * 1.e3 <<
" ms,"
726 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
735 int &iHit, map<int, unsigned int> &nHitsInMCTrack)
737 TClonesArray *hitsArray;
739 Int_t ftsLinkType = FairRootManager::Instance()->GetBranchId(
"FTSPoint");
745 std::map<Int_t,Int_t> tubeMap;
746 std::map<Int_t,Int_t>::iterator mapIt;
748 for(
int iH=0; iH<hitsArray->GetEntriesFast(); iH++)
753 mapIt = tubeMap.find(
'b');
754 if( mapIt == tubeMap.end() ){
755 tubeMap.insert( std::pair<Int_t,Int_t>(tubeID,1) );
758 if( mapIt->second >3 )
continue;
767 const Double_t errXY2 = errXY*errXY;
781 TMatrixT<Double_t>
C(3,3);
785 C[0][1] = C[0][2] = C[1][0] = C[1][2] = C[2][0] = C[2][1] = 0;
787 TMatrixT<Double_t>
CR =
C;
790 CR = CR*RM.Transpose(RM);
835 FairMultiLinkedData links = currenthit->GetLinksWithType(ftsLinkType);
836 if( links.GetNLinks() >0 )
838 int iPoint = links.GetLink(0).GetIndex();
847 trackID = point->GetTrackID();
854 TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(mcTr->
GetPdgCode());
855 float q = part->Charge()/3.f;
856 float qp = q/
sqrt( point->GetPx()*point->GetPx() + point->GetPy()*point->GetPy() + point->GetPz()*point->GetPz() );
858 h.
point_X = (float) point->GetX();
859 h.
point_Y = (float) point->GetY();
860 h.
point_Z = (float) point->GetZ();
861 h.
point_Px = (float) point->GetPx();
862 h.
point_Py = (float) point->GetPy();
863 h.
point_Pz = (float) point->GetPz();
871 h.
SetErr2X(currenthit->GetDx()*currenthit->GetDx());
872 h.
SetErr2Y(currenthit->GetDy()*currenthit->GetDy());
884 h.SetErr2R( closestDistanceError*closestDistanceError );
894 h.
SetPndDetID( FairRootManager::Instance()->GetBranchId(
"FTSHit") );
899 int trackIDs[3] = {-1, -1, -1};
900 trackIDs[0] = trackID;
911 if ( nHitsInMCTrack.find(trackIDs[0]) != nHitsInMCTrack.end() ) {
912 nHitsInMCTrack[trackIDs[0]]++;
914 nHitsInMCTrack[trackIDs[0]] = 1;
bool NonReconstructableEvent()
void SetC(const TMatrixT< Double_t > c)
TClonesArray * fTracks
Array of event's hits.
void SetRefIndex(TString branch, Int_t i)
const PndFTSCAGBTrack & Track(int i) const
static void CATrackParToFairTrackParP(FairTrackParP *fairParam, const PndFTSCATrackParam *caParam)
int TrackHit(int i) const
PndFTSCAGBTracker * fTracker
double StatTime(int iTimer) const
friend F32vec4 sqrt(const F32vec4 &a)
bool compareFtsPoints(PndFtsPoint *const a, PndFtsPoint *const b)
void ReadSettings(std::istream &in)
TVector3 GetMomentum() const
vector< PndFTSCAMCTrack > ftsmctracks
void SetPersistency(Bool_t val=kTRUE)
double SliceTrackerCpuTime() const
void SetPoint(PndFtsPoint *ppp, Double_t qq)
cout<< "POINTs for new FwEndCap == "<< tsim-> GetEntriesFast()
TVector3 GetWireDirection() const
double SliceTrackerTime() const
TClonesArray * fTubeArrayFts
PndFTSResizableArray< PndFTSCAGBHit > fHits
const PndFTSCATrackParam & OuterParam() const
bool fDoPerformance
Array of found tracks.
PndFtsCATracking(const char *name="FtsCATracking", Int_t iVerbose=0)
const float * Cov() const
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
void SetHits(std::vector< PndFTSCAGBHit > &hits)
PndFTSCAParam & GetParametersNonConst()
void SetMCTrack(const PndMCTrack *ttt, Double_t q, unsigned int Nmcpoints, unsigned int FirstmcpointId)
TMatrixT< Double_t > GetRotationMatrix() const
TVector3 GetPosition() const
const PndFTSCATrackParam & InnerParam() const
Double_t GetHalfLength() const
PndFTSCAPerformance * fPerformance
TClonesArray * fHits
Array of event's points.
Double_t GetIsochrone() const
Double_t GetRadIn() const
Double_t GetIsochroneError() const
TClonesArray * FillTubeArray()
this function will be used in PndFtsHitProducesRealFast
virtual void Exec(Option_t *opt)
vector< PndFTSCALocalMCPoint > ftsmcpoints
const PndFTSCAGBHit & Hit(int index) const
virtual InitStatus Init()
vector< int > allFwdTrackIds
void WriteFTSHits(std::vector< PndFTSCAGBHit > &vHits, int &iHit, map< int, unsigned int > &nHitsInMCTrack)
TClonesArray * fMCPoints
Array of PndMCTrack.