1 #include "AliHBTReaderESD.h"
2 //____________________________________________________________________
3 //////////////////////////////////////////////////////////////////////
5 // class AliHBTReaderESD //
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>
28 #include "AliHBTRun.h"
29 #include "AliHBTEvent.h"
30 #include "AliHBTParticle.h"
31 #include "AliHBTParticleCut.h"
32 #include "AliHBTTrackPoints.h"
33 #include "AliHBTClusterMap.h"
35 ClassImp(AliHBTReaderESD)
37 AliHBTReaderESD::AliHBTReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
38 fESDFileName(esdfilename),
39 fGAlFileName(galfilename),
43 fReadParticles(kFALSE),
44 fCheckParticlePID(kFALSE),
51 fTPCChi2PerClustMin(0.0),
52 fTPCChi2PerClustMax(10e5),
78 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
79 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
81 /********************************************************************/
83 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
85 fESDFileName(esdfilename),
86 fGAlFileName(galfilename),
90 fReadParticles(kFALSE),
91 fCheckParticlePID(kFALSE),
98 fTPCChi2PerClustMin(0.0),
99 fTPCChi2PerClustMax(10e5),
124 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
125 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
127 /********************************************************************/
129 AliHBTReaderESD::~AliHBTReaderESD()
136 /**********************************************************/
137 Int_t AliHBTReaderESD::ReadNext()
139 //reads next event from fFile
140 //fRunLoader is for reading Kine
142 if (AliHBTParticle::GetDebug())
143 Info("ReadNext","Entered");
145 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
146 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
148 fParticlesEvent->Reset();
149 fTracksEvent->Reset();
151 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
155 fFile = OpenFile(fCurrentDir);//rl is opened here
158 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
163 fKeyIterator = new TIter(fFile->GetListOfKeys());
165 // fFile->GetListOfKeys()->Print();
167 TKey* key = (TKey*)fKeyIterator->Next();
170 if (AliHBTParticle::GetDebug() > 2 )
172 Info("ReadNext","No more keys.");
177 delete fFile;//we have to assume there is no more ESD objects in the fFile
186 // TObject* esdobj = key->ReadObj();
187 // if (esdobj == 0x0)
189 // if (AliHBTParticle::GetDebug() > 2 )
191 // Info("ReadNext","Key read NULL. Key Name is %s",key->GetName());
197 // AliESD* esd = dynamic_cast<AliESD*>(esdobj);
199 TString esdname = "ESD";
200 esdname+=fCurrentEvent;
201 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
204 // if (AliHBTParticle::GetDebug() > 2 )
206 // Info("ReadNext","This key is not an AliESD object %s",key->GetName());
208 if (AliHBTParticle::GetDebug() > 2 )
210 Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
215 delete fFile;//we have to assume there is no more ESD objects in the fFile
227 return 0;//success -> read one event
228 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
230 return 1; //no more directories to read
232 /**********************************************************/
234 Int_t AliHBTReaderESD::ReadESD(AliESD* esd)
236 //****** Tentative particle type "concentrations"
237 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
239 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
240 Double_t w[kNSpecies];
241 Double_t mom[3];//momentum
242 Double_t pos[3];//position
243 Double_t vertexpos[3];//vertex position
247 Error("ReadESD","ESD is NULL");
251 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
254 Error("ReadESD","Can not get PDG Database Instance.");
258 Float_t mf = esd->GetMagneticField();
260 if ( (mf == 0.0) && (fNTrackPoints > 0) )
262 Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
266 AliStack* stack = 0x0;
267 if (fReadParticles && fRunLoader)
269 fRunLoader->GetEvent(fCurrentEvent);
270 stack = fRunLoader->Stack();
273 const AliESDVertex* vertex = esd->GetVertex();
276 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
283 vertex->GetXYZ(vertexpos);
286 if (AliHBTParticle::GetDebug() > 0)
288 Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
291 Info("ReadESD","Reading Event %d",fCurrentEvent);
293 Int_t ntr = esd->GetNumberOfTracks();
294 Info("ReadESD","Found %d tracks.",ntr);
295 for (Int_t i = 0;i<ntr; i++)
297 AliESDtrack *esdtrack = esd->GetTrack(i);
300 Error("Next","Can not get track %d", i);
304 //if (esdtrack->HasVertexParameters() == kFALSE)
305 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
307 if (AliHBTParticle::GetDebug() > 2)
308 Info("ReadNext","Particle skipped: Data at vertex not available.");
314 if ((esdtrack->GetStatus() & AliESDtrack::kTPCin) == kFALSE)
316 if (AliHBTParticle::GetDebug() > 2)
317 Info("ReadNext","Particle skipped: Was not reconstructed in TPC.");
321 if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE)
323 if (AliHBTParticle::GetDebug() > 2)
324 Info("ReadNext","Particle skipped: PID BIT is not set.");
331 esdtrack->GetConstrainedExternalParameters(extx,extp);
334 if (AliHBTParticle::GetDebug() > 2)
335 Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
338 esdtrack->GetESDpid(pidtable);
339 esdtrack->GetConstrainedPxPyPz(mom);
340 esdtrack->GetConstrainedXYZ(pos);
341 pos[0] -= vertexpos[0];//we are interested only in relative position to Primary vertex at this point
342 pos[1] -= vertexpos[1];
343 pos[2] -= vertexpos[2];
345 Int_t charge = (extp[4] > 0)?1:-1;//if curvature=charg/Pt is positive charge is positive
347 //Particle from kinematics
348 AliHBTParticle* particle = 0;
349 Bool_t keeppart = kFALSE;
350 if ( fReadParticles && stack )
352 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
353 TParticle *p = stack->Particle(esdtrack->GetLabel());
356 Error("ReadNext","Can not find track with such label.");
359 if (fCheckParticlePID)
361 if(Pass(p->GetPdgCode()))
363 if ( AliHBTParticle::GetDebug() > 5 )
364 Info("ReadNext","Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode());
365 continue; //check if we are intersted with particles of this type
368 // if(p->GetPdgCode()<0) charge = -1;
369 particle = new AliHBTParticle(*p,i);
373 if(CheckTrack(esdtrack)) continue;
375 //Here we apply Bayes' formula
377 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
380 if (AliHBTParticle::GetDebug() > 2)
381 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
385 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
387 if (AliHBTParticle::GetDebug() > 4)
389 Info("ReadNext","###########################################################################");
390 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
391 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
392 TString msg("Pid list got from track:");
393 for (Int_t s = 0;s<kNSpecies;s++)
398 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
405 Info("ReadNext","%s",msg.Data());
406 }//if (AliHBTParticle::GetDebug()>4)
408 AliHBTTrackPoints* tpts = 0x0;
409 if (fNTrackPoints > 0)
411 tpts = new AliHBTTrackPoints(fNTrackPoints,esdtrack,mf,fdR);
414 AliHBTClusterMap* cmap = 0x0;
417 cmap = new AliHBTClusterMap(esdtrack);
420 for (Int_t s = 0; s<kNSpecies; s++)
422 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
426 if ( AliHBTParticle::GetDebug() > 5 )
427 Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
433 if ( AliHBTParticle::GetDebug() > 5 )
434 Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
435 continue; //check if we are intersted with particles of this type
438 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
439 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
441 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
442 mom[0], mom[1], mom[2], tEtot,
443 pos[0], pos[1], pos[2], 0.);
444 //copy probabilitis of other species (if not zero)
445 for (Int_t k = 0; k<kNSpecies; k++)
447 if (k == s) continue;
448 if (w[k] == 0.0) continue;
449 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
452 if(Pass(track))//check if meets all criteria of any of our cuts
453 //if it does not delete it and take next good track
455 if ( AliHBTParticle::GetDebug() > 4 )
456 Info("ReadNext","Track did not pass the cut");
461 //Single Particle cuts on cluster map and track points rather do not have sense
464 track->SetTrackPoints(tpts);
469 track->SetClusterMap(cmap);
472 fTracksEvent->AddParticle(track);
473 if (particle) fParticlesEvent->AddParticle(particle);
476 if (AliHBTParticle::GetDebug() > 4 )
478 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
480 if (particle) particle->Print();
481 Info("ReadNext","\n----------------------------------------------\n");
483 }//for (Int_t s = 0; s<kNSpecies; s++)
485 if (keeppart == kFALSE)
487 delete particle;//particle was not stored in event
492 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
494 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
495 fTracksEvent->GetNumberOfParticles(), fParticlesEvent->GetNumberOfParticles(),
496 fNEventsRead,fCurrentEvent,fCurrentDir);
497 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
501 /**********************************************************/
503 void AliHBTReaderESD::Rewind()
514 if (fTrackCounter) fTrackCounter->Reset();
516 /**********************************************************/
518 TFile* AliHBTReaderESD::OpenFile(Int_t n)
520 //opens fFile with kine tree
522 const TString& dirname = GetDirName(n);
525 Error("OpenFiles","Can not get directory name");
528 TString filename = dirname +"/"+ fESDFileName;
529 TFile *ret = TFile::Open(filename.Data());
533 Error("OpenFiles","Can't open fFile %s",filename.Data());
538 Error("OpenFiles","Can't open fFile %s",filename.Data());
544 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
545 if (fRunLoader == 0x0)
547 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
552 fRunLoader->LoadHeader();
553 if (fRunLoader->LoadKinematics())
555 Error("Next","Error occured while loading kinematics.");
564 /**********************************************************/
566 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
568 //returns pdg code from the PID index
569 //ask jura about charge
588 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);
593 /********************************************************************/
594 Bool_t AliHBTReaderESD::CheckTrack(AliESDtrack* t) const
596 //Performs check of the track
598 if ( (t->GetConstrainedChi2() < fChi2Min) || (t->GetConstrainedChi2() > fChi2Max) ) return kTRUE;
600 if ( (t->GetTPCclusters(0x0) < fNTPCClustMin) || (t->GetTPCclusters(0x0) > fNTPCClustMax) ) return kTRUE;
602 if (t->GetTPCclusters(0x0) > 0)
604 Float_t chisqpercl = t->GetTPCchi2()/((Double_t)t->GetTPCclusters(0x0));
605 if ( (chisqpercl < fTPCChi2PerClustMin) || (chisqpercl > fTPCChi2PerClustMax) ) return kTRUE;
609 t->GetConstrainedExternalCovariance(cc);
611 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
612 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
613 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
614 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
615 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
618 t->GetInnerExternalCovariance(cc);
620 if ( (cc[0] < fTPCC00Min) || (cc[0] > fTPCC00Max) ) return kTRUE;
621 if ( (cc[2] < fTPCC11Min) || (cc[2] > fTPCC11Max) ) return kTRUE;
622 if ( (cc[5] < fTPCC22Min) || (cc[5] > fTPCC22Max) ) return kTRUE;
623 if ( (cc[9] < fTPCC33Min) || (cc[9] > fTPCC33Max) ) return kTRUE;
624 if ( (cc[14] < fTPCC44Min) || (cc[14] > fTPCC44Max) ) return kTRUE;
629 /********************************************************************/
631 void AliHBTReaderESD::SetChi2Range(Float_t min, Float_t max)
633 //sets range of Chi2 per Cluster
637 /********************************************************************/
639 void AliHBTReaderESD::SetTPCNClustersRange(Int_t min,Int_t max)
641 //sets range of Number Of Clusters that tracks have to have
645 /********************************************************************/
647 void AliHBTReaderESD::SetTPCChi2PerCluserRange(Float_t min, Float_t max)
649 //sets range of Chi2 per Cluster
650 fTPCChi2PerClustMin = min;
651 fTPCChi2PerClustMax = max;
653 /********************************************************************/
655 void AliHBTReaderESD::SetC00Range(Float_t min, Float_t max)
657 //Sets range of C00 parameter of covariance matrix of the track
658 //it defines uncertainty of the momentum
662 /********************************************************************/
664 void AliHBTReaderESD::SetC11Range(Float_t min, Float_t max)
666 //Sets range of C11 parameter of covariance matrix of the track
667 //it defines uncertainty of the momentum
671 /********************************************************************/
673 void AliHBTReaderESD::SetC22Range(Float_t min, Float_t max)
675 //Sets range of C22 parameter of covariance matrix of the track
676 //it defines uncertainty of the momentum
680 /********************************************************************/
682 void AliHBTReaderESD::SetC33Range(Float_t min, Float_t max)
684 //Sets range of C33 parameter of covariance matrix of the track
685 //it defines uncertainty of the momentum
689 /********************************************************************/
691 void AliHBTReaderESD::SetC44Range(Float_t min, Float_t max)
693 //Sets range of C44 parameter of covariance matrix of the track
694 //it defines uncertainty of the momentum