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)
146 if (AliHBTParticle::fgDebug > 2)
147 Info("ReadNext","Particle skipped: Data at vertex not available.");
151 if ((esdtrack->GetStatus()&AliESDtrack::kESDpid) == kFALSE)
153 if (AliHBTParticle::fgDebug > 2)
154 Info("ReadNext","Particle skipped: PID BIT is not set.");
158 esdtrack->GetESDpid(pidtable);
159 esdtrack->GetVertexPxPyPz(mom[0],mom[1],mom[2]);
160 esdtrack->GetVertexXYZ(pos[0],pos[1],pos[2]);
164 esdtrack->GetExternalParameters(extx,extp);
166 Int_t charge = (extp[4] > 0)?-1:1;//if curvature=-charg/Pt is positive charge is negative
168 //Particle from kinematics
169 AliHBTParticle* particle = 0;
170 Bool_t keeppart = kFALSE;
171 if ( fReadParticles && stack )
173 if (esdtrack->GetLabel() < 0) continue;//this is fake - we are not able to match any track
174 TParticle *p = stack->Particle(esdtrack->GetLabel());
177 Error("ReadNext","Can not find track with such label.");
180 // if(p->GetPdgCode()<0) charge = -1;
181 particle = new AliHBTParticle(*p,i);
185 //Here we apply Bayes' formula
187 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
190 if (AliHBTParticle::fgDebug > 2)
191 Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
195 for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
197 if (AliHBTParticle::fgDebug > 4)
199 Info("ReadNext","###########################################################################");
200 Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
201 Info("ReadNext","Position: %f %f %f",pos[0],pos[1],pos[2]);
202 TString msg("Pid list got from track:");
203 for (Int_t s = 0;s<kNSpecies;s++)
208 msg+=charge*GetSpeciesPdgCode((ESpecies)s);
215 Info("ReadNext","%s",msg.Data());
216 }//if (AliHBTParticle::fgDebug>4)
218 for (Int_t s = 0; s<kNSpecies; s++)
221 if (pp == 0.0) continue;
223 Int_t pdgcode = charge*GetSpeciesPdgCode((ESpecies)s);
224 if(Pass(pdgcode)) continue; //check if we are intersted with particles of this type
226 Double_t mass = pdgdb->GetParticle(pdgcode)->Mass();
227 Double_t tEtot = TMath::Sqrt( mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2] + mass*mass);//total energy of the track
229 AliHBTParticle* track = new AliHBTParticle(pdgcode, w[s],i,
230 mom[0], mom[1], mom[2], tEtot,
231 pos[0], pos[1], pos[2], 0.);
232 //copy probabilitis of other species (if not zero)
233 for (Int_t k = 0; k<kNSpecies; k++)
235 if (k == s) continue;
236 if (w[k] == 0.0) continue;
237 track->SetPIDprobability(charge*GetSpeciesPdgCode( (ESpecies)k ),w[k]);
239 if(Pass(track))//check if meets all criteria of any of our cuts
240 //if it does not delete it and take next good track
246 fTracksEvent->AddParticle(track);
247 if (particle) fParticlesEvent->AddParticle(particle);
250 if (AliHBTParticle::fgDebug > 4 )
252 Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
255 }//for (Int_t s = 0; s<kNSpecies; s++)
257 if (keeppart == kFALSE) delete particle;//particle was not stored in event
259 }//for (Int_t i = 0;i<ntr; i++) -- loop over tracks
261 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
262 fTracksEvent->GetNumberOfParticles(), fParticlesEvent->GetNumberOfParticles(),
263 fNEventsRead,fCurrentEvent,fCurrentDir);
268 return 0;//success -> read one event
269 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
271 return 1; //no more directories to read
273 /**********************************************************/
274 void AliHBTReaderESD::Rewind()
284 /**********************************************************/
286 TFile* AliHBTReaderESD::OpenFile(Int_t n)
288 //opens fFile with kine tree
290 const TString& dirname = GetDirName(n);
293 Error("OpenFiles","Can not get directory name");
296 TString filename = dirname +"/"+ fESDFileName;
297 TFile *ret = TFile::Open(filename.Data());
301 Error("OpenFiles","Can't open fFile %s",filename.Data());
306 Error("OpenFiles","Can't open fFile %s",filename.Data());
312 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
313 if (fRunLoader == 0x0)
315 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
319 fRunLoader->LoadHeader();
320 if (fRunLoader->LoadKinematics())
322 Error("Next","Error occured while loading kinematics.");
330 /**********************************************************/
332 Int_t AliHBTReaderESD::GetSpeciesPdgCode(ESpecies spec)//skowron
334 //returns pdg code from the PID index
335 //ask jura about charge
354 ::Warning("GetSpeciesPdgCode","Specie with number %d is not defined.",(Int_t)spec);