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),
49 fTPCChi2PerClustMin(0.0),
50 fTPCChi2PerClustMax(10e5),
74 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
75 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
77 /********************************************************************/
79 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
81 fESDFileName(esdfilename),
82 fGAlFileName(galfilename),
86 fReadParticles(kFALSE),
92 fTPCChi2PerClustMin(0.0),
93 fTPCChi2PerClustMax(10e5),
116 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
117 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
119 /********************************************************************/
121 AliHBTReaderESD::~AliHBTReaderESD()
128 /**********************************************************/
129 Int_t AliHBTReaderESD::ReadNext()
131 //reads next event from fFile
132 //fRunLoader is for reading Kine
134 if (AliHBTParticle::GetDebug())
135 Info("ReadNext","Entered");
137 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
138 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
140 fParticlesEvent->Reset();
141 fTracksEvent->Reset();
143 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
147 fFile = OpenFile(fCurrentDir);//rl is opened here
150 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
155 fKeyIterator = new TIter(fFile->GetListOfKeys());
157 // fFile->GetListOfKeys()->Print();
159 TKey* key = (TKey*)fKeyIterator->Next();
162 if (AliHBTParticle::GetDebug() > 2 )
164 Info("ReadNext","No more keys.");
169 delete fFile;//we have to assume there is no more ESD objects in the fFile
178 // TObject* esdobj = key->ReadObj();
179 // if (esdobj == 0x0)
181 // if (AliHBTParticle::GetDebug() > 2 )
183 // Info("ReadNext","Key read NULL. Key Name is %s",key->GetName());
189 // AliESD* esd = dynamic_cast<AliESD*>(esdobj);
191 TString esdname = "ESD";
192 esdname+=fCurrentEvent;
193 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
196 // if (AliHBTParticle::GetDebug() > 2 )
198 // Info("ReadNext","This key is not an AliESD object %s",key->GetName());
200 if (AliHBTParticle::GetDebug() > 2 )
202 Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
207 delete fFile;//we have to assume there is no more ESD objects in the fFile
219 return 0;//success -> read one event
220 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
222 return 1; //no more directories to read
224 /**********************************************************/
226 Int_t AliHBTReaderESD::ReadESD(AliESD* esd)
228 //****** Tentative particle type "concentrations"
229 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
231 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
232 Double_t w[kNSpecies];
233 Double_t mom[3];//momentum
234 Double_t pos[3];//position
235 Double_t vertexpos[3];//vertex position
239 Error("ReadESD","ESD is NULL");
243 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
246 Error("ReadESD","Can not get PDG Database Instance.");
250 Float_t mf = esd->GetMagneticField();
252 if ( (mf == 0.0) && (fNTrackPoints > 0) )
254 Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
258 AliStack* stack = 0x0;
259 if (fReadParticles && fRunLoader)
261 fRunLoader->GetEvent(fCurrentEvent);
262 stack = fRunLoader->Stack();
265 const AliESDVertex* vertex = esd->GetVertex();
268 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
275 vertex->GetXYZ(vertexpos);
278 if (AliHBTParticle::GetDebug() > 0)
280 Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
283 Info("ReadESD","Reading Event %d",fCurrentEvent);
285 Int_t ntr = esd->GetNumberOfTracks();
286 Info("ReadESD","Found %d tracks.",ntr);
287 for (Int_t i = 0;i<ntr; i++)
289 AliESDtrack *esdtrack = esd->GetTrack(i);
292 Error("Next","Can not get track %d", i);
296 //if (esdtrack->HasVertexParameters() == kFALSE)
297 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
299 if (AliHBTParticle::GetDebug() > 2)
300 Info("ReadNext","Particle skipped: Data at vertex not available.");
304 if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE)
306 if (AliHBTParticle::GetDebug() > 2)
307 Info("ReadNext","Particle skipped: PID BIT is not set.");
314 esdtrack->GetConstrainedExternalParameters(extx,extp);
317 if (AliHBTParticle::GetDebug() > 2)
318 Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
321 esdtrack->GetESDpid(pidtable);
322 //esdtrack->GetVertexPxPyPz(mom[0],mom[1],mom[2]);
323 esdtrack->GetConstrainedPxPyPz(mom);
324 //esdtrack->GetVertexXYZ(pos[0],pos[1],pos[2]);
325 esdtrack->GetConstrainedXYZ(pos);
326 pos[0] -= vertexpos[0];//we are interested only in relative position to Primary vertex at this point
327 pos[1] -= vertexpos[1];
328 pos[2] -= vertexpos[2];
330 Int_t charge = (extp[4] > 0)?1:-1;//if curvature=charg/Pt is positive charge is positive
332 //Particle from kinematics
333 AliHBTParticle* particle = 0;
334 Bool_t keeppart = kFALSE;
335 if ( fReadParticles && stack )
337 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
338 TParticle *p = stack->Particle(esdtrack->GetLabel());
341 Error("ReadNext","Can not find track with such label.");
344 // if(p->GetPdgCode()<0) charge = -1;
345 particle = new AliHBTParticle(*p,i);
349 //Here we apply Bayes' formula
351 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
354 if (AliHBTParticle::GetDebug() > 2)
355 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
359 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
361 if (AliHBTParticle::GetDebug() > 4)
363 Info("ReadNext","###########################################################################");
364 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
365 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
366 TString msg("Pid list got from track:");
367 for (Int_t s = 0;s<kNSpecies;s++)
372 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
379 Info("ReadNext","%s",msg.Data());
380 }//if (AliHBTParticle::GetDebug()>4)
382 AliHBTTrackPoints* tpts = 0x0;
383 if (fNTrackPoints > 0)
385 tpts = new AliHBTTrackPoints(fNTrackPoints,esdtrack,mf,fdR);
388 AliHBTClusterMap* cmap = 0x0;
391 cmap = new AliHBTClusterMap(esdtrack);
394 for (Int_t s = 0; s<kNSpecies; s++)
396 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
400 if ( AliHBTParticle::GetDebug() > 5 )
401 Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
407 if ( AliHBTParticle::GetDebug() > 5 )
408 Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
409 continue; //check if we are intersted with particles of this type
412 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
413 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
415 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
416 mom[0], mom[1], mom[2], tEtot,
417 pos[0], pos[1], pos[2], 0.);
418 //copy probabilitis of other species (if not zero)
419 for (Int_t k = 0; k<kNSpecies; k++)
421 if (k == s) continue;
422 if (w[k] == 0.0) continue;
423 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
426 if(Pass(track))//check if meets all criteria of any of our cuts
427 //if it does not delete it and take next good track
429 if ( AliHBTParticle::GetDebug() > 4 )
430 Info("ReadNext","Track did not pass the cut");
435 //Single Particle cuts on cluster map and track points rather do not have sense
438 track->SetTrackPoints(tpts);
443 track->SetClusterMap(cmap);
446 fTracksEvent->AddParticle(track);
447 if (particle) fParticlesEvent->AddParticle(particle);
450 if (AliHBTParticle::GetDebug() > 4 )
452 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
454 if (particle) particle->Print();
455 Info("ReadNext","\n----------------------------------------------\n");
457 }//for (Int_t s = 0; s<kNSpecies; s++)
459 if (keeppart == kFALSE)
461 delete particle;//particle was not stored in event
466 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
468 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
469 fTracksEvent->GetNumberOfParticles(), fParticlesEvent->GetNumberOfParticles(),
470 fNEventsRead,fCurrentEvent,fCurrentDir);
471 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
475 /**********************************************************/
477 void AliHBTReaderESD::Rewind()
488 if (fTrackCounter) fTrackCounter->Reset();
490 /**********************************************************/
492 TFile* AliHBTReaderESD::OpenFile(Int_t n)
494 //opens fFile with kine tree
496 const TString& dirname = GetDirName(n);
499 Error("OpenFiles","Can not get directory name");
502 TString filename = dirname +"/"+ fESDFileName;
503 TFile *ret = TFile::Open(filename.Data());
507 Error("OpenFiles","Can't open fFile %s",filename.Data());
512 Error("OpenFiles","Can't open fFile %s",filename.Data());
518 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
519 if (fRunLoader == 0x0)
521 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
526 fRunLoader->LoadHeader();
527 if (fRunLoader->LoadKinematics())
529 Error("Next","Error occured while loading kinematics.");
538 /**********************************************************/
540 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
542 //returns pdg code from the PID index
543 //ask jura about charge
562 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);
567 /********************************************************************/
569 void AliHBTReaderESD::SetTPCNClustersRange(Int_t min,Int_t max)
571 //sets range of Number Of Clusters that tracks have to have
575 /********************************************************************/
577 void AliHBTReaderESD::SetTPCChi2PerCluserRange(Float_t min, Float_t max)
579 //sets range of Chi2 per Cluster
580 fTPCChi2PerClustMin = min;
581 fTPCChi2PerClustMax = max;
583 /********************************************************************/
585 void AliHBTReaderESD::SetC00Range(Float_t min, Float_t max)
587 //Sets range of C00 parameter of covariance matrix of the track
588 //it defines uncertainty of the momentum
592 /********************************************************************/
594 void AliHBTReaderESD::SetC11Range(Float_t min, Float_t max)
596 //Sets range of C11 parameter of covariance matrix of the track
597 //it defines uncertainty of the momentum
601 /********************************************************************/
603 void AliHBTReaderESD::SetC22Range(Float_t min, Float_t max)
605 //Sets range of C22 parameter of covariance matrix of the track
606 //it defines uncertainty of the momentum
610 /********************************************************************/
612 void AliHBTReaderESD::SetC33Range(Float_t min, Float_t max)
614 //Sets range of C33 parameter of covariance matrix of the track
615 //it defines uncertainty of the momentum
619 /********************************************************************/
621 void AliHBTReaderESD::SetC44Range(Float_t min, Float_t max)
623 //Sets range of C44 parameter of covariance matrix of the track
624 //it defines uncertainty of the momentum