]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HBTAN/AliHBTReaderTPC.cxx
Typo corrected (HP)
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReaderTPC.cxx
CommitLineData
1b446896 1#include "AliHBTReaderTPC.h"
2
3#include <iostream.h>
7da9bdd2 4//#include <fstream.h>
1b446896 5#include <TTree.h>
6#include <TFile.h>
16701d1b 7#include <TParticle.h>
1b446896 8
16701d1b 9#include <AliRun.h>
10#include <AliMagF.h>
1b446896 11#include <AliTPCtrack.h>
12#include <AliTPCParam.h>
13#include <AliTPCtracker.h>
14
1b446896 15#include "AliHBTRun.h"
16#include "AliHBTEvent.h"
17#include "AliHBTParticle.h"
18#include "AliHBTParticleCut.h"
19
20
21ClassImp(AliHBTReaderTPC)
22//reader for TPC tracking
23//needs galice.root, AliTPCtracks.root, AliTPCclusters.root, good_tracks_tpc
24//
25//more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
26//Piotr.Skowronski@cern.ch
27
28AliHBTReaderTPC::
29 AliHBTReaderTPC(const Char_t* trackfilename,const Char_t* clusterfilename,
16701d1b 30 const Char_t* galicefilename):
1b446896 31 fTrackFileName(trackfilename),fClusterFileName(clusterfilename),
16701d1b 32 fGAliceFileName(galicefilename)
1b446896 33{
16701d1b 34 //constructor,
1b446896 35 //Defaults:
36 // trackfilename = "AliTPCtracks.root"
37 // clusterfilename = "AliTPCclusters.root"
1b446896 38 // galicefilename = "" - this means: Do not open gAlice file -
39 // just leave the global pointer untached
40
41 fParticles = new AliHBTRun();
42 fTracks = new AliHBTRun();
16701d1b 43 fIsRead = kFALSE;
44}
45/********************************************************************/
46AliHBTReaderTPC::
47AliHBTReaderTPC(TObjArray* dirs,
df9a1768 48 const Char_t* trackfilename, const Char_t* clusterfilename,
49 const Char_t* galicefilename):
50 AliHBTReader(dirs), fTrackFileName(trackfilename),
51 fClusterFileName(clusterfilename),fGAliceFileName(galicefilename)
1b446896 52
16701d1b 53{
54 //constructor,
55 //Defaults:
56 // trackfilename = "AliTPCtracks.root"
57 // clusterfilename = "AliTPCclusters.root"
58 // galicefilename = "" - this means: Do not open gAlice file -
59 // just leave the global pointer untached
60
16701d1b 61 fParticles = new AliHBTRun();
62 fTracks = new AliHBTRun();
1b446896 63 fIsRead = kFALSE;
16701d1b 64
1b446896 65}
66/********************************************************************/
67
68AliHBTReaderTPC::~AliHBTReaderTPC()
69 {
70 //desctructor
71 delete fParticles;
72 delete fTracks;
73 }
74/********************************************************************/
75
76AliHBTEvent* AliHBTReaderTPC::GetParticleEvent(Int_t n)
77 {
78 //returns Nth event with simulated particles
16701d1b 79 if (!fIsRead)
80 if(Read(fParticles,fTracks))
81 {
82 Error("GetParticleEvent","Error in reading");
83 return 0x0;
84 }
1b446896 85 return fParticles->GetEvent(n);
86 }
87/********************************************************************/
88AliHBTEvent* AliHBTReaderTPC::GetTrackEvent(Int_t n)
89 {
90 //returns Nth event with reconstructed tracks
16701d1b 91 if (!fIsRead)
92 if(Read(fParticles,fTracks))
93 {
94 Error("GetTrackEvent","Error in reading");
95 return 0x0;
96 }
1b446896 97 return fTracks->GetEvent(n);
98 }
99/********************************************************************/
100
101Int_t AliHBTReaderTPC::GetNumberOfPartEvents()
102 {
103 //returns number of events of particles
16701d1b 104 if (!fIsRead)
105 if ( Read(fParticles,fTracks))
106 {
107 Error("GetNumberOfPartEvents","Error in reading");
108 return 0;
109 }
1b446896 110 return fParticles->GetNumberOfEvents();
111 }
112
113/********************************************************************/
114Int_t AliHBTReaderTPC::GetNumberOfTrackEvents()
115 {
116 //returns number of events of tracks
16701d1b 117 if (!fIsRead)
118 if(Read(fParticles,fTracks))
119 {
120 Error("GetNumberOfTrackEvents","Error in reading");
121 return 0;
122 }
1b446896 123 return fTracks->GetNumberOfEvents();
124 }
125/********************************************************************/
126
127
128Int_t AliHBTReaderTPC::Read(AliHBTRun* particles, AliHBTRun *tracks)
129 {
130 //reads data and puts put to the particles and tracks objects
131 //reurns 0 if everything is OK
132 //
b71a5edb 133 cout<<"AliHBTReaderTPC::Read()"<<endl;
1b446896 134 Int_t i; //iterator and some temprary values
16701d1b 135 Int_t Nevents = 0;
136 Int_t totalNevents = 0;
137 TFile *aTracksFile;//file with tracks
138 TFile *aClustersFile;//file with clusters
139 TFile *aGAliceFile;//!ile name with galice
140
1b446896 141 if (!particles) //check if an object is instatiated
142 {
7da9bdd2 143 Error("Read"," particles object must instatiated before passing it to the reader");
1b446896 144 }
145 if (!tracks) //check if an object is instatiated
146 {
7da9bdd2 147 Error("Read"," tracks object must instatiated before passing it to the reader");
1b446896 148 }
149 particles->Reset();//clear runs == delete all old events
150 tracks->Reset();
16701d1b 151
152 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
153 tarray->SetOwner(); //set the ownership of the objects it contains
154 //when array is is deleted or cleared all objects
155 //that it contains are deleted
156 Int_t currentdir = 0;
b71a5edb 157
158 Int_t Ndirs;
159 if (fDirs) //if array with directories is supplied by user
160 {
161 Ndirs = fDirs->GetEntries(); //get the number if directories
162 }
163 else
164 {
165 Ndirs = 0; //if the array is not supplied read only from current directory
166 }
167
16701d1b 168 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
1b446896 169 {
16701d1b 170
171 if( (i=OpenFiles(aTracksFile,aClustersFile,aGAliceFile,currentdir)) )
172 {
7da9bdd2 173 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
16701d1b 174 return i;
175 }
1b446896 176
177
16701d1b 178 if (gAlice->TreeE())//check if tree E exists
179 {
180 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
181 cout<<"________________________________________________________\n";
182 cout<<"Found "<<Nevents<<" event(s) in directory "<<GetDirName(currentdir)<<endl;
183 cout<<"Setting Magnetic Field. Factor is "<<gAlice->Field()->Factor()<<endl;
184 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());
185 }
186 else
187 {//if not return an error
7da9bdd2 188 Error("Read","Can not find Header tree (TreeE) in gAlice");
16701d1b 189 return 1;
190 }
1b446896 191
16701d1b 192 aClustersFile->cd();//set cluster file active
193 AliTPCParam *TPCParam= (AliTPCParam*)aClustersFile->Get("75x40_100x60");
194 if (!TPCParam)
195 {
7da9bdd2 196 Error("Read","TPC parameters have not been found !\n");
16701d1b 197 return 1;
198 }
1b446896 199
1b446896 200
16701d1b 201 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
202 {
203 cout<<"Reading Event "<<currentEvent<<endl;
204 /**************************************/
205 /**************************************/
206 /**************************************/
1b446896 207
16701d1b 208 aTracksFile->cd();//set track file active
209
1b446896 210 Char_t treename[100];
211 sprintf(treename,"TreeT_TPC_%d",currentEvent);//prepare name of the tree
212
213 TTree *tracktree=0;
214
16701d1b 215 tracktree=(TTree*)aTracksFile->Get(treename);//get the tree
1b446896 216 if (!tracktree) //check if we got the tree
217 {//if not return with error
7da9bdd2 218 Error("Read","Can't get a tree with TPC tracks !\n");
16701d1b 219
1b446896 220 return 1;
221 }
222
223 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
224 if (!trackbranch) ////check if we got the branch
225 {//if not return with error
7da9bdd2 226 Error("Read","Can't get a branch with TPC tracks !\n");
1b446896 227 return 2;
228 }
229 Int_t NTPCtracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
230 cout<<"Found "<<NTPCtracks<<" TPC tracks.\n";
231 //Copy tracks to array
232
233 AliTPCtrack *iotrack=0;
234
16701d1b 235 aClustersFile->cd();//set cluster file active
1b446896 236 AliTPCtracker *tracker = new AliTPCtracker(TPCParam,currentEvent);//create the tacker for this event
237 if (!tracker) //check if it has created succeffuly
238 {//if not return with error
7da9bdd2 239 Error("Read","Can't get a tracker !\n");
1b446896 240 return 3;
241 }
242 tracker->LoadInnerSectors();
243 tracker->LoadOuterSectors();
244
245 for (i=0; i<NTPCtracks; i++) //loop over all tpc tracks
246 {
247 iotrack=new AliTPCtrack; //create new tracks
248 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
249 tracktree->GetEvent(i); //stream track i to the iotrack
250 tracker->CookLabel(iotrack,0.1); //calculate (cook) the label of the tpc track
251 //which is the label of corresponding simulated particle
252 tarray->AddLast(iotrack); //put the track in the array
253 }
254
16701d1b 255 aTracksFile->Delete(treename);//delete tree from memmory (and leave untached on disk)- we do not need it any more
256 aTracksFile->Delete("tracks");//delete branch from memmory
1b446896 257 delete tracker; //delete tracker
258
259 tracker = 0x0;
260 trackbranch = 0x0;
261 tracktree = 0x0;
1b446896 262
263 Double_t xk;
264 Double_t par[5];
265 Float_t phi, lam, pt;//angles and transverse momentum
266 Int_t label; //label of the current track
16701d1b 267
268 aGAliceFile->cd();
269 gAlice->GetEvent(currentEvent);
270
271 gAlice->Particles();
272
273 for (i=0; i<NTPCtracks; i++) //loop over all good tracks
1b446896 274 {
16701d1b 275 iotrack = (AliTPCtrack*)tarray->At(i);
276 label = iotrack->GetLabel();
277
278 if (label < 0) continue;
1b446896 279
16701d1b 280 TParticle *p = (TParticle*)gAlice->Particle(label);
1b446896 281
f1e2da22 282 if(p == 0x0) continue; //if returned pointer is NULL
283 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
284
16701d1b 285 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
286 //if not take next partilce
1b446896 287
16701d1b 288 AliHBTParticle* part = new AliHBTParticle(*p);
1b446896 289 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
290 //if it does not delete it and take next good track
291
16701d1b 292
293 iotrack->PropagateToVertex();
7da9bdd2 294
1b446896 295 iotrack->GetExternalParameters(xk,par); //get properties of the track
296 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
297 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
298 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
299 lam=par[3];
300 pt=1.0/TMath::Abs(par[4]);
301
302 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
303 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
304 Double_t tpz = pt * lam; //track z coordinate of momentum
305
16701d1b 306 Double_t mass = p->GetMass();
1b446896 307 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
308
16701d1b 309 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
7da9bdd2 310 if(Pass(track))//check if meets all criteria of any of our cuts
311 //if it does not delete it and take next good track
312 {
313 delete track;
314 delete part;
315 continue;
316 }
16701d1b 317 particles->AddParticle(totalNevents,part);//put track and particle on the run
318 tracks->AddParticle(totalNevents,track);
1b446896 319
320 }
321 tarray->Clear(); //clear the array
16701d1b 322
323 /**************************************/
1b446896 324 /**************************************/
16701d1b 325 /**************************************/
326 totalNevents++;
327 }
1b446896 328
16701d1b 329 //save environment (resouces) --
330 //clean your place after the work
331 CloseFiles(aTracksFile,aClustersFile,aGAliceFile);
332 currentdir++;
b71a5edb 333 }while(currentdir < Ndirs);
16701d1b 334
335
1b446896 336 delete tarray;
1b446896 337 fIsRead = kTRUE;
338 return 0;
339 }
340
341/********************************************************************/
16701d1b 342Int_t AliHBTReaderTPC::OpenFiles
343(TFile*& aTracksFile, TFile*& aClustersFile, TFile*& agAliceFile,Int_t event)
1b446896 344{
345 //opens all the files
16701d1b 346
347
348 const TString& dirname = GetDirName(event);
349 if (dirname == "")
350 {
351 Error("OpenFiles","Can not get directory name");
352 return 4;
353 }
354
355 TString filename = dirname +"/"+ fTrackFileName;
356 aTracksFile = TFile::Open(filename.Data());
357 if ( aTracksFile == 0x0 )
1b446896 358 {
16701d1b 359 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
1b446896 360 return 1;
361 }
16701d1b 362 if (!aTracksFile->IsOpen())
363 {
364 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
365 return 1;
366 }
367
368 filename = dirname +"/"+ fClusterFileName;
369 aClustersFile = TFile::Open(filename.Data());
370 if ( aClustersFile == 0x0 )
1b446896 371 {
16701d1b 372 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
1b446896 373 return 2;
374 }
16701d1b 375 if (!aClustersFile->IsOpen())
376 {
377 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
378 return 2;
379 }
380
381 filename = dirname +"/"+ fGAliceFileName;
382 agAliceFile = TFile::Open(filename.Data());
383 if ( agAliceFile== 0x0)
384 {
385 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
386 return 3;
387 }
388 if (!agAliceFile->IsOpen())
389 {
390 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
391 return 3;
392 }
393
394 if (!(gAlice=(AliRun*)agAliceFile->Get("gAlice")))
395 {
396 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
397 return 5;
398 }
1b446896 399
16701d1b 400 return 0;
1b446896 401}
16701d1b 402/********************************************************************/
1b446896 403
404/********************************************************************/
405
16701d1b 406void AliHBTReaderTPC::CloseFiles(TFile*& tracksFile, TFile*& clustersFile, TFile*& gAliceFile)
1b446896 407{
408 //closes the files
16701d1b 409 tracksFile->Close();
7da9bdd2 410 delete tracksFile;
16701d1b 411 tracksFile = 0x0;
412 clustersFile->Close();
7da9bdd2 413 delete clustersFile;
16701d1b 414 clustersFile = 0x0;
7da9bdd2 415
416 delete gAlice;
417 gAlice = 0;
418
419 if (gAliceFile)
420 {
421 gAliceFile->Close();
422 delete gAliceFile;
423 gAliceFile = 0x0;
424 }
1b446896 425}
426
427/********************************************************************/
428
429/********************************************************************/
430/********************************************************************/
431/********************************************************************/
432