8 #include "FairTrackParP.h"
9 #include "FairMCPoint.h"
17 #include "FairRootManager.h"
19 #include "TObjectTable.h"
20 #include "TClonesArray.h"
21 #include "TParticlePDG.h"
31 #include "FairRootManager.h"
32 #include "FairRunAna.h"
33 #include "FairRuntimeDb.h"
38 FairTask(
"FTSTrackfinderIdeal"), fMCTracks(0), fTrackCands(0), fTracks(0),
39 fTrackIds(0), fMinFtsHitsPerTrack(5), fMomSigma(0,0,0), fDPoP(0.), fRelative (kFALSE), fVtxSigma(0,0,0), fEfficiency(1.), fPersistence(kTRUE),
40 fTracksArrayName(
"FTSTrkIdeal"), pdg(0)
44 fTracks =
new TClonesArray(
"PndTrack");
56 FairRootManager *fManager =FairRootManager::Instance();
66 if(
fVerbose>3) Info(
"Register",
"Done.");
71 FairRuntimeDb*
rtdb = FairRunAna::Instance()->GetRuntimeDb();
78 if(
fVerbose>3) Info(
"Init",
"Start initialisation.");
80 FairRootManager *fManager = FairRootManager::Instance();
83 fMCTracks =
dynamic_cast<TClonesArray *
>(fManager->GetObject(
"MCTrack"));
85 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No MCTrack array! Needed for MC Truth" << std::endl;
90 fMCPoints[0] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"FTSPoint"));
92 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No FTSPoint array!" << std::endl;
95 fHits[0] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"FTSHit"));
97 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No FTSHit array!" << std::endl;
100 fBranchIDs[0] = FairRootManager::Instance()->GetBranchId(
"FTSHit");
104 fMCPoints[1] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"GEMPoint"));
106 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No GEMPoint array!" << std::endl;
107 fMCPoints[1]=
new TClonesArray(
"FairMCPoint");
109 fHits[1] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"GEMHit"));
111 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No GEMHit array!" << std::endl;
112 fHits[1]=
new TClonesArray(
"FairHit");
114 fBranchIDs[1] = FairRootManager::Instance()->GetBranchId(
"GEMHit");
117 fMCPoints[2] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"MVDPoint"));
119 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No MVDPoint array!" << std::endl;
120 fMCPoints[1]=
new TClonesArray(
"FairMCPoint");
122 fHits[2] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"MVDHitsPixel"));
124 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No MVDHitsPixel array!" << std::endl;
125 fHits[2]=
new TClonesArray(
"FairHit");
127 fBranchIDs[2] = FairRootManager::Instance()->GetBranchId(
"MVDHitsPixel");
130 fHits[3] =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"MVDHitsStrip"));
132 std::cout <<
"-W- PndFtsTrackerIdeal::Init: No MVDHitsStrip array!" << std::endl;
133 fMCPoints[3]=
new TClonesArray(
"FairHit");
135 fBranchIDs[3] = FairRootManager::Instance()->GetBranchId(
"MVDHitsStrip");
137 if(
fVerbose>3) Info(
"Init",
"Fetched all arrays.");
141 pdg =
new TDatabasePDG();
142 if(
fVerbose>3) Info(
"Init",
"End initialisation.");
155 if(
fVerbose>3) Info(
"Exec",
"Start eventloop.");
157 Info(
"Exec",
"Print some array properties");
158 for(
int iii=0;iii<4;iii++){
159 std::cout<<
"fHits["<<iii<<
"] is branchID "<<
fBranchIDs[iii]<<
" with the name "<<
fHits[iii]->GetName()<<
" and contains "<<
fHits[iii]->GetEntriesFast()<<
" entries."<<std::endl;
160 std::cout<<
"fMCPoints["<<iii<<
"] with the name "<<
fMCPoints[iii]->GetName()<<
" and contains "<<
fMCPoints[iii]->GetEntriesFast()<<
" entries."<<std::endl;
171 FairHit* ghit = NULL;
172 std::map<Int_t, FairHit*> firstHit;
173 std::map<Int_t, FairHit*> lastHit;
174 FairMCPoint* myPoint=NULL;
175 std::map<Int_t, FairMCPoint*> firstPoint;
176 std::map<Int_t, FairMCPoint*> lastPoint;
177 std::map<Int_t, PndTrackCand*> candlist;
187 for(Int_t iDet=0;iDet<4;iDet++){
189 if(
fVerbose>4) Info(
"Exec",
"Use detector %i",iDet);
191 for (Int_t ih = 0; ih <
fHits[iDet]->GetEntriesFast(); ih++) {
192 ghit = (FairHit*)
fHits[iDet]->
At(ih);
205 Int_t mchitid=ghit->GetRefIndex();
207 if(
fVerbose>3) Error(
"Exec",
"Have a negative mcHit %i",mchitid);
210 myPoint = (FairMCPoint*)(
fMCPoints[iDet]->
At(mchitid));
211 if(!myPoint)
continue;
212 Int_t trackID = myPoint->GetTrackID();
213 if(trackID<0)
continue;
215 if(
fVerbose>5) Info(
"Exec",
"Have a Hit %i at Track index %i",ih,trackID);
222 if(
fVerbose>5) Info(
"Exec",
"Skip Hit %i, it's not connected to a Track in FTS",ih);
225 if(
fVerbose>5) Info(
"Exec",
"Create new PndTrack object %i",trackID);
228 if(
fVerbose>5) Info(
"Exec",
"Creating new PndTrack object finished %i",trackID);
230 if(
fVerbose>5) Info(
"Exec",
"add the hit %i to trackcand %i",ih,trackID);
233 if(!firstHit[trackID] || firstPoint[trackID]->GetTime() > myPoint->GetTime()) {
234 firstHit[trackID]=ghit;
235 firstPoint[trackID]=myPoint;
238 if(!lastHit[trackID] || lastPoint[trackID]->GetTime() < myPoint->GetTime()) {
239 lastHit[trackID]=ghit;
240 lastPoint[trackID]=myPoint;
243 candlist[trackID] = cand;
254 if(
fVerbose>5) Info(
"Exec",
"Remove all PndTrkCand which are not realistic to be found by FTS Pattern Recognition");
258 std::map<Int_t, PndTrackCand*>::iterator candit;
259 std::vector<Int_t> keysToDeleteFromCandList;
262 cout <<
"print the map keys BEFORE cleaning\n";
263 for(candit=candlist.begin(); candit!=candlist.end(); ++candit) {
264 cout <<
"trackID == " << candit->first << endl;
269 for(candit=candlist.begin(); candit!=candlist.end(); ++candit) {
270 Int_t trackID=candit->first;
273 if(
fVerbose>3) Warning(
"Exec",
"Have no candidate at %i",trackID);
279 Info(
"Exec",
"Mark candlist[%i] for deletion because it has only %i FTS hits which is not enough.", trackID, tcand->
GetNHits());
281 keysToDeleteFromCandList.push_back(trackID);
291 for(
size_t iSortedHit=0; iSortedHit<tcand->
GetNHits(); ++iSortedHit ) {
293 if(
fVerbose>11) Info(
"Exec",
"Look at hit iSortedHit == %i", (
int)iSortedHit);
298 cout <<
"PndFtsTrackerIdeal at cleaning loop\n";
299 cout <<
"candhit = " << candhit << endl;
300 cout <<
"hitID = " << hitID << endl;
301 cout <<
"detID = " << detID << endl;
305 if(detID == FairRootManager::Instance()->GetBranchId(
"FTSHit")) {
307 Int_t tubeID = ((
PndFtsHit*) hit)->GetTubeID();
310 if(hit->GetRefIndex() == -1) {
311 Error(
"Exec",
"Cleaning loop found a hit which was not caused by any MC truth track at iSortedHit == %i",(
int)iSortedHit);
320 if ( pnt->GetZ() < lastz ){
322 Info(
"Exec",
"Mark candlist[%i] for deletion because the track turns around in the dipole field (its time-sorted hits have decreasing z values at some point).", trackID);
325 keysToDeleteFromCandList.push_back(trackID);
333 }
else Error(
"Exec",
"Cleaning loop found a hit from a detector other than FTS at iSortedHit == %i",(
int)iSortedHit);
338 if(
fVerbose>3) Info(
"Exec",
"Ended cleaning loop for candidate with trackID %i",trackID);
343 for (
size_t iKey=0; iKey<keysToDeleteFromCandList.size(); ++iKey){
345 std::cout <<
"Delete key " << keysToDeleteFromCandList[iKey] << std::endl;
347 candlist.erase(keysToDeleteFromCandList[iKey]);
349 keysToDeleteFromCandList.clear();
352 cout <<
"print the map keys AFTER cleaning\n";
353 for(candit=candlist.begin(); candit!=candlist.end(); ++candit) {
354 cout <<
"trackID == " << candit->first << endl;
363 if(
fVerbose>3) Info(
"Exec",
"Insert to TCA (depending on efficiency)");
366 std::map<Int_t, PndTrackCand*>::iterator candit;
371 Int_t charge=0, trackID=-1;
373 for(candit=candlist.begin(); candit!=candlist.end(); ++candit) {
375 trackID=candit->first;
377 if(
fVerbose>3) Warning(
"Exec",
"Have no candidate at %i",trackID);
380 if( tcand->
GetNHits() < 3 )
continue;
386 if (mc->
GetPdgCode()<100000000) charge = (Int_t)TMath::Sign(1.0, ((TParticlePDG*)
pdg->GetParticle(mc->
GetPdgCode()))->Charge());
390 firstPoint[trackID]->Position(svtx);
392 firstPoint[trackID]->Momentum(smom);
395 FairTrackParP* firstPar=
new FairTrackParP(svtx, smom,
398 TVector3(1.,0.,0.), TVector3(0.,1.,0.));
400 lastPoint[trackID]->Position(svtx);
402 lastPoint[trackID]->Momentum(smom);
404 FairTrackParP* lastPar=
new FairTrackParP(svtx, smom,
407 TVector3(1.,0.,0.), TVector3(0.,1.,0.));
409 if(
fVerbose>3) Info(
"Exec",
"Store candidate at %i",trackID);
411 if(
fVerbose>3) Info(
"AddTrack",
"Adding a Track.");
412 TClonesArray &pndtracks = *
fTracks;
415 Int_t size = pndtrackcands.GetEntriesFast();
416 if(pndtracks.GetEntriesFast() != size) {
417 Error(
"Exec",
"Arrays out of synchronisation: %i tracks, %i cands. Abort event."
418 ,pndtracks.GetEntriesFast(),pndtrackcands.GetEntriesFast());
423 new(pndtracks[size])
PndTrack(*firstPar, *lastPar, *tcand,0,0,1,mc->
GetPdgCode(),trackID,FairRootManager::Instance()->GetBranchId(
"MCTrack"));
429 if(
fVerbose>3) Info(
"Exec",
"End eventloop.");
435 std::cout <<
" Found "<<
fTracks->GetEntriesFast() <<
" tracks\n";
450 if (minFtsHitsPerTrack<1)
452 minFtsHitsPerTrack=1;
465 rannn = gRandom->Gaus(vec.X(),sigma.X());
468 rannn = gRandom->Gaus(vec.Y(),sigma.Y());
471 rannn = gRandom->Gaus(vec.Z(),sigma.Z());
virtual void Exec(Option_t *option)
Int_t fMinFtsHitsPerTrack
Array of track IDs (Links)
void SetTrackOutput(TString name="FTSTrkIdeal")
PndTrackCandHit GetSortedHit(UInt_t i)
cout<< "POINTs for new FwEndCap == "<< tsim-> GetEntriesFast()
Bool_t fBranchActive[4]
Array of Branch IDs.
TClonesArray * fHits[4]
Array of event's points.
cout<< "blue = Monte Carlo "<< endl;cout<< "red = Helix Hit "<< endl;cout<< "green = Center Of Tubes "<< endl;for(Int_t k=0;k< track->GetEntriesFast();k++){PndSttTrack *stttrack=(PndSttTrack *) track-> At(k)
void SmearFWD(TVector3 &vec, const TVector3 &sigma)
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
TClonesArray * fTubeArrayFts
virtual InitStatus Init()
TClonesArray * fTrackCands
Array of disabled stations.
Int_t fBranchIDs[4]
Array of event's hits.
PndGeoFtsPar * fFtsParameters
Particle DB.
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)
ClassImp(PndFtsTrackerIdeal)
Int_t SetMinFtsHitsPerTrack(Int_t minFtsHitsPerTrack=5)
TClonesArray * fTracks
Array of found track candidates.
TClonesArray * FillTubeArray()
this function will be used in PndFtsHitProducesRealFast
TClonesArray * fMCPoints[4]
Array of PndMCTrack.
virtual ~PndFtsTrackerIdeal()
std::map< int, bool > fStationsDisabled
Array of Branch Activeness.