]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HBTAN/AliHBTReaderITSv1.cxx
MC-dependent part of AliRun extracted in AliMC (F.Carminati)
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReaderITSv1.cxx
CommitLineData
1b446896 1
64e553ff 2#include "AliHBTReaderITSv1.h"
3#include "AliHBTEvent.h"
4#include "AliHBTRun.h"
5#include "AliHBTParticle.h"
6#include "AliHBTParticleCut.h"
1b446896 7
d0c23b58 8#include <Riostream.h>
64e553ff 9
10#include <TROOT.h>
11#include <TFile.h>
12#include <TTree.h>
13#include <TBranch.h>
14#include <TObjArray.h>
15#include <TParticle.h>
16#include <TString.h>
17#include <TObjString.h>
18
19#include <AliRun.h>
20#include <AliMagF.h>
21#include <AliKalmanTrack.h>
22#include <AliITSIOTrack.h>
5d12ce38 23#include "AliMC.h"
1b446896 24
64e553ff 25ClassImp(AliHBTReaderITSv1)
26/********************************************************************/
1b446896 27
64e553ff 28AliHBTReaderITSv1::
29AliHBTReaderITSv1(const Char_t* tracksfilename,const Char_t* galicefilename):
30 fITSTracksFileName(tracksfilename),fGAliceFileName(galicefilename)
1b446896 31 {
32 fParticles = new AliHBTRun();
33 fTracks = new AliHBTRun();
34 fIsRead = kFALSE;
35 }
64e553ff 36/********************************************************************/
37
38AliHBTReaderITSv1::
39AliHBTReaderITSv1(TObjArray* dirs, const Char_t* tracksfilename,const Char_t* galicefilename):
40 AliHBTReader(dirs),
41 fITSTracksFileName(tracksfilename),fGAliceFileName(galicefilename)
42 {
43 fParticles = new AliHBTRun();
44 fTracks = new AliHBTRun();
45 fIsRead = kFALSE;
46 }
47/********************************************************************/
48
49AliHBTReaderITSv1::~AliHBTReaderITSv1()
1b446896 50{
51 delete fParticles;
52 delete fTracks;
53}
64e553ff 54/********************************************************************/
55
1b446896 56AliHBTEvent* AliHBTReaderITSv1::GetParticleEvent(Int_t n)
57 {
58 //returns Nth event with simulated particles
64e553ff 59 if (!fIsRead)
60 if(Read(fParticles,fTracks))
61 {
62 Error("GetParticleEvent","Error in reading");
63 return 0x0;
64 }
65
1b446896 66 return fParticles->GetEvent(n);
67 }
68/********************************************************************/
64e553ff 69
1b446896 70AliHBTEvent* AliHBTReaderITSv1::GetTrackEvent(Int_t n)
71 {
72 //returns Nth event with reconstructed tracks
64e553ff 73 if (!fIsRead)
74 if(Read(fParticles,fTracks))
75 {
76 Error("GetTrackEvent","Error in reading");
77 return 0x0;
78 }
1b446896 79 return fTracks->GetEvent(n);
80 }
81/********************************************************************/
82
83Int_t AliHBTReaderITSv1::GetNumberOfPartEvents()
84 {
85 //returns number of events of particles
64e553ff 86 if (!fIsRead)
87 if(Read(fParticles,fTracks))
88 {
89 Error("GetNumberOfPartEvents","Error in reading");
90 return 0;
91 }
1b446896 92 return fParticles->GetNumberOfEvents();
93 }
94
95/********************************************************************/
96Int_t AliHBTReaderITSv1::GetNumberOfTrackEvents()
97 {
98 //returns number of events of tracks
64e553ff 99 if (!fIsRead)
100 if(Read(fParticles,fTracks))
101 {
102 Error("GetNumberOfTrackEvents","Error in reading");
103 return 0;
104 }
1b446896 105 return fTracks->GetNumberOfEvents();
106 }
107/********************************************************************/
108
109Int_t AliHBTReaderITSv1::Read(AliHBTRun* particles, AliHBTRun *tracks)
64e553ff 110{
429f368c 111 cout<<"AliHBTReaderITSv1::Read()"<<endl;
64e553ff 112 Int_t Nevents = 0;
113 AliITSIOTrack *iotrack=new AliITSIOTrack;
114 Int_t currentdir = 0;
115 Int_t Ndirs;
b0d56759 116 Int_t totalNevents = 0;
117
64e553ff 118 if (fDirs)
119 {
120 Ndirs = fDirs->GetEntries();
121 }
122 else
123 {
124 Ndirs = 0;
125 }
126
127 do //do while is good even if
128 {
129 TFile* gAliceFile = OpenGAliceFile(currentdir);
130 if(gAliceFile == 0x0)
1b446896 131 {
64e553ff 132 Error("Read","Can not open the file with gAlice");
133 delete iotrack;
134 return 1;
1b446896 135 }
64e553ff 136 if (gAlice->TreeE())//check if tree E exists
137 {
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());
143 }
144 else
145 {//if not return an error
146 Error("Read","Can not find Header tree (TreeE) in gAlice");
147 delete iotrack;
148 return 4;
149 }
0f14cc3e 150
151 TFile *file = OpenTrackFile(currentdir);
152 if(file == 0x0)
153 {
154 Error("Read","Can not open the file with ITS tracks V1");
155 delete iotrack;
156 return 2;
157 }
b0d56759 158
159 Int_t naccepted = 0;
64e553ff 160 char tname[30];
b0d56759 161
64e553ff 162 for (Int_t currentEvent = 0; currentEvent < Nevents; currentEvent++)
163 {
b0d56759 164 cout<<"Reading Event "<<currentEvent;
64e553ff 165
166 sprintf(tname,"TreeT%d",currentEvent);
167 file->cd();
168 TTree *tracktree=(TTree*)file->Get(tname);
169 TBranch *tbranch=tracktree->GetBranch("ITStracks");
170 tbranch->SetAddress(&iotrack);
171
172 gAliceFile->cd();
173 gAlice->GetEvent(currentEvent);
5d12ce38 174 gAlice->GetMCApp()->Particles();
1b446896 175
64e553ff 176 Int_t nentr=(Int_t)tracktree->GetEntries();
b0d56759 177
178 cout<<". Found "<<nentr<<" tracks.";
179 fflush(0);
180
64e553ff 181 for (Int_t i=0; i<nentr; i++)
182 {
1b446896 183
64e553ff 184 tracktree->GetEvent(i);
185 if(!iotrack) continue;
186 Int_t label = iotrack->GetLabel();
187 if (label < 0)
188 {
6440fe71 189 continue;
64e553ff 190 }
0f14cc3e 191
5d12ce38 192 TParticle *p = (TParticle*)gAlice->GetMCApp()->Particle(label);
64e553ff 193 if(!p)
194 {
195 Warning("Read","Can not get particle with label &d",label);
196 continue;
197 }
198 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
199 //if not take next partilce
1b446896 200
8089a083 201 AliHBTParticle* part = new AliHBTParticle(*p,i);
64e553ff 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
204
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
210
211 Double_t x= iotrack->GetX();
212 Double_t y= iotrack->GetY();
213 Double_t z= iotrack->GetZ();
214
88cb7938 215 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), i, px, py , pz, tEtot, x, y, z, 0.);
64e553ff 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
1b446896 218
64e553ff 219 particles->AddParticle(totalNevents,part);//put track and particle on the run
220 tracks->AddParticle(totalNevents,track);
b0d56759 221 naccepted++;
64e553ff 222 }//end loop over tracks in the event
1b446896 223
64e553ff 224 totalNevents++;
b0d56759 225 cout<<" Accepted "<<naccepted<<" tracks"<<endl;
64e553ff 226 }//end of loop over events in current directory
227
228 gAliceFile->Close();
229 delete gAliceFile;
230 gAliceFile = 0;
231
232 file->Close();
233 delete file;
234 file = 0;
429f368c 235 currentdir++;
64e553ff 236 }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array
1b446896 237
1b446896 238
64e553ff 239 delete iotrack;
240 fIsRead = kTRUE;
241 return 0;
242
1b446896 243 }
64e553ff 244/********************************************************************/
1b446896 245
64e553ff 246TFile* AliHBTReaderITSv1::OpenTrackFile(Int_t ndir)
247{
248//opens files to be read for given directoru nomber in fDirs Array
249 const TString& dirname = GetDirName(ndir);
250 if (dirname == "")
251 {
252 Error("OpenGAliceFile","Can not get directory name");
253 return 0x0;
254 }
255 TString filename = dirname + "/" + fITSTracksFileName;
f20bcaaa 256
257 TFile *file = TFile::Open(filename.Data());
64e553ff 258 if (!file)
259 {
260 Error("Read","Can not open file %s",filename.Data());
261 return 0x0;
262 }
263 if (!file->IsOpen())
264 {
265 Error("Read","Can not open file %s",filename.Data());
266 return 0x0;
267 }
268
269 return file;
270}
1b446896 271
272
64e553ff 273/********************************************************************/
274TFile* AliHBTReaderITSv1::OpenGAliceFile(Int_t ndir)
275{
276 const TString& dirname = GetDirName(ndir);
277 if (dirname == "")
278 {
279 Error("OpenGAliceFile","Can not get directory name");
280 return 0x0;
281 }
1b446896 282
64e553ff 283 TString filename = dirname + "/" + fGAliceFileName;
284
285 TFile* gAliceFile = TFile::Open(filename.Data());
286 if ( gAliceFile== 0x0)
1b446896 287 {
64e553ff 288 Error("OpenFiles","Can't open file named %s",filename.Data());
289 return 0x0;
1b446896 290 }
64e553ff 291 if (!gAliceFile->IsOpen())
1b446896 292 {
64e553ff 293 Error("OpenFiles","Can't open file named %s",filename.Data());
294 return 0x0;
1b446896 295 }
1b446896 296
64e553ff 297 if (!(gAlice=(AliRun*)gAliceFile->Get("gAlice")))
298 {
299 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
300 gAliceFile->Close();
301 delete gAliceFile;
302 return 0x0;
303 }
304
305 return gAliceFile;
306}
307
308/********************************************************************/
309/********************************************************************/
310
311