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>
24 ClassImp(AliHBTReaderITSv1)
25 /********************************************************************/
28 AliHBTReaderITSv1(const Char_t* tracksfilename,const Char_t* galicefilename):
29 fITSTracksFileName(tracksfilename),fGAliceFileName(galicefilename)
31 fParticles = new AliHBTRun();
32 fTracks = new AliHBTRun();
35 /********************************************************************/
38 AliHBTReaderITSv1(TObjArray* dirs, const Char_t* tracksfilename,const Char_t* galicefilename):
40 fITSTracksFileName(tracksfilename),fGAliceFileName(galicefilename)
42 fParticles = new AliHBTRun();
43 fTracks = new AliHBTRun();
46 /********************************************************************/
48 AliHBTReaderITSv1::~AliHBTReaderITSv1()
53 /********************************************************************/
55 AliHBTEvent* AliHBTReaderITSv1::GetParticleEvent(Int_t n)
57 //returns Nth event with simulated particles
59 if(Read(fParticles,fTracks))
61 Error("GetParticleEvent","Error in reading");
65 return fParticles->GetEvent(n);
67 /********************************************************************/
69 AliHBTEvent* AliHBTReaderITSv1::GetTrackEvent(Int_t n)
71 //returns Nth event with reconstructed tracks
73 if(Read(fParticles,fTracks))
75 Error("GetTrackEvent","Error in reading");
78 return fTracks->GetEvent(n);
80 /********************************************************************/
82 Int_t AliHBTReaderITSv1::GetNumberOfPartEvents()
84 //returns number of events of particles
86 if(Read(fParticles,fTracks))
88 Error("GetNumberOfPartEvents","Error in reading");
91 return fParticles->GetNumberOfEvents();
94 /********************************************************************/
95 Int_t AliHBTReaderITSv1::GetNumberOfTrackEvents()
97 //returns number of events of tracks
99 if(Read(fParticles,fTracks))
101 Error("GetNumberOfTrackEvents","Error in reading");
104 return fTracks->GetNumberOfEvents();
106 /********************************************************************/
108 Int_t AliHBTReaderITSv1::Read(AliHBTRun* particles, AliHBTRun *tracks)
110 cout<<"AliHBTReaderITSv1::Read()"<<endl;
112 AliITSIOTrack *iotrack=new AliITSIOTrack;
113 Int_t currentdir = 0;
118 Ndirs = fDirs->GetEntries();
125 do //do while is good even if
127 TFile* gAliceFile = OpenGAliceFile(currentdir);
128 if(gAliceFile == 0x0)
130 Error("Read","Can not open the file with gAlice");
134 TFile *file = OpenTrackFile(currentdir);
137 Error("Read","Can not open the file with ITS tracks V1");
142 if (gAlice->TreeE())//check if tree E exists
144 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
145 cout<<"________________________________________________________\n";
146 cout<<"Found "<<Nevents<<" event(s) in directory "<<GetDirName(currentdir)<<endl;
147 cout<<"Setting Magnetic Field. Factor is "<<gAlice->Field()->Factor()<<endl;
148 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());
151 {//if not return an error
152 Error("Read","Can not find Header tree (TreeE) in gAlice");
158 Int_t totalNevents = 0;
159 for (Int_t currentEvent = 0; currentEvent < Nevents; currentEvent++)
161 cout<<"Reading Event "<<currentEvent<<endl;
163 sprintf(tname,"TreeT%d",currentEvent);
165 TTree *tracktree=(TTree*)file->Get(tname);
166 TBranch *tbranch=tracktree->GetBranch("ITStracks");
167 tbranch->SetAddress(&iotrack);
170 gAlice->GetEvent(currentEvent);
173 Int_t nentr=(Int_t)tracktree->GetEntries();
175 for (Int_t i=0; i<nentr; i++)
178 tracktree->GetEvent(i);
179 if(!iotrack) continue;
180 Int_t label = iotrack->GetLabel();
186 TParticle *p = (TParticle*)gAlice->Particle(label);
189 Warning("Read","Can not get particle with label &d",label);
192 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
193 //if not take next partilce
195 AliHBTParticle* part = new AliHBTParticle(*p);
196 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
197 //if it does not delete it and take next good track
199 Double_t px=iotrack->GetPx();
200 Double_t py=iotrack->GetPy();
201 Double_t pz=iotrack->GetPz();
202 Double_t mass = p->GetMass();
203 Double_t tEtot = TMath::Sqrt(px*px + py*py + pz*pz + mass*mass);//total energy of the track
205 Double_t x= iotrack->GetX();
206 Double_t y= iotrack->GetY();
207 Double_t z= iotrack->GetZ();
209 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), px, py , pz, tEtot, x, y, z, 0.);
210 if(Pass(track)) { delete track;continue;}//check if meets all criteria of any of our cuts
211 //if it does not delete it and take next good track
213 particles->AddParticle(totalNevents,part);//put track and particle on the run
214 tracks->AddParticle(totalNevents,track);
215 }//end loop over tracks in the event
219 }//end of loop over events in current directory
229 }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array
237 /********************************************************************/
239 TFile* AliHBTReaderITSv1::OpenTrackFile(Int_t ndir)
241 //opens files to be read for given directoru nomber in fDirs Array
242 const TString& dirname = GetDirName(ndir);
245 Error("OpenGAliceFile","Can not get directory name");
248 TString filename = dirname + "/" + fITSTracksFileName;
249 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data());
250 if (!file) file = new TFile(filename.Data());
254 Error("Read","Can not open file %s",filename.Data());
259 Error("Read","Can not open file %s",filename.Data());
267 /********************************************************************/
268 TFile* AliHBTReaderITSv1::OpenGAliceFile(Int_t ndir)
270 const TString& dirname = GetDirName(ndir);
273 Error("OpenGAliceFile","Can not get directory name");
277 TString filename = dirname + "/" + fGAliceFileName;
279 TFile* gAliceFile = TFile::Open(filename.Data());
280 if ( gAliceFile== 0x0)
282 Error("OpenFiles","Can't open file named %s",filename.Data());
285 if (!gAliceFile->IsOpen())
287 Error("OpenFiles","Can't open file named %s",filename.Data());
291 if (!(gAlice=(AliRun*)gAliceFile->Get("gAlice")))
293 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
302 /********************************************************************/
303 /********************************************************************/