1 #include "AliHBTReaderTPC.h"
9 #include <AliTPCtrack.h>
10 #include <AliTPCParam.h>
12 #include "AliHBTRun.h"
13 #include "AliHBTEvent.h"
14 #include "AliHBTParticle.h"
15 #include "AliHBTParticleCut.h"
18 ClassImp(AliHBTReaderTPC)
19 //______________________________________________
21 // class AliHBTReaderTPC
23 //reader for TPC tracking
24 //needs galice.root, AliTPCtracks.root
26 //more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
27 //Piotr.Skowronski@cern.ch
31 AliHBTReaderTPC:: AliHBTReaderTPC(const Char_t* trackfilename,
32 const Char_t* clusterfilename,
33 const Char_t* galicefilename):
34 fParticles(new AliHBTRun()),
35 fTracks(new AliHBTRun()),
36 fTrackFileName(trackfilename),
37 fClusterFileName(clusterfilename),
38 fGAliceFileName(galicefilename),
41 fUseMagFFromRun(kTRUE)
45 // trackfilename = "AliTPCtracks.root"
46 // clusterfilename = "AliTPCclusters.root"
47 // galicefilename = "" - this means: Do not open gAlice file -
48 // just leave the global pointer untached
49 //this class is not supposed to be written, that is why I let myself and user
50 //for comfort of having default constructor which allocates dynamic memmory
51 //in case it is going to be written, it should be changed
54 /********************************************************************/
55 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs,
56 const Char_t* trackfilename, const Char_t* clusterfilename,
57 const Char_t* galicefilename):
59 fParticles(new AliHBTRun()),
60 fTracks(new AliHBTRun()),
61 fTrackFileName(trackfilename),
62 fClusterFileName(clusterfilename),
63 fGAliceFileName(galicefilename),
66 fUseMagFFromRun(kTRUE)
70 // trackfilename = "AliTPCtracks.root"
71 // clusterfilename = "AliTPCclusters.root"
72 // galicefilename = "" - this means: Do not open gAlice file -
73 // just leave the global pointer untached
75 /********************************************************************/
77 AliHBTReaderTPC::~AliHBTReaderTPC()
83 /********************************************************************/
85 AliHBTEvent* AliHBTReaderTPC::GetParticleEvent(Int_t n)
87 //returns Nth event with simulated particles
89 if(Read(fParticles,fTracks))
91 Error("GetParticleEvent","Error in reading");
94 return fParticles->GetEvent(n);
96 /********************************************************************/
98 AliHBTEvent* AliHBTReaderTPC::GetTrackEvent(Int_t n)
100 //returns Nth event with reconstructed tracks
102 if(Read(fParticles,fTracks))
104 Error("GetTrackEvent","Error in reading");
107 return fTracks->GetEvent(n);
109 /********************************************************************/
111 Int_t AliHBTReaderTPC::GetNumberOfPartEvents()
113 //returns number of events of particles
115 if ( Read(fParticles,fTracks))
117 Error("GetNumberOfPartEvents","Error in reading");
120 return fParticles->GetNumberOfEvents();
123 /********************************************************************/
124 Int_t AliHBTReaderTPC::GetNumberOfTrackEvents()
126 //returns number of events of tracks
128 if(Read(fParticles,fTracks))
130 Error("GetNumberOfTrackEvents","Error in reading");
133 return fTracks->GetNumberOfEvents();
135 /********************************************************************/
138 Int_t AliHBTReaderTPC::Read(AliHBTRun* particles, AliHBTRun *tracks)
140 //reads data and puts put to the particles and tracks objects
141 //reurns 0 if everything is OK
144 Int_t i; //iterator and some temprary values
146 Int_t totalNevents = 0;
147 TFile *aTracksFile;//file with tracks
148 TFile *aClustersFile;//file with clusters
149 TFile *aGAliceFile;//!ile name with galice
151 if (!particles) //check if an object is instatiated
153 Error("Read"," particles object must instatiated before passing it to the reader");
155 if (!tracks) //check if an object is instatiated
157 Error("Read"," tracks object must instatiated before passing it to the reader");
159 particles->Reset();//clear runs == delete all old events
162 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
163 tarray->SetOwner(); //set the ownership of the objects it contains
164 //when array is is deleted or cleared all objects
165 //that it contains are deleted
166 Int_t currentdir = 0;
169 if (fDirs) //if array with directories is supplied by user
171 Ndirs = fDirs->GetEntries(); //get the number if directories
175 Ndirs = 0; //if the array is not supplied read only from current directory
178 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
181 if( (i=OpenFiles(aTracksFile,aClustersFile,aGAliceFile,currentdir)) )
183 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
189 if (gAlice->TreeE())//check if tree E exists
191 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
192 Info("Read","________________________________________________________");
193 Info("Read","Found %d event(s) in directory %s",Nevents,GetDirName(currentdir).Data());
197 mf = gAlice->Field()->SolenoidField();
198 Info("Read","Setting Magnetic Field from run: B=%fT",mf/10.);
202 Info("Read","Setting Own Magnetic Field: B=%fT",fMagneticField);
203 mf = fMagneticField*10.;
205 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
208 {//if not return an error
209 Error("Read","Can not find Header tree (TreeE) in gAlice");
214 aGAliceFile->cd();//set cluster file active
215 AliTPCParam *TPCParam= (AliTPCParam*)aGAliceFile->Get("75x40_100x60_150x60");
218 TPCParam= (AliTPCParam*)aGAliceFile->Get("75x40_100x60");
221 Error("Read","TPC parameters have not been found !\n");
228 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
230 Info("Read","Reading Event %d",currentEvent);
231 /**************************************/
232 /**************************************/
233 /**************************************/
235 aTracksFile->cd();//set track file active
237 Char_t treename[100];
238 sprintf(treename,"TreeT_TPC_%d",currentEvent);//prepare name of the tree
242 tracktree=(TTree*)aTracksFile->Get(treename);//get the tree
243 if (!tracktree) //check if we got the tree
244 {//if not return with error
245 Error("Read","Can't get a tree with TPC tracks !\n");
249 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
250 if (!trackbranch) ////check if we got the branch
251 {//if not return with error
252 Error("Read","Can't get a branch with TPC tracks !\n");
255 Int_t NTPCtracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
256 Info("Read","Found %d TPC tracks.",NTPCtracks);
257 //Copy tracks to array
259 AliTPCtrack *iotrack=0;
261 // aClustersFile->cd();//set cluster file active
263 for (i=0; i<NTPCtracks; i++) //loop over all tpc tracks
265 iotrack=new AliTPCtrack; //create new tracks
266 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
267 tracktree->GetEvent(i); //stream track i to the iotrack
268 tarray->AddLast(iotrack); //put the track in the array
271 aTracksFile->Delete(treename);//delete tree from memmory (and leave untached on disk)- we do not need it any more
272 aTracksFile->Delete("tracks");//delete branch from memmory
279 Float_t phi, lam, pt;//angles and transverse momentum
280 Int_t label; //label of the current track
283 gAlice->GetEvent(currentEvent);
287 for (i=0; i<NTPCtracks; i++) //loop over all good tracks
289 iotrack = (AliTPCtrack*)tarray->At(i);
290 label = iotrack->GetLabel();
292 if (label < 0) continue;
295 TParticle *p = (TParticle*)gAlice->Particle(label);
297 if(p == 0x0) continue; //if returned pointer is NULL
298 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
300 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
301 //if not take next partilce
302 AliHBTParticle* part = new AliHBTParticle(*p,i);
303 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
304 //if it does not delete it and take next good track
306 iotrack->PropagateToVertex();
308 iotrack->GetExternalParameters(xk,par); //get properties of the track
309 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
310 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
311 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
313 pt=1.0/TMath::Abs(par[4]);
315 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
316 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
317 Double_t tpz = pt * lam; //track z coordinate of momentum
319 Double_t mass = p->GetMass();
320 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
322 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
323 if(Pass(track))//check if meets all criteria of any of our cuts
324 //if it does not delete it and take next good track
330 particles->AddParticle(totalNevents,part);//put track and particle on the run
331 tracks->AddParticle(totalNevents,track);
333 tarray->Clear(); //clear the array
335 /**************************************/
336 /**************************************/
337 /**************************************/
340 //save environment (resouces) --
341 //clean your place after the work
342 CloseFiles(aTracksFile,aClustersFile,aGAliceFile);
344 }while(currentdir < Ndirs);
352 /********************************************************************/
353 Int_t AliHBTReaderTPC::OpenFiles
354 (TFile*& aTracksFile, TFile*& aClustersFile, TFile*& agAliceFile,Int_t event)
356 //opens all the files
359 const TString& dirname = GetDirName(event);
362 Error("OpenFiles","Can not get directory name");
366 TString filename = dirname +"/"+ fTrackFileName;
367 aTracksFile = TFile::Open(filename.Data());
368 if ( aTracksFile == 0x0 )
370 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
373 if (!aTracksFile->IsOpen())
375 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
380 filename = dirname +"/"+ fClusterFileName;
381 aClustersFile = TFile::Open(filename.Data());
382 if ( aClustersFile == 0x0 )
384 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
387 if (!aClustersFile->IsOpen())
389 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
393 filename = dirname +"/"+ fGAliceFileName;
394 agAliceFile = TFile::Open(filename.Data());
395 if ( agAliceFile== 0x0)
397 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
400 if (!agAliceFile->IsOpen())
402 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
406 if (!(gAlice=(AliRun*)agAliceFile->Get("gAlice")))
408 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
414 /********************************************************************/
416 /********************************************************************/
418 void AliHBTReaderTPC::CloseFiles(TFile*& tracksFile, TFile*& clustersFile, TFile*& gAliceFile)
425 // clustersFile->Close();
426 // delete clustersFile;
427 // clustersFile = 0x0;
440 /********************************************************************/
442 /********************************************************************/
443 /********************************************************************/
444 /********************************************************************/