2 #include "AliHBTReaderITSv2.h"
7 #include <TObjString.h>
10 #include <TParticle.h>
13 #include <AliRunLoader.h>
14 #include <AliLoader.h>
17 #include <AliITStrackV2.h>
18 #include <AliITStrackerV2.h>
19 #include <AliITSgeom.h>
21 #include "AliHBTRun.h"
22 #include "AliHBTEvent.h"
23 #include "AliHBTParticle.h"
24 #include "AliHBTParticleCut.h"
27 ClassImp(AliHBTReaderITSv2)
29 AliHBTReaderITSv2::AliHBTReaderITSv2():fFileName("galice.root")
33 // galicefilename = "galice.root"
38 /********************************************************************/
40 AliHBTReaderITSv2::AliHBTReaderITSv2(const Char_t* galicefilename):fFileName(galicefilename)
44 // galicefilename = "galice.root"
45 fParticles = new AliHBTRun();
46 fTracks = new AliHBTRun();
49 /********************************************************************/
51 AliHBTReaderITSv2::AliHBTReaderITSv2(TObjArray* dirs, const Char_t* galicefilename):
52 AliHBTReader(dirs), fFileName(galicefilename)
56 // galicefilename = "galice.root"
58 fParticles = new AliHBTRun();
59 fTracks = new AliHBTRun();
62 /********************************************************************/
64 AliHBTReaderITSv2::~AliHBTReaderITSv2()
66 if (fParticles) delete fParticles;
67 if (fTracks) delete fTracks;
69 /********************************************************************/
70 /********************************************************************/
72 AliHBTEvent* AliHBTReaderITSv2::GetParticleEvent(Int_t n)
74 //returns Nth event with simulated particles
77 if (fParticles == 0x0) fParticles = new AliHBTRun();
78 if (fTracks == 0x0) fTracks = new AliHBTRun();
79 if(Read(fParticles,fTracks))
81 Error("GetParticleEvent","Error in reading");
85 return (fParticles)?fParticles->GetEvent(n):0x0;
87 /********************************************************************/
89 AliHBTEvent* AliHBTReaderITSv2::GetTrackEvent(Int_t n)
91 //returns Nth event with reconstructed tracks
94 if (fParticles == 0x0) fParticles = new AliHBTRun();
95 if (fTracks == 0x0) fTracks = new AliHBTRun();
96 if(Read(fParticles,fTracks))
98 Error("GetTrackEvent","Error in reading");
102 return (fTracks)?fTracks->GetEvent(n):0x0;
104 /********************************************************************/
106 Int_t AliHBTReaderITSv2::GetNumberOfPartEvents()
108 //returns number of events of particles
111 if (fParticles == 0x0) fParticles = new AliHBTRun();
112 if (fTracks == 0x0) fTracks = new AliHBTRun();
113 if(Read(fParticles,fTracks))
115 Error("GetNumberOfPartEvents","Error in reading");
119 return (fParticles)?fParticles->GetNumberOfEvents():0;
122 /********************************************************************/
123 Int_t AliHBTReaderITSv2::GetNumberOfTrackEvents()
125 //returns number of events of tracks
128 if (fParticles == 0x0) fParticles = new AliHBTRun();
129 if (fTracks == 0x0) fTracks = new AliHBTRun();
130 if(Read(fParticles,fTracks))
132 Error("GetNumberOfTrackEvents","Error in reading");
136 return (fTracks)?fTracks->GetNumberOfEvents():0;
138 /********************************************************************/
139 /********************************************************************/
142 Int_t AliHBTReaderITSv2::Read(AliHBTRun* particles, AliHBTRun *tracks)
145 Int_t Nevents = 0; //number of events found in given directory
146 Int_t Ndirs; //number of the directories to be read
147 Int_t Ntracks; //number of tracks in current event
148 Int_t currentdir = 0; //number of events in the current directory
149 Int_t totalNevents = 0; //total number of events read from all directories up to now
150 register Int_t i = 0; //iterator
152 // AliITStrackerV2 *tracker; // ITS tracker - used for cooking labels
153 TTree *tracktree; // tree for tracks
156 Double_t par[5]; //Kalman track parameters
157 Float_t phi, lam, pt;//angles and transverse momentum
158 Int_t label; //label of the current track
160 AliITStrackV2 *iotrack = 0x0; //buffer track for reading data from tree
162 if (!particles) //check if an object is instatiated
164 Error("Read"," particles object must instatiated before passing it to the reader");
166 if (!tracks) //check if an object is instatiated
168 Error("Read"," tracks object must instatiated before passing it to the reader");
170 particles->Reset();//clear runs == delete all old events
173 if (fDirs) //if array with directories is supplied by user
175 Ndirs = fDirs->GetEntries(); //get the number if directories
179 Ndirs = 0; //if the array is not supplied read only from current directory
182 // cout<<"Found "<<Ndirs<<" directory entries"<<endl;
184 do //do while is good even if Ndirs==0 (than read from current directory)
186 TString filename = GetDirName(currentdir);
187 if (filename.IsNull())
189 Error("Read","Can not get directory name");
193 filename = filename +"/"+ fFileName;
194 AliRunLoader* rl = AliRunLoader::Open(filename);
197 Error("Read","Exiting due to problems with opening files.");
203 rl->LoadKinematics();
205 gAlice = rl->GetAliRun();
206 AliITS* its = (AliITS*)gAlice->GetModule("ITS");
208 AliLoader* itsl = rl->GetLoader("ITSLoader");
210 if ((its == 0x0) || ( itsl== 0x0))
212 Error("Read","Can not found ITS in this run");
218 Nevents = rl->GetNumberOfEvents();
220 if (Nevents > 0)//check if tree E exists
222 Info("Read","________________________________________________________");
223 Info("Read","Found %d event(s) in directory %s",Nevents,GetDirName(currentdir).Data());
227 mf = gAlice->Field()->SolenoidField();
228 Info("Read","Setting Magnetic Field from run: B=%fT",mf/10.);
232 Info("Read","Setting Own Magnetic Field: B=%fT",fMagneticField);
233 mf = fMagneticField*10.;
235 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
236 if (iotrack == 0x0) iotrack = new AliITStrackV2();
239 {//if not return an error
240 Error("Read","No events in this run");
247 AliITSgeom *geom= its->GetITSgeom();
250 Error("Read","Can't get the ITS geometry!");
259 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
261 cout<<"Reading Event "<<currentEvent<<endl;
262 rl->GetEvent(currentEvent);
263 tracktree=itsl->TreeT();
267 Error("Read","Can't get a tree with ITS tracks");
270 TBranch *tbranch=tracktree->GetBranch("tracks");
271 Ntracks=(Int_t)tracktree->GetEntries();
276 for (i=0; i<Ntracks; i++) //loop over all tpc tracks
278 if(i%100 == 0)cout<<"all: "<<i<<" accepted: "<<accepted<<" tpc faults: "<<tpcfault<<"\r";
280 tbranch->SetAddress(&iotrack);
281 tracktree->GetEvent(i);
283 label=iotrack->GetLabel();
290 TParticle *p = (TParticle*)gAlice->Particle(label);
291 if(p == 0x0) continue; //if returned pointer is NULL
292 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
294 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
295 //if not take next partilce
297 AliHBTParticle* part = new AliHBTParticle(*p,i);
298 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
299 //if it does not delete it and take next good track
301 iotrack->PropagateTo(3.,0.0028,65.19);
302 iotrack->PropagateToVertex();
304 iotrack->GetExternalParameters(xk,par); //get properties of the track
305 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
306 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
307 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
309 pt=1.0/TMath::Abs(par[4]);
311 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
312 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
313 Double_t tpz = pt * lam; //track z coordinate of momentum
315 Double_t mass = p->GetMass();
316 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
318 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
319 if(Pass(track))//check if meets all criteria of any of our cuts
320 //if it does not delete it and take next good track
326 particles->AddParticle(totalNevents,part);//put track and particle on the run
327 tracks->AddParticle(totalNevents,track);
329 }//end of loop over tracks in the event
332 cout<<"all: "<<i<<" accepted: "<<accepted<<" tpc faults: "<<tpcfault<<" its faults: "<<itsfault<<endl;
334 }//end of loop over events in current directory
337 }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array
344 /********************************************************************/
345 /********************************************************************/