1 #include "AliHBTReaderESD.h"
5 #include <TObjString.h>
10 #include <AliRunLoader.h>
12 #include <AliESDtrack.h>
15 #include "AliHBTRun.h"
16 #include "AliHBTEvent.h"
17 #include "AliHBTParticle.h"
18 #include "AliHBTParticleCut.h"
22 ClassImp(AliHBTReaderESD)
24 AliHBTReaderESD::AliHBTReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
25 fESDFileName(esdfilename),
26 fGAlFileName(galfilename),
29 fReadParticles(kFALSE)
32 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
33 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
35 /********************************************************************/
37 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
39 fESDFileName(esdfilename),
40 fGAlFileName(galfilename),
43 fReadParticles(kFALSE)
46 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
47 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
49 /********************************************************************/
51 AliHBTReaderESD::~AliHBTReaderESD()
57 /**********************************************************/
58 Int_t AliHBTReaderESD::ReadNext()
60 //reads next event from fFile
62 //****** Tentative particle type "concentrations"
63 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
65 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
66 Double_t w[kNSpecies];
67 Double_t mom[3];//momentum
68 Double_t pos[3];//position
70 if (AliHBTParticle::fgDebug)
71 Info("ReadNext","Entered");
73 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
76 Error("Next","Can not get PDG Database Instance.");
80 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
81 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
83 fParticlesEvent->Reset();
84 fTracksEvent->Reset();
86 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
90 fFile = OpenFile(fCurrentDir);//rl is opened here
93 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
102 esdname+=fCurrentEvent;
103 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
106 if (AliHBTParticle::fgDebug > 2 )
108 Info("ReadNext","Can not find ESD object named %s.",esdname.Data());
111 delete fFile;//we have to assume there is no more ESD objects in the fFile
116 AliStack* stack = 0x0;
117 if (fReadParticles && fRunLoader)
119 fRunLoader->GetEvent(fCurrentEvent);
120 stack = fRunLoader->Stack();
122 Info("ReadNext","Reading Event %d",fCurrentEvent);
124 Int_t ntr = esd->GetNumberOfTracks();
125 Info("ReadNext","Found %d tracks.",ntr);
126 for (Int_t i = 0;i<ntr; i++)
128 AliESDtrack *esdtrack = esd->GetTrack(i);
131 Error("Next","Can not get track %d", i);
134 if ((esdtrack->GetStatus()&AliESDtrack::kESDpid) == kFALSE)
136 if (AliHBTParticle::fgDebug > 2)
137 Info("ReadNext","Particle skipped: PID BIT is not set.");
141 esdtrack->GetESDpid(pidtable);
142 esdtrack->GetPxPyPz(mom);
143 esdtrack->GetXYZ(pos);
145 //Particle from kinematics
146 AliHBTParticle* particle = 0;
147 Bool_t keeppart = kFALSE;
148 if ( fReadParticles && stack )
150 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
151 TParticle *p = stack->Particle(esdtrack->GetLabel());
154 Error("ReadNext","Can not find track with such label.");
157 particle = new AliHBTParticle(*p,i);
160 //Here we apply Bayes' formula
162 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
165 if (AliHBTParticle::fgDebug > 2)
166 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
170 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
172 if (AliHBTParticle::fgDebug > 4)
174 Info("ReadNext","###########################################################################");
175 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
176 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
177 TString msg("Pid list got from track:");
178 for (Int_t s = 0;s<kNSpecies;s++)
183 msg+=GetSpeciesPdgCode((ESpecies)s);
190 Info("ReadNext","%s",msg.Data());
191 }//if (AliHBTParticle::fgDebug>4)
193 for (Int_t s = 0; s<kNSpecies; s++)
195 if (w[s] == 0.0) continue;
197 Int_t pdgcode = GetSpeciesPdgCode((ESpecies)s);
198 if(Pass(pdgcode)) continue; //check if we are intersted with particles of this type
200 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
201 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
203 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
204 mom[0], mom[1], mom[2], tEtot,
205 pos[0], pos[1], pos[2], 0.);
206 //copy probabilitis of other species (if not zero)
207 for (Int_t k = 0; k<kNSpecies; k++)
209 if (k == s) continue;
210 if (w[k] == 0.0) continue;
211 track->SetPIDprobability(GetSpeciesPdgCode( (ESpecies)k ),w[k]);
213 if(Pass(track))//check if meets all criteria of any of our cuts
214 //if it does not delete it and take next good track
220 fTracksEvent->AddParticle(track);
221 if (particle) fParticlesEvent->AddParticle(particle);
224 if (AliHBTParticle::fgDebug > 4 )
226 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
229 }//for (Int_t s = 0; s<kNSpecies; s++)
231 if (keeppart == kFALSE) delete particle;//particle was not stored in event
233 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
235 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
236 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
237 fNEventsRead,fCurrentEvent,fCurrentDir);
242 return 0;//success -> read one event
243 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
245 return 1; //no more directories to read
247 /**********************************************************/
248 void AliHBTReaderESD::Rewind()
258 /**********************************************************/
260 TFile* AliHBTReaderESD::OpenFile(Int_t n)
262 //opens fFile with kine tree
264 const TString& dirname = GetDirName(n);
267 Error("OpenFiles","Can not get directory name");
270 TString filename = dirname +"/"+ fESDFileName;
271 TFile *ret = TFile::Open(filename.Data());
275 Error("OpenFiles","Can't open fFile %s",filename.Data());
280 Error("OpenFiles","Can't open fFile %s",filename.Data());
286 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
287 if (fRunLoader == 0x0)
289 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
293 fRunLoader->LoadHeader();
294 if (fRunLoader->LoadKinematics())
296 Error("Next","Error occured while loading kinematics.");
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);