2 #include "AliHBTReaderITSv1.h"
3 #include "AliHBTEvent.h"
5 #include "AliHBTParticle.h"
6 #include "AliHBTParticleCut.h"
14 #include <TObjArray.h>
15 #include <TParticle.h>
17 #include <TObjString.h>
21 #include <AliKalmanTrack.h>
22 #include <AliITSIOTrack.h>
25 ClassImp(AliHBTReaderITSv1)
26 /********************************************************************/
29 AliHBTReaderITSv1(const Char_t* tracksfilename,const Char_t* galicefilename):
30 fITSTracksFileName(tracksfilename),fGAliceFileName(galicefilename)
32 fParticles = new AliHBTRun();
33 fTracks = new AliHBTRun();
36 /********************************************************************/
39 AliHBTReaderITSv1(TObjArray* dirs, const Char_t* tracksfilename,const Char_t* galicefilename):
41 fITSTracksFileName(tracksfilename),fGAliceFileName(galicefilename)
43 fParticles = new AliHBTRun();
44 fTracks = new AliHBTRun();
47 /********************************************************************/
49 AliHBTReaderITSv1::~AliHBTReaderITSv1()
54 /********************************************************************/
56 AliHBTEvent* AliHBTReaderITSv1::GetParticleEvent(Int_t n)
58 //returns Nth event with simulated particles
60 if(Read(fParticles,fTracks))
62 Error("GetParticleEvent","Error in reading");
66 return fParticles->GetEvent(n);
68 /********************************************************************/
70 AliHBTEvent* AliHBTReaderITSv1::GetTrackEvent(Int_t n)
72 //returns Nth event with reconstructed tracks
74 if(Read(fParticles,fTracks))
76 Error("GetTrackEvent","Error in reading");
79 return fTracks->GetEvent(n);
81 /********************************************************************/
83 Int_t AliHBTReaderITSv1::GetNumberOfPartEvents()
85 //returns number of events of particles
87 if(Read(fParticles,fTracks))
89 Error("GetNumberOfPartEvents","Error in reading");
92 return fParticles->GetNumberOfEvents();
95 /********************************************************************/
96 Int_t AliHBTReaderITSv1::GetNumberOfTrackEvents()
98 //returns number of events of tracks
100 if(Read(fParticles,fTracks))
102 Error("GetNumberOfTrackEvents","Error in reading");
105 return fTracks->GetNumberOfEvents();
107 /********************************************************************/
109 Int_t AliHBTReaderITSv1::Read(AliHBTRun* particles, AliHBTRun *tracks)
111 cout<<"AliHBTReaderITSv1::Read()"<<endl;
113 AliITSIOTrack *iotrack=new AliITSIOTrack;
114 Int_t currentdir = 0;
116 Int_t totalNevents = 0;
120 Ndirs = fDirs->GetEntries();
127 do //do while is good even if
129 TFile* gAliceFile = OpenGAliceFile(currentdir);
130 if(gAliceFile == 0x0)
132 Error("Read","Can not open the file with gAlice");
136 if (gAlice->TreeE())//check if tree E exists
138 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
139 cout<<"________________________________________________________\n";
140 cout<<"Found "<<Nevents<<" event(s) in directory "<<GetDirName(currentdir)<<endl;
141 cout<<"Setting Magnetic Field. Factor is "<<gAlice->Field()->Factor()<<endl;
142 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());
145 {//if not return an error
146 Error("Read","Can not find Header tree (TreeE) in gAlice");
151 TFile *file = OpenTrackFile(currentdir);
154 Error("Read","Can not open the file with ITS tracks V1");
162 for (Int_t currentEvent = 0; currentEvent < Nevents; currentEvent++)
164 cout<<"Reading Event "<<currentEvent;
166 sprintf(tname,"TreeT%d",currentEvent);
168 TTree *tracktree=(TTree*)file->Get(tname);
169 TBranch *tbranch=tracktree->GetBranch("ITStracks");
170 tbranch->SetAddress(&iotrack);
173 gAlice->GetEvent(currentEvent);
174 gAlice->GetMCApp()->Particles();
176 Int_t nentr=(Int_t)tracktree->GetEntries();
178 cout<<". Found "<<nentr<<" tracks.";
181 for (Int_t i=0; i<nentr; i++)
184 tracktree->GetEvent(i);
185 if(!iotrack) continue;
186 Int_t label = iotrack->GetLabel();
192 TParticle *p = (TParticle*)gAlice->GetMCApp()->Particle(label);
195 Warning("Read","Can not get particle with label &d",label);
198 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
199 //if not take next partilce
201 AliHBTParticle* part = new AliHBTParticle(*p,i);
202 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
203 //if it does not delete it and take next good track
205 Double_t px=iotrack->GetPx();
206 Double_t py=iotrack->GetPy();
207 Double_t pz=iotrack->GetPz();
208 Double_t mass = p->GetMass();
209 Double_t tEtot = TMath::Sqrt(px*px + py*py + pz*pz + mass*mass);//total energy of the track
211 Double_t x= iotrack->GetX();
212 Double_t y= iotrack->GetY();
213 Double_t z= iotrack->GetZ();
215 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), i, px, py , pz, tEtot, x, y, z, 0.);
216 if(Pass(track)) { delete track;continue;}//check if meets all criteria of any of our cuts
217 //if it does not delete it and take next good track
219 particles->AddParticle(totalNevents,part);//put track and particle on the run
220 tracks->AddParticle(totalNevents,track);
222 }//end loop over tracks in the event
225 cout<<" Accepted "<<naccepted<<" tracks"<<endl;
226 }//end of loop over events in current directory
236 }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array
244 /********************************************************************/
246 TFile* AliHBTReaderITSv1::OpenTrackFile(Int_t ndir)
248 //opens files to be read for given directoru nomber in fDirs Array
249 const TString& dirname = GetDirName(ndir);
252 Error("OpenGAliceFile","Can not get directory name");
255 TString filename = dirname + "/" + fITSTracksFileName;
257 TFile *file = TFile::Open(filename.Data());
260 Error("Read","Can not open file %s",filename.Data());
265 Error("Read","Can not open file %s",filename.Data());
273 /********************************************************************/
274 TFile* AliHBTReaderITSv1::OpenGAliceFile(Int_t ndir)
276 const TString& dirname = GetDirName(ndir);
279 Error("OpenGAliceFile","Can not get directory name");
283 TString filename = dirname + "/" + fGAliceFileName;
285 TFile* gAliceFile = TFile::Open(filename.Data());
286 if ( gAliceFile== 0x0)
288 Error("OpenFiles","Can't open file named %s",filename.Data());
291 if (!gAliceFile->IsOpen())
293 Error("OpenFiles","Can't open file named %s",filename.Data());
297 if (!(gAlice=(AliRun*)gAliceFile->Get("gAlice")))
299 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
308 /********************************************************************/
309 /********************************************************************/