3 //____________________________________________________________________
4 //////////////////////////////////////////////////////////////////////
6 // class AliHBTReaderESD //
8 // Reader for ALICE Event Summary Data (ESD). //
10 // Piotr.Skowronski@cern.ch //
12 //////////////////////////////////////////////////////////////////////
14 #include <Riostream.h>
18 #include <TObjString.h>
24 #include <AliESDtrack.h>
25 #include <AliKalmanTrack.h>
26 #include <AliJetEventParticles.h>
27 #include "AliJetParticlesReaderESD.h"
29 ClassImp(AliJetParticlesReaderESD)
31 AliJetParticlesReaderESD::AliJetParticlesReaderESD(Bool_t constrained,
32 const Char_t* esdfilename) :
33 AliJetParticlesReader(),
34 fConstrained(constrained),
35 fESDFileName(esdfilename),
40 fPassFlag(AliESDtrack::kTPCrefit)
45 /********************************************************************/
47 AliJetParticlesReaderESD::AliJetParticlesReaderESD(
50 const Char_t* esdfilename) :
51 AliJetParticlesReader(dirs),
52 fConstrained(constrained),
53 fESDFileName(esdfilename),
58 fPassFlag(AliESDtrack::kTPCrefit)
63 /********************************************************************/
65 AliJetParticlesReaderESD::~AliJetParticlesReaderESD()
69 if(fTree) delete fTree;
70 if(fKeyIterator) delete fKeyIterator;
71 if(fFile) delete fFile;
74 /**********************************************************/
76 Int_t AliJetParticlesReaderESD::ReadESD(AliESD* esd)
82 Error("ReadESD","ESD is NULL");
86 //TDatabasePDG* pdgdb = TDatabasePDG::Instance();
89 // Error("ReadESD","Can not get PDG Database Instance.");
93 Float_t mf = esd->GetMagneticField();
96 Error("ReadESD","Magnetic Field is 0. Skipping to next event.");
99 AliKalmanTrack::SetMagneticField(mf/10.);
101 Info("ReadESD","Reading Event %d",fCurrentEvent);
102 if((!fOwner) || (fEventParticles==0))
103 fEventParticles = new AliJetEventParticles();
105 const Int_t kntr = esd->GetNumberOfTracks();
106 Info("ReadESD","Found %d tracks.",kntr);
107 fEventParticles->Reset(kntr);
111 headdesc+=esd->GetRunNumber();
113 headdesc+=esd->GetEventNumber();
114 fEventParticles->SetHeader(headdesc);
116 Double_t vertexpos[3];//vertex position
117 const AliESDVertex* kvertex = esd->GetVertex();
120 Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
127 kvertex->GetXYZ(vertexpos);
129 fEventParticles->SetVertex(vertexpos[0],vertexpos[1],vertexpos[2]);
132 for (Int_t i = 0;i<kntr; i++)
134 const AliESDtrack *kesdtrack = esd->GetTrack(i);
137 Error("ReadESD","Can't get track %d", i);
141 if ((kesdtrack->GetStatus() & fPassFlag)) // != fPassFlag)
143 Info("ReadNext","Particle skipped: %ud.",kesdtrack->GetStatus());
147 Double_t mom[3]; //momentum
148 Double_t xyz[3]; //position
150 if (kesdtrack->GetConstrainedChi2() > 25) continue;
151 kesdtrack->GetConstrainedPxPyPz(mom);
152 kesdtrack->GetConstrainedXYZ(xyz);
154 kesdtrack->GetPxPyPz(mom);
155 kesdtrack->GetXYZ(xyz);
157 const Float_t kmass=kesdtrack->GetMass();
158 const Float_t kp2=mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2];
159 const Float_t ketot=TMath::Sqrt(kmass*kmass+kp2);
160 const Float_t kpt=TMath::Sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
161 const Float_t kp=TMath::Sqrt(kp2);
162 const Float_t keta=0.5*TMath::Log((kp+mom[2]+1e-30)/(kp-mom[2]+1e-30));
163 const Float_t kphi=TMath::Pi()+TMath::ATan2(-mom[1],-mom[0]);
164 //Double_t dx = xyz[0]-vertexpos[0];
165 //Double_t dy = xyz[1]-vertexpos[1];
166 //Float_t dca = TMath::Sqrt(dx*dx + dy*dy);
167 //Float_t dz = xyz[2]-vertexpos[2];
169 const Int_t kncl=kesdtrack->GetITSclusters(index)
170 +kesdtrack->GetTPCclusters(NULL)
171 +kesdtrack->GetTRDclusters(NULL);
172 if(IsAcceptedParticle(kpt,kphi,keta))
173 fEventParticles->AddParticle(mom[0],mom[1],mom[2],ketot,i,kesdtrack->GetLabel(),kncl,kpt,kphi,keta);
175 } // loop over tracks
180 /**********************************************************/
182 void AliJetParticlesReaderESD::Rewind()
186 if(fFile) delete fFile;
187 if(fKeyIterator) delete fKeyIterator;
194 /**********************************************************/
196 Int_t AliJetParticlesReaderESD::ReadNext()
198 //reads next event from fFile
200 do // is OK even if 0 dirs specified,
201 { // in that case we try to read from "./"
204 fFile = OpenFile(fCurrentDir);
207 Error("ReadNext","Can't get fFile for dir no. %d",fCurrentDir);
213 //fFile->GetListOfKeys()->Print();
215 if(fTree) delete fTree;
216 fTree = dynamic_cast<TTree*>(fFile->Get("esdTree"));
218 fTree->SetBranchAddress("ESD",&fESD);
220 fKeyIterator = new TIter(fFile->GetListOfKeys());
225 if(AliKalmanTrack::GetConvConst()<=0.)
226 AliKalmanTrack::SetMagneticField(0.5);
227 if(fCurrentEvent>=fTree->GetEntries())
236 fTree->GetEvent(fCurrentEvent);
239 { // "old" way via ESD objects stored in root file
240 TKey* key = (TKey*)fKeyIterator->Next();
246 delete fFile; //we have to assume there are no more ESD objects in the fFile
250 TString esdname = "ESD";
251 esdname+=fCurrentEvent;
252 if(fESD) delete fESD;
253 fESD = dynamic_cast<AliESD*>(fFile->Get(esdname));
256 Info("ReadNext","Can't find AliESD object named %s",esdname.Data());
260 delete fFile;//we have to assume there is no more ESD objects in the fFile
268 return kTRUE;//success -> read one event
269 } while(fCurrentDir < GetNumberOfDirs());
270 //end of loop over directories specified in fDirs Obj Array
271 return kFALSE; //no more directories to read
274 /**********************************************************/
276 TFile* AliJetParticlesReaderESD::OpenFile(Int_t n)
278 //opens fFile with kine tree
280 const TString& dirname = GetDirName(n);
283 Error("OpenFiles","Can't get directory name");
286 TString filename = dirname +"/"+ fESDFileName;
287 TFile *ret = TFile::Open(filename.Data());
290 Error("OpenFiles","Can't open fFile %s",filename.Data());
295 Error("OpenFiles","Can't open fFile %s",filename.Data());