1 #include "AliHBTReaderESD.h"
5 #include <TObjString.h>
10 #include <AliESDtrack.h>
13 #include "AliHBTRun.h"
14 #include "AliHBTEvent.h"
15 #include "AliHBTParticle.h"
16 #include "AliHBTParticleCut.h"
18 ClassImp(AliHBTReaderESD)
20 AliHBTReaderESD::AliHBTReaderESD(const Char_t* esdfilename):
21 fParticles(new AliHBTRun()),
22 fTracks(new AliHBTRun()),
23 fESDFileName(esdfilename),
27 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
28 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
30 /********************************************************************/
32 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename):
34 fParticles(new AliHBTRun()),
35 fTracks(new AliHBTRun()),
36 fESDFileName(esdfilename),
40 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
41 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
43 /********************************************************************/
45 AliHBTReaderESD::~AliHBTReaderESD()
51 /********************************************************************/
53 AliHBTEvent* AliHBTReaderESD::GetParticleEvent(Int_t n)
55 //returns Nth event with simulated particles
57 if(Read(fParticles,fTracks))
59 Error("GetParticleEvent","Error in reading");
62 return fParticles->GetEvent(n);
64 /********************************************************************/
66 AliHBTEvent* AliHBTReaderESD::GetTrackEvent(Int_t n)
68 //returns Nth event with reconstructed tracks
70 if(Read(fParticles,fTracks))
72 Error("GetTrackEvent","Error in reading");
75 return fTracks->GetEvent(n);
77 /********************************************************************/
79 Int_t AliHBTReaderESD::GetNumberOfPartEvents()
81 //returns number of events of particles
83 if ( Read(fParticles,fTracks))
85 Error("GetNumberOfPartEvents","Error in reading");
88 return fParticles->GetNumberOfEvents();
91 /********************************************************************/
92 Int_t AliHBTReaderESD::GetNumberOfTrackEvents()
94 //returns number of events of tracks
96 if(Read(fParticles,fTracks))
98 Error("GetNumberOfTrackEvents","Error in reading");
101 return fTracks->GetNumberOfEvents();
103 /********************************************************************/
106 Int_t AliHBTReaderESD::Read(AliHBTRun* particles, AliHBTRun *tracks)
108 //reads data and puts put to the particles and tracks objects
109 //reurns 0 if everything is OK
112 Int_t totalNevents = 0;
113 Int_t currentdir = 0; //number of current directory name is fDirs array
115 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
116 Double_t w[kNSpecies];
117 Double_t mom[3];//momentum
118 Double_t pos[3];//position
119 //****** Tentative particle type "concentrations"
120 const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
122 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
125 Error("Read","Can not get PDG Database Instance.");
128 if (!particles) //check if an object is instatiated
130 Error("Read"," particles object must instatiated before passing it to the reader");
133 if (!tracks) //check if an object is instatiated
135 Error("Read"," tracks object must instatiated before passing it to the reader");
138 particles->Reset();//clear runs == delete all old events
142 if (fDirs) //if array with directories is supplied by user
144 Ndirs = fDirs->GetEntries(); //get the number if directories
148 Ndirs = 0; //if the array is not supplied read only from current directory
151 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
153 TFile* file = OpenFile(currentdir);
156 Error("Read","Cannot get File for dir no. %d",currentdir);
161 for(Int_t currentEvent = 0; ;currentEvent++)//loop over all events
164 esdname+=currentEvent;
165 AliESD* esd = dynamic_cast<AliESD*>(file->Get(esdname));
168 if (AliHBTParticle::fgDebug > 2 )
170 Info("Read","Can not find ESD object named %s.",esdname.Data());
173 break;//we have to assume there is no more ESD objects in the file
176 Info("Read","Reading Event %d",currentEvent);
178 Int_t ntr = esd->GetNumberOfTracks();
179 Info("Read","Found %d tracks.",ntr);
180 for (Int_t i = 0;i<ntr; i++)
182 AliESDtrack *esdtrack = esd->GetTrack(i);
185 Error("Read","Can not get track %d", i);
188 if ((esdtrack->GetStatus()&AliESDtrack::kESDpid) == kFALSE)
190 if (AliHBTParticle::fgDebug > 2)
191 Info("Read","Particle skipped: PID BIT is not set.");
195 esdtrack->GetESDpid(pidtable);
196 esdtrack->GetPxPyPz(mom);
197 esdtrack->GetXYZ(pos);
200 //Here we apply Bayes' formula
201 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
204 if (AliHBTParticle::fgDebug > 2)
205 Info("Read","Particle rejected since total bayessian PID probab. is zero.");
209 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
211 if (AliHBTParticle::fgDebug > 4)
213 Info("Read","###########################################################################");
214 Info("Read","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
215 Info("Read","Position: %f %f %f",pos[0],pos[1],pos[2]);
216 Info("Read","Radius: %f ,rc: %f",TMath::Hypot(pos[0],pos[1]),rc);
217 TString msg("Pid list got from track:");
218 for (Int_t s = 0;s<kNSpecies;s++)
223 msg+=GetSpeciesPdgCode((ESpecies)s);
230 Info("Read","%s",msg.Data());
231 }//if (AliHBTParticle::fgDebug>4)
233 for (Int_t s = 0; s<kNSpecies; s++)
235 if (w[s] == 0.0) continue;
237 Int_t pdgcode = GetSpeciesPdgCode((ESpecies)s);
238 if(Pass(pdgcode)) continue; //check if we are intersted with particles of this type
240 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
241 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
243 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
244 mom[0], mom[1], mom[2], tEtot,
245 pos[0], pos[1], pos[2], 0.);
246 //copy probabilitis of other species (if not zero)
247 for (Int_t k = 0; k<kNSpecies; k++)
249 if (k == s) continue;
250 if (w[k] == 0.0) continue;
251 track->SetPIDprobability(GetSpeciesPdgCode( (ESpecies)k ),w[k]);
253 if(Pass(track))//check if meets all criteria of any of our cuts
254 //if it does not delete it and take next good track
259 tracks->AddParticle(totalNevents,track);
260 if (AliHBTParticle::fgDebug > 4 )
262 Info("Read","\n\nAdding Particle with incarnation %d",pdgcode);
265 }//for (Int_t s = 0; s<kNSpecies; s++)
267 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
269 }//for(Int_t currentEvent = 0; ;currentEvent++) -- for over ESD in single file
271 }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array
276 /**********************************************************/
278 TFile* AliHBTReaderESD::OpenFile(Int_t n)
280 //opens file with kine tree
282 const TString& dirname = GetDirName(n);
285 Error("OpenFiles","Can not get directory name");
288 TString filename = dirname +"/"+ fESDFileName;
289 TFile *ret = TFile::Open(filename.Data());
293 Error("OpenFiles","Can't open file %s",filename.Data());
298 Error("OpenFiles","Can't open file %s",filename.Data());
304 /**********************************************************/
306 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
308 //returns pdg code from the PID index
309 //ask jura about charge
328 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);