1 #include "AliHBTReaderESD.h"
2 //____________________________________________________________________
3 //////////////////////////////////////////////////////////////////////
5 // class AliHBTReaderESD //
7 // reader for ALICE Event Summary Data (ESD). //
9 // Piotr.Skowronski@cern.ch //
11 //////////////////////////////////////////////////////////////////////
15 #include <TObjString.h>
18 #include <TParticle.h>
20 #include <AliRunLoader.h>
22 #include <AliESDtrack.h>
25 #include "AliHBTRun.h"
26 #include "AliHBTEvent.h"
27 #include "AliHBTParticle.h"
28 #include "AliHBTParticleCut.h"
30 ClassImp(AliHBTReaderESD)
32 AliHBTReaderESD::AliHBTReaderESD(const Char_t* esdfilename, const Char_t* galfilename):
33 fESDFileName(esdfilename),
34 fGAlFileName(galfilename),
37 fReadParticles(kFALSE)
40 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
41 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
43 /********************************************************************/
45 AliHBTReaderESD::AliHBTReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char_t* galfilename):
47 fESDFileName(esdfilename),
48 fGAlFileName(galfilename),
51 fReadParticles(kFALSE)
54 if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
55 Fatal("AliHBTReaderESD","ESD defintions probobly changed. Ask Youra.");
57 /********************************************************************/
59 AliHBTReaderESD::~AliHBTReaderESD()
65 /**********************************************************/
66 Int_t AliHBTReaderESD::ReadNext()
68 //reads next event from fFile
70 //****** Tentative particle type "concentrations"
71 static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
73 Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
74 Double_t w[kNSpecies];
75 Double_t mom[3];//momentum
76 Double_t pos[3];//position
78 if (AliHBTParticle::fgDebug)
79 Info("ReadNext","Entered");
81 TDatabasePDG* pdgdb = TDatabasePDG::Instance();
84 Error("Next","Can not get PDG Database Instance.");
88 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
89 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
91 fParticlesEvent->Reset();
92 fTracksEvent->Reset();
94 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
98 fFile = OpenFile(fCurrentDir);//rl is opened here
101 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
110 esdname+=fCurrentEvent;
111 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
114 if (AliHBTParticle::fgDebug > 2 )
116 Info("ReadNext","Can not find ESD object named %s.",esdname.Data());
119 delete fFile;//we have to assume there is no more ESD objects in the fFile
125 AliStack* stack = 0x0;
126 if (fReadParticles && fRunLoader)
128 fRunLoader->GetEvent(fCurrentEvent);
129 stack = fRunLoader->Stack();
131 Info("ReadNext","Reading Event %d",fCurrentEvent);
133 Int_t ntr = esd->GetNumberOfTracks();
134 Info("ReadNext","Found %d tracks.",ntr);
135 for (Int_t i = 0;i<ntr; i++)
137 AliESDtrack *esdtrack = esd->GetTrack(i);
140 Error("Next","Can not get track %d", i);
144 //if (esdtrack->HasVertexParameters() == kFALSE)
145 if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
147 if (AliHBTParticle::fgDebug > 2)
148 Info("ReadNext","Particle skipped: Data at vertex not available.");
152 if ((esdtrack->GetStatus()&AliESDtrack::kESDpid) == kFALSE)
154 if (AliHBTParticle::fgDebug > 2)
155 Info("ReadNext","Particle skipped: PID BIT is not set.");
159 esdtrack->GetESDpid(pidtable);
160 //esdtrack->GetVertexPxPyPz(mom[0],mom[1],mom[2]);
161 esdtrack->GetPxPyPz(mom);
162 //esdtrack->GetVertexXYZ(pos[0],pos[1],pos[2]);
163 esdtrack->GetXYZ(pos);
167 esdtrack->GetExternalParameters(extx,extp);
169 Int_t charge = (extp[4] > 0)?-1:1;//if curvature=-charg/Pt is positive charge is negative
171 //Particle from kinematics
172 AliHBTParticle* particle = 0;
173 Bool_t keeppart = kFALSE;
174 if ( fReadParticles && stack )
176 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
177 TParticle *p = stack->Particle(esdtrack->GetLabel());
180 Error("ReadNext","Can not find track with such label.");
183 // if(p->GetPdgCode()<0) charge = -1;
184 particle = new AliHBTParticle(*p,i);
188 //Here we apply Bayes' formula
190 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
193 if (AliHBTParticle::fgDebug > 2)
194 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
198 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
200 if (AliHBTParticle::fgDebug > 4)
202 Info("ReadNext","###########################################################################");
203 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
204 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
205 TString msg("Pid list got from track:");
206 for (Int_t s = 0;s<kNSpecies;s++)
211 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
218 Info("ReadNext","%s",msg.Data());
219 }//if (AliHBTParticle::fgDebug>4)
221 for (Int_t s = 0; s<kNSpecies; s++)
224 if (pp == 0.0) continue;
226 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
227 if(Pass(pdgcode)) continue; //check if we are intersted with particles of this type
229 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
230 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
232 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
233 mom[0], mom[1], mom[2], tEtot,
234 pos[0], pos[1], pos[2], 0.);
235 //copy probabilitis of other species (if not zero)
236 for (Int_t k = 0; k<kNSpecies; k++)
238 if (k == s) continue;
239 if (w[k] == 0.0) continue;
240 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
242 if(Pass(track))//check if meets all criteria of any of our cuts
243 //if it does not delete it and take next good track
249 fTracksEvent->AddParticle(track);
250 if (particle) fParticlesEvent->AddParticle(particle);
253 if (AliHBTParticle::fgDebug > 4 )
255 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
258 }//for (Int_t s = 0; s<kNSpecies; s++)
260 if (keeppart == kFALSE) delete particle;//particle was not stored in event
262 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
264 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
265 fTracksEvent->GetNumberOfParticles(), fParticlesEvent->GetNumberOfParticles(),
266 fNEventsRead,fCurrentEvent,fCurrentDir);
271 return 0;//success -> read one event
272 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
274 return 1; //no more directories to read
276 /**********************************************************/
277 void AliHBTReaderESD::Rewind()
287 /**********************************************************/
289 TFile* AliHBTReaderESD::OpenFile(Int_t n)
291 //opens fFile with kine tree
293 const TString& dirname = GetDirName(n);
296 Error("OpenFiles","Can not get directory name");
299 TString filename = dirname +"/"+ fESDFileName;
300 TFile *ret = TFile::Open(filename.Data());
304 Error("OpenFiles","Can't open fFile %s",filename.Data());
309 Error("OpenFiles","Can't open fFile %s",filename.Data());
315 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
316 if (fRunLoader == 0x0)
318 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
322 fRunLoader->LoadHeader();
323 if (fRunLoader->LoadKinematics())
325 Error("Next","Error occured while loading kinematics.");
333 /**********************************************************/
335 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
337 //returns pdg code from the PID index
338 //ask jura about charge
357 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);