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"
20 ClassImp(AliHBTReaderESD)
22 AliHBTReaderESD::AliHBTReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
23 fESDFileName(esdfilename),
24 fGAlFileName(galfilename),
27 fReadParticles(kFALSE)
30 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
31 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
33 /********************************************************************/
35 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
37 fESDFileName(esdfilename),
38 fGAlFileName(galfilename),
41 fReadParticles(kFALSE)
44 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
45 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
47 /********************************************************************/
49 AliHBTReaderESD::~AliHBTReaderESD()
55 /**********************************************************/
56 Int_t AliHBTReaderESD::ReadNext()
58 //reads next event from fFile
60 //****** Tentative particle type "concentrations"
61 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
63 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
64 Double_t w[kNSpecies];
65 Double_t mom[3];//momentum
66 Double_t pos[3];//position
68 if (AliHBTParticle::fgDebug)
69 Info("ReadNext","Entered");
71 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
74 Error("Next","Can not get PDG Database Instance.");
78 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
79 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
81 fParticlesEvent->Reset();
82 fTracksEvent->Reset();
84 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
88 fFile = OpenFile(fCurrentDir);//rl is opened here
91 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
100 esdname+=fCurrentEvent;
101 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
104 if (AliHBTParticle::fgDebug > 2 )
106 Info("ReadNext","Can not find ESD object named %s.",esdname.Data());
109 delete fFile;//we have to assume there is no more ESD objects in the fFile
114 AliStack* stack = 0x0;
115 if (fReadParticles && fRunLoader)
117 fRunLoader->GetEvent(fCurrentEvent);
118 stack = fRunLoader->Stack();
120 Info("ReadNext","Reading Event %d",fCurrentEvent);
122 Int_t ntr = esd->GetNumberOfTracks();
123 Info("ReadNext","Found %d tracks.",ntr);
124 for (Int_t i = 0;i<ntr; i++)
126 AliESDtrack *esdtrack = esd->GetTrack(i);
129 Error("Next","Can not get track %d", i);
132 if ((esdtrack->GetStatus()&AliESDtrack::kESDpid) == kFALSE)
134 if (AliHBTParticle::fgDebug > 2)
135 Info("ReadNext","Particle skipped: PID BIT is not set.");
139 esdtrack->GetESDpid(pidtable);
140 esdtrack->GetPxPyPz(mom);
141 esdtrack->GetXYZ(pos);
145 esdtrack->GetExternalParameters(extx,extp);
147 Int_t charge = (extp[4] > 0)?-1:1;//if curvature=-charg/Pt is positive charge is negative
149 //Particle from kinematics
150 AliHBTParticle* particle = 0;
151 Bool_t keeppart = kFALSE;
152 if ( fReadParticles && stack )
154 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
155 TParticle *p = stack->Particle(esdtrack->GetLabel());
158 Error("ReadNext","Can not find track with such label.");
161 // if(p->GetPdgCode()<0) charge = -1;
162 particle = new AliHBTParticle(*p,i);
166 //Here we apply Bayes' formula
168 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
171 if (AliHBTParticle::fgDebug > 2)
172 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
176 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
178 if (AliHBTParticle::fgDebug > 4)
180 Info("ReadNext","###########################################################################");
181 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
182 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
183 TString msg("Pid list got from track:");
184 for (Int_t s = 0;s<kNSpecies;s++)
189 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
196 Info("ReadNext","%s",msg.Data());
197 }//if (AliHBTParticle::fgDebug>4)
199 for (Int_t s = 0; s<kNSpecies; s++)
201 if (w[s] == 0.0) continue;
203 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
204 if(Pass(pdgcode)) continue; //check if we are intersted with particles of this type
206 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
207 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
209 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
210 mom[0], mom[1], mom[2], tEtot,
211 pos[0], pos[1], pos[2], 0.);
212 //copy probabilitis of other species (if not zero)
213 for (Int_t k = 0; k<kNSpecies; k++)
215 if (k == s) continue;
216 if (w[k] == 0.0) continue;
217 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
219 if(Pass(track))//check if meets all criteria of any of our cuts
220 //if it does not delete it and take next good track
226 fTracksEvent->AddParticle(track);
227 if (particle) fParticlesEvent->AddParticle(particle);
230 if (AliHBTParticle::fgDebug > 4 )
232 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
235 }//for (Int_t s = 0; s<kNSpecies; s++)
237 if (keeppart == kFALSE) delete particle;//particle was not stored in event
239 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
241 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
242 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
243 fNEventsRead,fCurrentEvent,fCurrentDir);
248 return 0;//success -> read one event
249 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
251 return 1; //no more directories to read
253 /**********************************************************/
254 void AliHBTReaderESD::Rewind()
264 /**********************************************************/
266 TFile* AliHBTReaderESD::OpenFile(Int_t n)
268 //opens fFile with kine tree
270 const TString& dirname = GetDirName(n);
273 Error("OpenFiles","Can not get directory name");
276 TString filename = dirname +"/"+ fESDFileName;
277 TFile *ret = TFile::Open(filename.Data());
281 Error("OpenFiles","Can't open fFile %s",filename.Data());
286 Error("OpenFiles","Can't open fFile %s",filename.Data());
292 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
293 if (fRunLoader == 0x0)
295 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
299 fRunLoader->LoadHeader();
300 if (fRunLoader->LoadKinematics())
302 Error("Next","Error occured while loading kinematics.");
310 /**********************************************************/
312 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
314 //returns pdg code from the PID index
315 //ask jura about charge
334 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);