1 #include "AliHBTReaderESD.h"
2 //____________________________________________________________________
3 //////////////////////////////////////////////////////////////////////
5 // class AliHBTReaderESD //
7 // reader for ALICE Event Summary Data (ESD). //
9 // Piotr.Skowronski@cern.ch //
11 //////////////////////////////////////////////////////////////////////
13 #include <Riostream.h>
17 #include <TObjString.h>
21 #include <TParticle.h>
25 #include <AliRunLoader.h>
27 #include <AliESDtrack.h>
28 #include <AliKalmanTrack.h>
31 #include "AliHBTRun.h"
32 #include "AliHBTEvent.h"
33 #include "AliHBTParticle.h"
34 #include "AliHBTParticleCut.h"
35 #include "AliHBTTrackPoints.h"
36 #include "AliHBTClusterMap.h"
38 ClassImp(AliHBTReaderESD)
40 AliHBTReaderESD::AliHBTReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
41 fESDFileName(esdfilename),
42 fGAlFileName(galfilename),
46 fReadParticles(kFALSE),
47 fCheckParticlePID(kFALSE),
51 fITSTrackPoints(kFALSE),
55 fTPCChi2PerClustMin(0.0),
56 fTPCChi2PerClustMax(10e5),
82 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
83 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
85 /********************************************************************/
87 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
89 fESDFileName(esdfilename),
90 fGAlFileName(galfilename),
94 fReadParticles(kFALSE),
95 fCheckParticlePID(kFALSE),
99 fITSTrackPoints(kFALSE),
103 fTPCChi2PerClustMin(0.0),
104 fTPCChi2PerClustMax(10e5),
129 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
130 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
132 /********************************************************************/
134 AliHBTReaderESD::~AliHBTReaderESD()
141 /**********************************************************/
142 Int_t AliHBTReaderESD::ReadNext()
144 //reads next event from fFile
145 //fRunLoader is for reading Kine
147 if (AliHBTParticle::GetDebug())
148 Info("ReadNext","Entered");
150 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
151 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
153 fParticlesEvent->Reset();
154 fTracksEvent->Reset();
156 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
160 fFile = OpenFile(fCurrentDir);//rl is opened here
163 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
168 fKeyIterator = new TIter(fFile->GetListOfKeys());
170 // fFile->GetListOfKeys()->Print();
172 TKey* key = (TKey*)fKeyIterator->Next();
175 if (AliHBTParticle::GetDebug() > 2 )
177 Info("ReadNext","No more keys.");
182 delete fFile;//we have to assume there is no more ESD objects in the fFile
191 // TObject* esdobj = key->ReadObj();
192 // if (esdobj == 0x0)
194 // if (AliHBTParticle::GetDebug() > 2 )
196 // Info("ReadNext","Key read NULL. Key Name is %s",key->GetName());
202 // AliESD* esd = dynamic_cast<AliESD*>(esdobj);
204 TString esdname = "ESD";
205 esdname+=fCurrentEvent;
206 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
209 // if (AliHBTParticle::GetDebug() > 2 )
211 // Info("ReadNext","This key is not an AliESD object %s",key->GetName());
213 if (AliHBTParticle::GetDebug() > 2 )
215 Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
220 delete fFile;//we have to assume there is no more ESD objects in the fFile
232 return 0;//success -> read one event
233 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
235 return 1; //no more directories to read
237 /**********************************************************/
239 Int_t AliHBTReaderESD::ReadESD(AliESD* esd)
241 //****** Tentative particle type "concentrations"
242 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
244 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
245 Double_t w[kNSpecies];
246 Double_t mom[3];//momentum
247 Double_t pos[3];//position
248 Double_t vertexpos[3];//vertex position
252 Error("ReadESD","ESD is NULL");
256 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
259 Error("ReadESD","Can not get PDG Database Instance.");
263 Float_t mf = esd->GetMagneticField();
265 if ( (mf == 0.0) && ((fNTrackPoints > 0) || fITSTrackPoints) )
267 Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
272 Info("ReadESD","Magnetic Field is %f",mf/10.);
273 AliKalmanTrack::SetMagneticField(mf/10.);
276 AliStack* stack = 0x0;
277 if (fReadParticles && fRunLoader)
279 fRunLoader->GetEvent(fCurrentEvent);
280 stack = fRunLoader->Stack();
283 const AliESDVertex* vertex = esd->GetVertex();
286 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
293 vertex->GetXYZ(vertexpos);
296 if (AliHBTParticle::GetDebug() > 0)
298 Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
301 Info("ReadESD","Reading Event %d",fCurrentEvent);
303 Int_t ntr = esd->GetNumberOfTracks();
304 Info("ReadESD","Found %d tracks.",ntr);
305 for (Int_t i = 0;i<ntr; i++)
307 AliESDtrack *esdtrack = esd->GetTrack(i);
310 Error("Next","Can not get track %d", i);
314 //if (esdtrack->HasVertexParameters() == kFALSE)
315 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
317 if (AliHBTParticle::GetDebug() > 2)
318 Info("ReadNext","Particle skipped: Data at vertex not available.");
324 if ((esdtrack->GetStatus() & AliESDtrack::kTPCin) == kFALSE)
326 if (AliHBTParticle::GetDebug() > 2)
327 Info("ReadNext","Particle skipped: Was not reconstructed in TPC.");
331 if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE)
333 if (AliHBTParticle::GetDebug() > 2)
334 Info("ReadNext","Particle skipped: PID BIT is not set.");
341 esdtrack->GetConstrainedExternalParameters(extx,extp);
344 if (AliHBTParticle::GetDebug() > 2)
345 Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
348 esdtrack->GetESDpid(pidtable);
349 esdtrack->GetConstrainedPxPyPz(mom);
350 esdtrack->GetConstrainedXYZ(pos);
351 pos[0] -= vertexpos[0];//we are interested only in relative position to Primary vertex at this point
352 pos[1] -= vertexpos[1];
353 pos[2] -= vertexpos[2];
355 Int_t charge = (extp[4] > 0)?1:-1;//if curvature=charg/Pt is positive charge is positive
357 //Particle from kinematics
358 AliHBTParticle* particle = 0;
359 Bool_t keeppart = kFALSE;
360 if ( fReadParticles && stack )
362 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
363 TParticle *p = stack->Particle(esdtrack->GetLabel());
366 Error("ReadNext","Can not find track with such label.");
369 if (fCheckParticlePID)
371 if(Pass(p->GetPdgCode()))
373 if ( AliHBTParticle::GetDebug() > 5 )
374 Info("ReadNext","Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode());
375 continue; //check if we are intersted with particles of this type
378 // if(p->GetPdgCode()<0) charge = -1;
379 particle = new AliHBTParticle(*p,i);
383 if(CheckTrack(esdtrack)) continue;
385 //Here we apply Bayes' formula
387 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
390 if (AliHBTParticle::GetDebug() > 2)
391 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
395 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
397 if (AliHBTParticle::GetDebug() > 4)
399 Info("ReadNext","###########################################################################");
400 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
401 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
402 TString msg("Pid list got from track:");
403 for (Int_t s = 0;s<kNSpecies;s++)
408 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
415 Info("ReadNext","%s",msg.Data());
416 }//if (AliHBTParticle::GetDebug()>4)
418 AliHBTTrackPoints* tpts = 0x0;
419 if (fNTrackPoints > 0)
421 tpts = new AliHBTTrackPoints(fNTrackPoints,esdtrack,mf,fdR);
422 tpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
425 AliHBTTrackPoints* itstpts = 0x0;
428 itstpts = new AliHBTTrackPoints(AliHBTTrackPoints::kITS,esdtrack);
429 itstpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
433 AliHBTClusterMap* cmap = 0x0;
436 cmap = new AliHBTClusterMap(esdtrack);
439 for (Int_t s = 0; s<kNSpecies; s++)
441 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
445 if ( AliHBTParticle::GetDebug() > 5 )
446 Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
452 if ( AliHBTParticle::GetDebug() > 5 )
453 Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
454 continue; //check if we are intersted with particles of this type
457 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
458 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
460 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
461 mom[0], mom[1], mom[2], tEtot,
462 pos[0], pos[1], pos[2], 0.);
463 //copy probabilitis of other species (if not zero)
464 for (Int_t k = 0; k<kNSpecies; k++)
466 if (k == s) continue;
467 if (w[k] == 0.0) continue;
468 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
471 if(Pass(track))//check if meets all criteria of any of our cuts
472 //if it does not delete it and take next good track
474 if ( AliHBTParticle::GetDebug() > 4 )
475 Info("ReadNext","Track did not pass the cut");
480 //Single Particle cuts on cluster map and track points rather do not have sense
483 track->SetTrackPoints(tpts);
488 track->SetITSTrackPoints(itstpts);
493 track->SetClusterMap(cmap);
496 fTracksEvent->AddParticle(track);
497 if (particle) fParticlesEvent->AddParticle(particle);
500 if (AliHBTParticle::GetDebug() > 4 )
502 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
504 if (particle) particle->Print();
505 Info("ReadNext","\n----------------------------------------------\n");
507 }//for (Int_t s = 0; s<kNSpecies; s++)
509 if (keeppart == kFALSE)
511 delete particle;//particle was not stored in event
518 if (particle->P() < 0.00001)
520 Info("ReadNext","###################################");
521 Info("ReadNext","###################################");
522 Info("ReadNext","Track Label %d",esdtrack->GetLabel());
523 TParticle *p = stack->Particle(esdtrack->GetLabel());
528 TString command("touch BadInput");
529 ofstream sfile("BadEvent",ios::out);
530 sfile<<fCurrentDir<<endl;
534 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
536 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
537 fTracksEvent->GetNumberOfParticles(), fParticlesEvent->GetNumberOfParticles(),
538 fNEventsRead,fCurrentEvent,fCurrentDir);
539 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
543 /**********************************************************/
545 void AliHBTReaderESD::Rewind()
556 if (fTrackCounter) fTrackCounter->Reset();
558 /**********************************************************/
560 TFile* AliHBTReaderESD::OpenFile(Int_t n)
562 //opens fFile with kine tree
564 const TString& dirname = GetDirName(n);
567 Error("OpenFiles","Can not get directory name");
570 TString filename = dirname +"/"+ fESDFileName;
571 TFile *ret = TFile::Open(filename.Data());
575 Error("OpenFiles","Can't open fFile %s",filename.Data());
580 Error("OpenFiles","Can't open fFile %s",filename.Data());
586 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
587 if (fRunLoader == 0x0)
589 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
594 fRunLoader->LoadHeader();
595 if (fRunLoader->LoadKinematics())
597 Error("Next","Error occured while loading kinematics.");
606 /**********************************************************/
608 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
610 //returns pdg code from the PID index
611 //ask jura about charge
630 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);
635 /********************************************************************/
636 Bool_t AliHBTReaderESD::CheckTrack(AliESDtrack* t) const
638 //Performs check of the track
640 if ( (t->GetConstrainedChi2() < fChi2Min) || (t->GetConstrainedChi2() > fChi2Max) ) return kTRUE;
642 if ( (t->GetTPCclusters(0x0) < fNTPCClustMin) || (t->GetTPCclusters(0x0) > fNTPCClustMax) ) return kTRUE;
644 if (t->GetTPCclusters(0x0) > 0)
646 Float_t chisqpercl = t->GetTPCchi2()/((Double_t)t->GetTPCclusters(0x0));
647 if ( (chisqpercl < fTPCChi2PerClustMin) || (chisqpercl > fTPCChi2PerClustMax) ) return kTRUE;
651 t->GetConstrainedExternalCovariance(cc);
653 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
654 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
655 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
656 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
657 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
660 t->GetInnerExternalCovariance(cc);
662 if ( (cc[0] < fTPCC00Min) || (cc[0] > fTPCC00Max) ) return kTRUE;
663 if ( (cc[2] < fTPCC11Min) || (cc[2] > fTPCC11Max) ) return kTRUE;
664 if ( (cc[5] < fTPCC22Min) || (cc[5] > fTPCC22Max) ) return kTRUE;
665 if ( (cc[9] < fTPCC33Min) || (cc[9] > fTPCC33Max) ) return kTRUE;
666 if ( (cc[14] < fTPCC44Min) || (cc[14] > fTPCC44Max) ) return kTRUE;
671 /********************************************************************/
673 void AliHBTReaderESD::SetChi2Range(Float_t min, Float_t max)
675 //sets range of Chi2 per Cluster
679 /********************************************************************/
681 void AliHBTReaderESD::SetTPCNClustersRange(Int_t min,Int_t max)
683 //sets range of Number Of Clusters that tracks have to have
687 /********************************************************************/
689 void AliHBTReaderESD::SetTPCChi2PerCluserRange(Float_t min, Float_t max)
691 //sets range of Chi2 per Cluster
692 fTPCChi2PerClustMin = min;
693 fTPCChi2PerClustMax = max;
695 /********************************************************************/
697 void AliHBTReaderESD::SetC00Range(Float_t min, Float_t max)
699 //Sets range of C00 parameter of covariance matrix of the track
700 //it defines uncertainty of the momentum
704 /********************************************************************/
706 void AliHBTReaderESD::SetC11Range(Float_t min, Float_t max)
708 //Sets range of C11 parameter of covariance matrix of the track
709 //it defines uncertainty of the momentum
713 /********************************************************************/
715 void AliHBTReaderESD::SetC22Range(Float_t min, Float_t max)
717 //Sets range of C22 parameter of covariance matrix of the track
718 //it defines uncertainty of the momentum
722 /********************************************************************/
724 void AliHBTReaderESD::SetC33Range(Float_t min, Float_t max)
726 //Sets range of C33 parameter of covariance matrix of the track
727 //it defines uncertainty of the momentum
731 /********************************************************************/
733 void AliHBTReaderESD::SetC44Range(Float_t min, Float_t max)
735 //Sets range of C44 parameter of covariance matrix of the track
736 //it defines uncertainty of the momentum