1 #include "AliReaderESD.h"
2 //____________________________________________________________________
3 //////////////////////////////////////////////////////////////////////
5 // class AliReaderESD //
7 // reader for ALICE Event Summary Data (ESD). //
9 // Piotr.Skowronski@cern.ch //
11 //////////////////////////////////////////////////////////////////////
15 #include <TObjString.h>
19 #include <TParticle.h>
23 #include <AliRunLoader.h>
25 #include <AliESDtrack.h>
26 #include <AliKalmanTrack.h>
29 #include "AliAnalysis.h"
30 #include "AliAODRun.h"
32 #include "AliAODParticle.h"
33 #include "AliAODParticleCut.h"
34 #include "AliTrackPoints.h"
35 #include "AliClusterMap.h"
37 ClassImp(AliReaderESD)
39 AliReaderESD::AliReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
40 fESDFileName(esdfilename),
41 fGAlFileName(galfilename),
46 fCheckParticlePID(kFALSE),
47 fReadMostProbableOnly(kFALSE),
51 fITSTrackPoints(kFALSE),
55 fTPCChi2PerClustMin(0.0),
56 fTPCChi2PerClustMax(10e5),
82 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
83 Fatal("AliReaderESD","ESD defintions probobly changed. Ask Youra.");
85 /********************************************************************/
87 AliReaderESD::AliReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
89 fESDFileName(esdfilename),
90 fGAlFileName(galfilename),
95 fCheckParticlePID(kFALSE),
96 fReadMostProbableOnly(kFALSE),
100 fITSTrackPoints(kFALSE),
104 fTPCChi2PerClustMin(0.0),
105 fTPCChi2PerClustMax(10e5),
130 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
131 Fatal("AliReaderESD","ESD defintions probobly changed. Ask Youra.");
133 /********************************************************************/
135 AliReaderESD::~AliReaderESD()
142 /**********************************************************/
143 Int_t AliReaderESD::ReadNext()
145 //reads next event from fFile
146 //fRunLoader is for reading Kine
148 if (AliVAODParticle::GetDebug())
149 Info("ReadNext","Entered");
151 if (fEventSim == 0x0) fEventSim = new AliAOD();
152 if (fEventRec == 0x0) fEventRec = new AliAOD();
157 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
161 fFile = OpenFile(fCurrentDir);//rl is opened here
164 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
169 fKeyIterator = new TIter(fFile->GetListOfKeys());
171 // fFile->GetListOfKeys()->Print();
173 TKey* key = (TKey*)fKeyIterator->Next();
176 if (AliVAODParticle::GetDebug() > 2 )
178 Info("ReadNext","No more keys.");
183 delete fFile;//we have to assume there is no more ESD objects in the fFile
192 // TObject* esdobj = key->ReadObj();
193 // if (esdobj == 0x0)
195 // if (AliVAODParticle::GetDebug() > 2 )
197 // Info("ReadNext","Key read NULL. Key Name is %s",key->GetName());
203 // AliESD* esd = dynamic_cast<AliESD*>(esdobj);
205 TString esdname = "ESD";
206 esdname+=fCurrentEvent;
207 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
210 // if (AliVAODParticle::GetDebug() > 2 )
212 // Info("ReadNext","This key is not an AliESD object %s",key->GetName());
214 if (AliVAODParticle::GetDebug() > 2 )
216 Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
221 delete fFile;//we have to assume there is no more ESD objects in the fFile
233 return 0;//success -> read one event
234 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
236 return 1; //no more directories to read
238 /**********************************************************/
240 Int_t AliReaderESD::ReadESD(AliESD* esd)
242 //****** Tentative particle type "concentrations"
243 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
245 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
246 Double_t w[kNSpecies];
247 Double_t mom[3];//momentum
248 Double_t pos[3];//position
249 Double_t vertexpos[3];//vertex position
253 Error("ReadESD","ESD is NULL");
257 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
260 Error("ReadESD","Can not get PDG Database Instance.");
264 Float_t mf = esd->GetMagneticField();
266 if ( (mf == 0.0) && ((fNTrackPoints > 0) || fITSTrackPoints) )
268 Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
274 Info("ReadESD","Magnetic Field is %f",mf/10.);
275 AliKalmanTrack::SetMagneticField(mf/10.);
278 AliStack* stack = 0x0;
279 if (fReadSim && fRunLoader)
281 fRunLoader->GetEvent(fCurrentEvent);
282 stack = fRunLoader->Stack();
285 const AliESDVertex* vertex = esd->GetVertex();
288 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
295 vertex->GetXYZ(vertexpos);
298 if (AliVAODParticle::GetDebug() > 0)
300 Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
303 Info("ReadESD","Reading Event %d",fCurrentEvent);
305 Int_t ntr = esd->GetNumberOfTracks();
306 Info("ReadESD","Found %d tracks.",ntr);
307 for (Int_t i = 0;i<ntr; i++)
309 AliESDtrack *esdtrack = esd->GetTrack(i);
312 Error("Next","Can not get track %d", i);
316 //if (esdtrack->HasVertexParameters() == kFALSE)
317 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
319 if (AliVAODParticle::GetDebug() > 2)
320 Info("ReadNext","Particle skipped: Data at vertex not available.");
326 if ((esdtrack->GetStatus() & AliESDtrack::kTPCin) == kFALSE)
328 if (AliVAODParticle::GetDebug() > 2)
329 Info("ReadNext","Particle skipped: Was not reconstructed in TPC.");
334 if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE)
336 if (AliVAODParticle::GetDebug() > 2)
337 Info("ReadNext","Particle skipped: PID BIT is not set.");
344 esdtrack->GetConstrainedExternalParameters(extx,extp);
347 if (AliVAODParticle::GetDebug() > 2)
348 Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
351 esdtrack->GetESDpid(pidtable);
352 esdtrack->GetConstrainedPxPyPz(mom);
353 esdtrack->GetConstrainedXYZ(pos);
354 pos[0] -= vertexpos[0];//we are interested only in relative position to Primary vertex at this point
355 pos[1] -= vertexpos[1];
356 pos[2] -= vertexpos[2];
358 Int_t charge = (extp[4] > 0)?1:-1;//if curvature=charg/Pt is positive charge is positive
360 //Particle from kinematics
361 AliAODParticle* particle = 0;
362 Bool_t keeppart = kFALSE;
363 if ( fReadSim && stack )
365 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
366 TParticle *p = stack->Particle(esdtrack->GetLabel());
369 Error("ReadNext","Can not find track with such label.");
373 if (fCheckParticlePID)
375 if(Pass(p->GetPdgCode()))
377 if ( AliVAODParticle::GetDebug() > 5 )
378 Info("ReadNext","Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode());
379 continue; //check if we are intersted with particles of this type
382 // if(p->GetPdgCode()<0) charge = -1;
383 particle = new AliAODParticle(*p,i);
387 if(CheckTrack(esdtrack)) continue;
389 //Here we apply Bayes' formula
391 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
394 if (AliVAODParticle::GetDebug() > 2)
395 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
399 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
401 if (AliVAODParticle::GetDebug() > 4)
403 Info("ReadNext","###########################################################################");
404 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
405 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
406 TString msg("Pid list got from track:");
407 for (Int_t s = 0;s<kNSpecies;s++)
412 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
419 Info("ReadNext","%s",msg.Data());
420 }//if (AliVAODParticle::GetDebug()>4)
422 AliTrackPoints* tpts = 0x0;
423 if (fNTrackPoints > 0)
425 tpts = new AliTrackPoints(fNTrackPoints,esdtrack,mf,fdR);
426 tpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
429 AliTrackPoints* itstpts = 0x0;
432 itstpts = new AliTrackPoints(AliTrackPoints::kITS,esdtrack);
433 itstpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
436 AliClusterMap* cmap = 0x0;
439 cmap = new AliClusterMap(esdtrack);
442 //If this flag fReadMostProbableOnly is false the
443 //loop over species (see "LOOPPIDS") is over all possible PIDs
444 //in other case the most probablle PID is searched
445 //and the loop is limited to that PID only
447 Int_t firstspecie = 0;
448 Int_t lastspecie = kNSpecies;
450 if (fReadMostProbableOnly)
452 //find the most probable PID
454 Float_t maxprob = w[0];
455 for (Int_t s=1; s<AliESDtrack::kSPECIES; s++)
464 lastspecie = spec + 1;
467 for (Int_t s = firstspecie; s<lastspecie; s++)//LOOPPIDS
469 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
473 if ( AliVAODParticle::GetDebug() > 5 )
474 Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
480 if ( AliVAODParticle::GetDebug() > 5 )
481 Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
482 continue; //check if we are intersted with particles of this type
485 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
486 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
488 AliAODParticle* track = new AliAODParticle(pdgcode, w[s],i,
489 mom[0], mom[1], mom[2], tEtot,
490 pos[0], pos[1], pos[2], 0.);
491 //copy probabilitis of other species (if not zero)
492 for (Int_t k = 0; k<kNSpecies; k++)
494 if (k == s) continue;
495 if (w[k] == 0.0) continue;
496 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
499 if(Pass(track))//check if meets all criteria of any of our cuts
500 //if it does not delete it and take next good track
502 if ( AliVAODParticle::GetDebug() > 4 )
503 Info("ReadNext","Track did not pass the cut");
508 //Single Particle cuts on cluster map and track points rather do not have sense
511 track->SetTPCTrackPoints(tpts);
516 track->SetITSTrackPoints(itstpts);
521 track->SetClusterMap(cmap);
524 fEventRec->AddParticle(track);
525 if (particle) fEventSim->AddParticle(particle);
528 if (AliVAODParticle::GetDebug() > 4 )
530 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
532 if (particle) particle->Print();
533 Info("ReadNext","\n----------------------------------------------\n");
535 }//for (Int_t s = 0; s<kNSpecies; s++)
537 if (keeppart == kFALSE)
539 delete particle;//particle was not stored in event
546 if (particle->P() < 0.00001)
548 Info("ReadNext","###################################");
549 Info("ReadNext","###################################");
550 Info("ReadNext","Track Label %d",esdtrack->GetLabel());
551 TParticle *p = stack->Particle(esdtrack->GetLabel());
559 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
561 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
562 fEventRec->GetNumberOfParticles(), fEventSim->GetNumberOfParticles(),
563 fNEventsRead,fCurrentEvent,fCurrentDir);
564 fTrackCounter->Fill(fEventRec->GetNumberOfParticles());
568 /**********************************************************/
570 void AliReaderESD::Rewind()
581 if (fTrackCounter) fTrackCounter->Reset();
583 /**********************************************************/
585 TFile* AliReaderESD::OpenFile(Int_t n)
587 //opens fFile with kine tree
589 const TString& dirname = GetDirName(n);
592 Error("OpenFiles","Can not get directory name");
595 TString filename = dirname +"/"+ fESDFileName;
596 TFile *ret = TFile::Open(filename.Data());
600 Error("OpenFiles","Can't open fFile %s",filename.Data());
605 Error("OpenFiles","Can't open fFile %s",filename.Data());
611 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
612 if (fRunLoader == 0x0)
614 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
619 fRunLoader->LoadHeader();
620 if (fRunLoader->LoadKinematics())
622 Error("Next","Error occured while loading kinematics.");
631 /**********************************************************/
633 Int_t AliReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
635 //returns pdg code from the PID index
636 //ask jura about charge
655 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);
660 /********************************************************************/
661 Bool_t AliReaderESD::CheckTrack(AliESDtrack* t) const
663 //Performs check of the track
665 if ( (t->GetConstrainedChi2() < fChi2Min) || (t->GetConstrainedChi2() > fChi2Max) ) return kTRUE;
667 if ( (t->GetTPCclusters(0x0) < fNTPCClustMin) || (t->GetTPCclusters(0x0) > fNTPCClustMax) ) return kTRUE;
669 if (t->GetTPCclusters(0x0) > 0)
671 Float_t chisqpercl = t->GetTPCchi2()/((Double_t)t->GetTPCclusters(0x0));
672 if ( (chisqpercl < fTPCChi2PerClustMin) || (chisqpercl > fTPCChi2PerClustMax) ) return kTRUE;
676 t->GetConstrainedExternalCovariance(cc);
678 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
679 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
680 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
681 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
682 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
685 t->GetInnerExternalCovariance(cc);
687 if ( (cc[0] < fTPCC00Min) || (cc[0] > fTPCC00Max) ) return kTRUE;
688 if ( (cc[2] < fTPCC11Min) || (cc[2] > fTPCC11Max) ) return kTRUE;
689 if ( (cc[5] < fTPCC22Min) || (cc[5] > fTPCC22Max) ) return kTRUE;
690 if ( (cc[9] < fTPCC33Min) || (cc[9] > fTPCC33Max) ) return kTRUE;
691 if ( (cc[14] < fTPCC44Min) || (cc[14] > fTPCC44Max) ) return kTRUE;
696 /********************************************************************/
698 void AliReaderESD::SetChi2Range(Float_t min, Float_t max)
700 //sets range of Chi2 per Cluster
704 /********************************************************************/
706 void AliReaderESD::SetTPCNClustersRange(Int_t min,Int_t max)
708 //sets range of Number Of Clusters that tracks have to have
712 /********************************************************************/
714 void AliReaderESD::SetTPCChi2PerCluserRange(Float_t min, Float_t max)
716 //sets range of Chi2 per Cluster
717 fTPCChi2PerClustMin = min;
718 fTPCChi2PerClustMax = max;
720 /********************************************************************/
722 void AliReaderESD::SetC00Range(Float_t min, Float_t max)
724 //Sets range of C00 parameter of covariance matrix of the track
725 //it defines uncertainty of the momentum
729 /********************************************************************/
731 void AliReaderESD::SetC11Range(Float_t min, Float_t max)
733 //Sets range of C11 parameter of covariance matrix of the track
734 //it defines uncertainty of the momentum
738 /********************************************************************/
740 void AliReaderESD::SetC22Range(Float_t min, Float_t max)
742 //Sets range of C22 parameter of covariance matrix of the track
743 //it defines uncertainty of the momentum
747 /********************************************************************/
749 void AliReaderESD::SetC33Range(Float_t min, Float_t max)
751 //Sets range of C33 parameter of covariance matrix of the track
752 //it defines uncertainty of the momentum
756 /********************************************************************/
758 void AliReaderESD::SetC44Range(Float_t min, Float_t max)
760 //Sets range of C44 parameter of covariance matrix of the track
761 //it defines uncertainty of the momentum