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 "AliClusterMap.h"
36 ClassImp(AliReaderESD)
38 AliReaderESD::AliReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
39 fESDFileName(esdfilename),
40 fGAlFileName(galfilename),
45 fCheckParticlePID(kFALSE),
46 fReadMostProbableOnly(kFALSE),
50 fITSTrackPoints(kFALSE),
51 fITSTrackPointsType(AliTrackPoints::kITS),
53 fReadCentralBarrel(kTRUE),
58 fTPCChi2PerClustMin(0.0),
59 fTPCChi2PerClustMax(10e5),
85 if ( ((Int_t)kNSpecies) != ((Int_t)AliPID::kSPECIES))
86 Fatal("AliReaderESD","ESD defintions probobly changed. Ask Youra.");
88 /********************************************************************/
90 AliReaderESD::AliReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
92 fESDFileName(esdfilename),
93 fGAlFileName(galfilename),
98 fCheckParticlePID(kFALSE),
99 fReadMostProbableOnly(kFALSE),
103 fITSTrackPoints(kFALSE),
104 fITSTrackPointsType(AliTrackPoints::kITS),
106 fReadCentralBarrel(kTRUE),
111 fTPCChi2PerClustMin(0.0),
112 fTPCChi2PerClustMax(10e5),
137 if ( ((Int_t)kNSpecies) != ((Int_t)AliPID::kSPECIES))
138 Fatal("AliReaderESD","ESD defintions probobly changed. Ask Youra.");
140 /********************************************************************/
142 AliReaderESD::~AliReaderESD()
150 /**********************************************************/
151 Int_t AliReaderESD::ReadNext()
153 //reads next event from fFile
154 //fRunLoader is for reading Kine
156 if (AliVAODParticle::GetDebug())
157 Info("ReadNext","Entered");
159 if (fEventSim == 0x0) fEventSim = new AliAOD();
160 if (fEventRec == 0x0) fEventRec = new AliAOD();
165 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
169 fFile = OpenFile(fCurrentDir);//rl is opened here
172 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
178 TString esdname = "ESD";
179 esdname+=fCurrentEvent;
180 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
183 if (AliVAODParticle::GetDebug() > 2 )
185 Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
188 delete fFile;//we have to assume there is no more ESD objects in the fFile
199 return 0;//success -> read one event
200 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
202 return 1; //no more directories to read
205 /**********************************************************/
206 Int_t AliReaderESD::ReadESD(AliESD* esd)
211 Error("ReadESD","ESD is NULL");
215 // seperate each method
216 if (fReadCentralBarrel) ReadESDCentral(esd);
218 if (fReadMuon) ReadESDMuon(esd);
220 if (fReadPHOS) ReadESDPHOS(esd);
225 /**********************************************************/
226 Int_t AliReaderESD::ReadESDCentral(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
238 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
241 Error("ReadESD","Can not get PDG Database Instance.");
245 Float_t mf = esd->GetMagneticField()/10.; //AliESD::GetMagnField returns mf in kG
247 if ( (mf == 0.0) && ((fNTrackPoints > 0) || fITSTrackPoints) )
249 Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
255 Info("ReadESD","Magnetic Field is %f",mf);
256 AliKalmanTrack::SetMagneticField(mf);
259 AliStack* stack = 0x0;
260 if (fReadSim && fRunLoader)
262 fRunLoader->GetEvent(fCurrentEvent);
263 stack = fRunLoader->Stack();
266 const AliESDVertex* vertex = esd->GetVertex();
269 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
276 vertex->GetXYZ(vertexpos);
279 if (AliVAODParticle::GetDebug() > 0)
281 Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
284 Info("ReadESD","Reading Event %d",fCurrentEvent);
286 Int_t ntr = esd->GetNumberOfTracks();
287 Info("ReadESD","Found %d tracks.",ntr);
288 for (Int_t i = 0;i<ntr; i++)
290 AliESDtrack *esdtrack = esd->GetTrack(i);
293 Error("Next","Can not get track %d", i);
297 //if (esdtrack->HasVertexParameters() == kFALSE)
298 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
300 if (AliVAODParticle::GetDebug() > 2)
301 Info("ReadNext","Particle skipped: Data at vertex not available.");
307 if ((esdtrack->GetStatus() & AliESDtrack::kTPCin) == kFALSE)
309 if (AliVAODParticle::GetDebug() > 2)
310 Info("ReadNext","Particle skipped: Was not reconstructed in TPC.");
315 if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE)
317 if (AliVAODParticle::GetDebug() > 2)
318 Info("ReadNext","Particle skipped: PID BIT is not set.");
325 esdtrack->GetConstrainedExternalParameters(extx,extp);
328 if (AliVAODParticle::GetDebug() > 2)
329 Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
332 esdtrack->GetESDpid(pidtable);
333 esdtrack->GetConstrainedPxPyPz(mom);
334 esdtrack->GetConstrainedXYZ(pos);
335 pos[0] -= vertexpos[0];//we are interested only in relative position to Primary vertex at this point
336 pos[1] -= vertexpos[1];
337 pos[2] -= vertexpos[2];
339 Int_t charge = (extp[4] > 0)?1:-1;//if curvature=charg/Pt is positive charge is positive
341 //Particle from kinematics
342 AliAODParticle* particle = 0;
343 Bool_t keeppart = kFALSE;
344 if ( fReadSim && stack )
346 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
347 TParticle *p = stack->Particle(esdtrack->GetLabel());
350 Error("ReadNext","Can not find track with such label.");
354 if (fCheckParticlePID)
356 if(Rejected(p->GetPdgCode()))
358 if ( AliVAODParticle::GetDebug() > 5 )
359 Info("ReadNext","Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode());
360 continue; //check if we are intersted with particles of this type
363 // if(p->GetPdgCode()<0) charge = -1;
364 particle = new AliAODParticle(*p,i);
368 if(CheckTrack(esdtrack)) continue;
370 //Here we apply Bayes' formula
372 for (Int_t s=0; s<AliPID::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
375 if (AliVAODParticle::GetDebug() > 2)
376 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
380 for (Int_t s=0; s<AliPID::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
382 if (AliVAODParticle::GetDebug() > 4)
384 Info("ReadNext","###########################################################################");
385 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
386 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
387 TString msg("Pid list got from track:");
388 for (Int_t s = 0;s<kNSpecies;s++)
393 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
400 Info("ReadNext","%s",msg.Data());
401 }//if (AliVAODParticle::GetDebug()>4)
403 AliTrackPoints* tpts = 0x0;
404 if (fNTrackPoints > 0)
406 tpts = new AliTrackPoints(fNTrackPoints,esdtrack,mf*10.0,fdR);
407 // tpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
410 AliTrackPoints* itstpts = 0x0;
413 itstpts = new AliTrackPoints(fITSTrackPointsType,esdtrack,mf*10.0);
414 // itstpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
417 AliClusterMap* cmap = 0x0;
420 cmap = new AliClusterMap(esdtrack);
423 //If this flag fReadMostProbableOnly is false the
424 //loop over species (see "LOOPPIDS") is over all possible PIDs
425 //in other case the most probablle PID is searched
426 //and the loop is limited to that PID only
428 Int_t firstspecie = 0;
429 Int_t lastspecie = kNSpecies;
431 if (fReadMostProbableOnly)
433 //find the most probable PID
435 Float_t maxprob = w[0];
436 for (Int_t s=1; s<AliPID::kSPECIES; s++)
445 lastspecie = spec + 1;
448 for (Int_t s = firstspecie; s<lastspecie; s++)//LOOPPIDS
450 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
454 if ( AliVAODParticle::GetDebug() > 5 )
455 Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
459 if(Rejected(pdgcode))
461 if ( AliVAODParticle::GetDebug() > 5 )
462 Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
463 continue; //check if we are intersted with particles of this type
466 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
467 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
469 AliAODParticle* track = new AliAODParticle(pdgcode, w[s],i,
470 mom[0], mom[1], mom[2], tEtot,
471 pos[0], pos[1], pos[2], 0.);
472 //copy probabilitis of other species (if not zero)
473 for (Int_t k = 0; k<kNSpecies; k++)
475 if (k == s) continue;
476 if (w[k] == 0.0) continue;
477 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
480 if(Rejected(track))//check if meets all criteria of any of our cuts
481 //if it does not delete it and take next good track
483 if ( AliVAODParticle::GetDebug() > 4 )
484 Info("ReadNext","Track did not pass the cut");
489 //Single Particle cuts on cluster map and track points rather do not have sense
492 track->SetTPCTrackPoints(tpts);
497 track->SetITSTrackPoints(itstpts);
502 track->SetClusterMap(cmap);
505 fEventRec->AddParticle(track);
506 if (particle) fEventSim->AddParticle(particle);
509 if (AliVAODParticle::GetDebug() > 4 )
511 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
513 if (particle) particle->Print();
514 Info("ReadNext","\n----------------------------------------------\n");
516 }//for (Int_t s = 0; s<kNSpecies; s++)
518 if (keeppart == kFALSE)
520 delete particle;//particle was not stored in event
527 if ( fReadSim && stack )
529 if (particle->P() < 0.00001)
531 Info("ReadNext","###################################");
532 Info("ReadNext","###################################");
533 Info("ReadNext","Track Label %d",esdtrack->GetLabel());
534 TParticle *p = stack->Particle(esdtrack->GetLabel());
543 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
545 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
546 fEventRec->GetNumberOfParticles(), fEventSim->GetNumberOfParticles(),
547 fNEventsRead,fCurrentEvent,fCurrentDir);
548 fTrackCounter->Fill(fEventRec->GetNumberOfParticles());
550 /******************************************************/
551 /****** Setting glevet properties *************/
552 /******************************************************/
554 if (fEventRec->GetNumberOfParticles() > 0)
556 fEventRec->SetPrimaryVertex(vertexpos[0],vertexpos[1],vertexpos[2]);
561 /**********************************************************/
562 Int_t AliReaderESD::ReadESDMuon(AliESD* esd)
565 Double_t vertexpos[3];//vertex position, assuming no secondary decay
567 const AliESDVertex* vertex = esd->GetVertex();
570 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
575 vertex->GetXYZ(vertexpos);
578 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
580 if (AliVAODParticle::GetDebug() > 0) {
581 Info("ReadESD","Reading Event %d",fCurrentEvent);
582 Info("ReadESD","Found %d tracks.",nTracks);
585 Float_t Chi2Cut = 100.;
586 Float_t PtCutMin = 1.;
587 Float_t PtCutMax = 10000.;
588 Float_t muonMass = 0.105658389;
590 Double_t thetaX, thetaY, pYZ;
591 Double_t pxRec1, pyRec1, pzRec1, E1;
599 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
601 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
603 thetaX = muonTrack->GetThetaX();
604 thetaY = muonTrack->GetThetaY();
606 pYZ = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
607 pzRec1 = - pYZ / TMath::Sqrt(1.0 + TMath::Tan(thetaY)*TMath::Tan(thetaX));
608 pxRec1 = pzRec1 * TMath::Tan(thetaX);
609 pyRec1 = pzRec1 * TMath::Tan(thetaY);
610 charge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
611 E1 = TMath::Sqrt(muonMass * muonMass + pxRec1 * pxRec1 + pyRec1 * pyRec1 + pzRec1 * pzRec1);
612 fV1.SetPxPyPzE(pxRec1, pyRec1, pzRec1, E1);
614 ntrackhits = muonTrack->GetNHit();
615 fitfmin = muonTrack->GetChi2();
617 // transverse momentum
618 Float_t pt1 = fV1.Pt();
621 Float_t ch1 = fitfmin / (2.0 * ntrackhits - 5);
623 if ((ch1 < Chi2Cut) && (pt1 > PtCutMin) && (pt1 < PtCutMax)) {
624 AliAODParticle* track = new AliAODParticle(pdgcode*charge,1,iTrack,
625 pxRec1, pyRec1,pzRec1, E1,
626 vertexpos[0], vertexpos[1], vertexpos[2], 0.);
627 fEventRec->AddParticle(track);
631 fTrackCounter->Fill(fEventRec->GetNumberOfParticles());
635 /**********************************************************/
637 void AliReaderESD::Rewind()
640 // delete fKeyIterator;
643 // fKeyIterator = 0x0;
648 if (fTrackCounter) fTrackCounter->Reset();
650 /**********************************************************/
652 TFile* AliReaderESD::OpenFile(Int_t n)
654 //opens fFile with tree
656 const TString& dirname = GetDirName(n);
659 Error("OpenFiles","Can not get directory name");
662 TString filename = dirname +"/"+ fESDFileName;
663 TFile *ret = TFile::Open(filename.Data());
667 Error("OpenFiles","Can't open fFile %s",filename.Data());
672 Error("OpenFiles","Can't open fFile %s",filename.Data());
678 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
679 if (fRunLoader == 0x0)
681 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
686 fRunLoader->LoadHeader();
687 if (fRunLoader->LoadKinematics())
689 Error("Next","Error occured while loading kinematics.");
698 /**********************************************************/
700 Int_t AliReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
702 //returns pdg code from the PID index
703 //ask jura about charge
722 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);
727 /********************************************************************/
728 Bool_t AliReaderESD::CheckTrack(AliESDtrack* t) const
730 //Performs check of the track
732 if ( (t->GetConstrainedChi2() < fChi2Min) || (t->GetConstrainedChi2() > fChi2Max) ) return kTRUE;
734 if ( (t->GetTPCclusters(0x0) < fNTPCClustMin) || (t->GetTPCclusters(0x0) > fNTPCClustMax) ) return kTRUE;
736 if (t->GetTPCclusters(0x0) > 0)
738 Float_t chisqpercl = t->GetTPCchi2()/((Double_t)t->GetTPCclusters(0x0));
739 if ( (chisqpercl < fTPCChi2PerClustMin) || (chisqpercl > fTPCChi2PerClustMax) ) return kTRUE;
743 t->GetConstrainedExternalCovariance(cc);
745 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
746 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
747 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
748 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
749 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
752 t->GetInnerExternalCovariance(cc);
754 if ( (cc[0] < fTPCC00Min) || (cc[0] > fTPCC00Max) ) return kTRUE;
755 if ( (cc[2] < fTPCC11Min) || (cc[2] > fTPCC11Max) ) return kTRUE;
756 if ( (cc[5] < fTPCC22Min) || (cc[5] > fTPCC22Max) ) return kTRUE;
757 if ( (cc[9] < fTPCC33Min) || (cc[9] > fTPCC33Max) ) return kTRUE;
758 if ( (cc[14] < fTPCC44Min) || (cc[14] > fTPCC44Max) ) return kTRUE;
763 /********************************************************************/
765 void AliReaderESD::SetChi2Range(Float_t min, Float_t max)
767 //sets range of Chi2 per Cluster
771 /********************************************************************/
773 void AliReaderESD::SetTPCNClustersRange(Int_t min,Int_t max)
775 //sets range of Number Of Clusters that tracks have to have
779 /********************************************************************/
781 void AliReaderESD::SetTPCChi2PerCluserRange(Float_t min, Float_t max)
783 //sets range of Chi2 per Cluster
784 fTPCChi2PerClustMin = min;
785 fTPCChi2PerClustMax = max;
787 /********************************************************************/
789 void AliReaderESD::SetC00Range(Float_t min, Float_t max)
791 //Sets range of C00 parameter of covariance matrix of the track
792 //it defines uncertainty of the momentum
796 /********************************************************************/
798 void AliReaderESD::SetC11Range(Float_t min, Float_t max)
800 //Sets range of C11 parameter of covariance matrix of the track
801 //it defines uncertainty of the momentum
805 /********************************************************************/
807 void AliReaderESD::SetC22Range(Float_t min, Float_t max)
809 //Sets range of C22 parameter of covariance matrix of the track
810 //it defines uncertainty of the momentum
814 /********************************************************************/
816 void AliReaderESD::SetC33Range(Float_t min, Float_t max)
818 //Sets range of C33 parameter of covariance matrix of the track
819 //it defines uncertainty of the momentum
823 /********************************************************************/
825 void AliReaderESD::SetC44Range(Float_t min, Float_t max)
827 //Sets range of C44 parameter of covariance matrix of the track
828 //it defines uncertainty of the momentum