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),
50 fTPCChi2PerClustMin(0.0),
51 fTPCChi2PerClustMax(10e5),
77 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
78 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
80 /********************************************************************/
82 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
84 fESDFileName(esdfilename),
85 fGAlFileName(galfilename),
89 fReadParticles(kFALSE),
90 fCheckParticlePID(kFALSE),
96 fTPCChi2PerClustMin(0.0),
97 fTPCChi2PerClustMax(10e5),
122 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
123 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
125 /********************************************************************/
127 AliHBTReaderESD::~AliHBTReaderESD()
134 /**********************************************************/
135 Int_t AliHBTReaderESD::ReadNext()
137 //reads next event from fFile
138 //fRunLoader is for reading Kine
140 if (AliHBTParticle::GetDebug())
141 Info("ReadNext","Entered");
143 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
144 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
146 fParticlesEvent->Reset();
147 fTracksEvent->Reset();
149 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
153 fFile = OpenFile(fCurrentDir);//rl is opened here
156 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
161 fKeyIterator = new TIter(fFile->GetListOfKeys());
163 // fFile->GetListOfKeys()->Print();
165 TKey* key = (TKey*)fKeyIterator->Next();
168 if (AliHBTParticle::GetDebug() > 2 )
170 Info("ReadNext","No more keys.");
175 delete fFile;//we have to assume there is no more ESD objects in the fFile
184 // TObject* esdobj = key->ReadObj();
185 // if (esdobj == 0x0)
187 // if (AliHBTParticle::GetDebug() > 2 )
189 // Info("ReadNext","Key read NULL. Key Name is %s",key->GetName());
195 // AliESD* esd = dynamic_cast<AliESD*>(esdobj);
197 TString esdname = "ESD";
198 esdname+=fCurrentEvent;
199 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
202 // if (AliHBTParticle::GetDebug() > 2 )
204 // Info("ReadNext","This key is not an AliESD object %s",key->GetName());
206 if (AliHBTParticle::GetDebug() > 2 )
208 Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
213 delete fFile;//we have to assume there is no more ESD objects in the fFile
225 return 0;//success -> read one event
226 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
228 return 1; //no more directories to read
230 /**********************************************************/
232 Int_t AliHBTReaderESD::ReadESD(AliESD* esd)
234 //****** Tentative particle type "concentrations"
235 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
237 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
238 Double_t w[kNSpecies];
239 Double_t mom[3];//momentum
240 Double_t pos[3];//position
241 Double_t vertexpos[3];//vertex position
245 Error("ReadESD","ESD is NULL");
249 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
252 Error("ReadESD","Can not get PDG Database Instance.");
256 Float_t mf = esd->GetMagneticField();
258 if ( (mf == 0.0) && (fNTrackPoints > 0) )
260 Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
264 AliStack* stack = 0x0;
265 if (fReadParticles && fRunLoader)
267 fRunLoader->GetEvent(fCurrentEvent);
268 stack = fRunLoader->Stack();
271 const AliESDVertex* vertex = esd->GetVertex();
274 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
281 vertex->GetXYZ(vertexpos);
284 if (AliHBTParticle::GetDebug() > 0)
286 Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
289 Info("ReadESD","Reading Event %d",fCurrentEvent);
291 Int_t ntr = esd->GetNumberOfTracks();
292 Info("ReadESD","Found %d tracks.",ntr);
293 for (Int_t i = 0;i<ntr; i++)
295 AliESDtrack *esdtrack = esd->GetTrack(i);
298 Error("Next","Can not get track %d", i);
302 //if (esdtrack->HasVertexParameters() == kFALSE)
303 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
305 if (AliHBTParticle::GetDebug() > 2)
306 Info("ReadNext","Particle skipped: Data at vertex not available.");
310 if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE)
312 if (AliHBTParticle::GetDebug() > 2)
313 Info("ReadNext","Particle skipped: PID BIT is not set.");
320 esdtrack->GetConstrainedExternalParameters(extx,extp);
323 if (AliHBTParticle::GetDebug() > 2)
324 Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
327 esdtrack->GetESDpid(pidtable);
328 esdtrack->GetConstrainedPxPyPz(mom);
329 esdtrack->GetConstrainedXYZ(pos);
330 pos[0] -= vertexpos[0];//we are interested only in relative position to Primary vertex at this point
331 pos[1] -= vertexpos[1];
332 pos[2] -= vertexpos[2];
334 Int_t charge = (extp[4] > 0)?1:-1;//if curvature=charg/Pt is positive charge is positive
336 //Particle from kinematics
337 AliHBTParticle* particle = 0;
338 Bool_t keeppart = kFALSE;
339 if ( fReadParticles && stack )
341 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
342 TParticle *p = stack->Particle(esdtrack->GetLabel());
345 Error("ReadNext","Can not find track with such label.");
348 if (fCheckParticlePID)
350 if(Pass(p->GetPdgCode()))
352 if ( AliHBTParticle::GetDebug() > 5 )
353 Info("ReadNext","Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode());
354 continue; //check if we are intersted with particles of this type
357 // if(p->GetPdgCode()<0) charge = -1;
358 particle = new AliHBTParticle(*p,i);
362 if(CheckTrack(esdtrack)) continue;
364 //Here we apply Bayes' formula
366 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
369 if (AliHBTParticle::GetDebug() > 2)
370 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
374 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
376 if (AliHBTParticle::GetDebug() > 4)
378 Info("ReadNext","###########################################################################");
379 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
380 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
381 TString msg("Pid list got from track:");
382 for (Int_t s = 0;s<kNSpecies;s++)
387 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
394 Info("ReadNext","%s",msg.Data());
395 }//if (AliHBTParticle::GetDebug()>4)
397 AliHBTTrackPoints* tpts = 0x0;
398 if (fNTrackPoints > 0)
400 tpts = new AliHBTTrackPoints(fNTrackPoints,esdtrack,mf,fdR);
403 AliHBTClusterMap* cmap = 0x0;
406 cmap = new AliHBTClusterMap(esdtrack);
409 for (Int_t s = 0; s<kNSpecies; s++)
411 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
415 if ( AliHBTParticle::GetDebug() > 5 )
416 Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
422 if ( AliHBTParticle::GetDebug() > 5 )
423 Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
424 continue; //check if we are intersted with particles of this type
427 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
428 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
430 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
431 mom[0], mom[1], mom[2], tEtot,
432 pos[0], pos[1], pos[2], 0.);
433 //copy probabilitis of other species (if not zero)
434 for (Int_t k = 0; k<kNSpecies; k++)
436 if (k == s) continue;
437 if (w[k] == 0.0) continue;
438 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
441 if(Pass(track))//check if meets all criteria of any of our cuts
442 //if it does not delete it and take next good track
444 if ( AliHBTParticle::GetDebug() > 4 )
445 Info("ReadNext","Track did not pass the cut");
450 //Single Particle cuts on cluster map and track points rather do not have sense
453 track->SetTrackPoints(tpts);
458 track->SetClusterMap(cmap);
461 fTracksEvent->AddParticle(track);
462 if (particle) fParticlesEvent->AddParticle(particle);
465 if (AliHBTParticle::GetDebug() > 4 )
467 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
469 if (particle) particle->Print();
470 Info("ReadNext","\n----------------------------------------------\n");
472 }//for (Int_t s = 0; s<kNSpecies; s++)
474 if (keeppart == kFALSE)
476 delete particle;//particle was not stored in event
481 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
483 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
484 fTracksEvent->GetNumberOfParticles(), fParticlesEvent->GetNumberOfParticles(),
485 fNEventsRead,fCurrentEvent,fCurrentDir);
486 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
490 /**********************************************************/
492 void AliHBTReaderESD::Rewind()
503 if (fTrackCounter) fTrackCounter->Reset();
505 /**********************************************************/
507 TFile* AliHBTReaderESD::OpenFile(Int_t n)
509 //opens fFile with kine tree
511 const TString& dirname = GetDirName(n);
514 Error("OpenFiles","Can not get directory name");
517 TString filename = dirname +"/"+ fESDFileName;
518 TFile *ret = TFile::Open(filename.Data());
522 Error("OpenFiles","Can't open fFile %s",filename.Data());
527 Error("OpenFiles","Can't open fFile %s",filename.Data());
533 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
534 if (fRunLoader == 0x0)
536 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
541 fRunLoader->LoadHeader();
542 if (fRunLoader->LoadKinematics())
544 Error("Next","Error occured while loading kinematics.");
553 /**********************************************************/
555 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
557 //returns pdg code from the PID index
558 //ask jura about charge
577 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);
582 /********************************************************************/
583 Bool_t AliHBTReaderESD::CheckTrack(AliESDtrack* t) const
585 //Performs check of the track
587 if ( (t->GetConstrainedChi2() < fChi2Min) || (t->GetConstrainedChi2() > fChi2Max) ) return kTRUE;
589 if ( (t->GetTPCclusters(0x0) < fNTPCClustMin) || (t->GetTPCclusters(0x0) > fNTPCClustMax) ) return kTRUE;
591 if (t->GetTPCclusters(0x0) > 0)
593 Float_t chisqpercl = t->GetTPCchi2()/((Double_t)t->GetTPCclusters(0x0));
594 if ( (chisqpercl < fTPCChi2PerClustMin) || (chisqpercl > fTPCChi2PerClustMax) ) return kTRUE;
598 t->GetConstrainedExternalCovariance(cc);
600 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
601 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
602 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
603 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
604 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
607 t->GetInnerExternalCovariance(cc);
609 if ( (cc[0] < fTPCC00Min) || (cc[0] > fTPCC00Max) ) return kTRUE;
610 if ( (cc[2] < fTPCC11Min) || (cc[2] > fTPCC11Max) ) return kTRUE;
611 if ( (cc[5] < fTPCC22Min) || (cc[5] > fTPCC22Max) ) return kTRUE;
612 if ( (cc[9] < fTPCC33Min) || (cc[9] > fTPCC33Max) ) return kTRUE;
613 if ( (cc[14] < fTPCC44Min) || (cc[14] > fTPCC44Max) ) return kTRUE;
618 /********************************************************************/
620 void AliHBTReaderESD::SetChi2Range(Float_t min, Float_t max)
622 //sets range of Chi2 per Cluster
626 /********************************************************************/
628 void AliHBTReaderESD::SetTPCNClustersRange(Int_t min,Int_t max)
630 //sets range of Number Of Clusters that tracks have to have
634 /********************************************************************/
636 void AliHBTReaderESD::SetTPCChi2PerCluserRange(Float_t min, Float_t max)
638 //sets range of Chi2 per Cluster
639 fTPCChi2PerClustMin = min;
640 fTPCChi2PerClustMax = max;
642 /********************************************************************/
644 void AliHBTReaderESD::SetC00Range(Float_t min, Float_t max)
646 //Sets range of C00 parameter of covariance matrix of the track
647 //it defines uncertainty of the momentum
651 /********************************************************************/
653 void AliHBTReaderESD::SetC11Range(Float_t min, Float_t max)
655 //Sets range of C11 parameter of covariance matrix of the track
656 //it defines uncertainty of the momentum
660 /********************************************************************/
662 void AliHBTReaderESD::SetC22Range(Float_t min, Float_t max)
664 //Sets range of C22 parameter of covariance matrix of the track
665 //it defines uncertainty of the momentum
669 /********************************************************************/
671 void AliHBTReaderESD::SetC33Range(Float_t min, Float_t max)
673 //Sets range of C33 parameter of covariance matrix of the track
674 //it defines uncertainty of the momentum
678 /********************************************************************/
680 void AliHBTReaderESD::SetC44Range(Float_t min, Float_t max)
682 //Sets range of C44 parameter of covariance matrix of the track
683 //it defines uncertainty of the momentum