1 #include "AliHBTReaderTPC.h"
9 #include <AliTPCtrack.h>
10 #include <AliTPCParam.h>
11 #include <AliTPCtracker.h>
13 #include "AliHBTRun.h"
14 #include "AliHBTEvent.h"
15 #include "AliHBTParticle.h"
16 #include "AliHBTParticleCut.h"
19 ClassImp(AliHBTReaderTPC)
20 //______________________________________________
22 // class AliHBTReaderTPC
24 //reader for TPC tracking
25 //needs galice.root, AliTPCtracks.root, AliTPCclusters.root
27 //more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
28 //Piotr.Skowronski@cern.ch
31 AliHBTReaderTPC:: AliHBTReaderTPC(const Char_t* trackfilename,
32 const Char_t* clusterfilename,
33 const Char_t* galicefilename):
34 fTrackFileName(trackfilename),
35 fClusterFileName(clusterfilename),
36 fGAliceFileName(galicefilename)
40 // trackfilename = "AliTPCtracks.root"
41 // clusterfilename = "AliTPCclusters.root"
42 // galicefilename = "" - this means: Do not open gAlice file -
43 // just leave the global pointer untached
45 fParticles = new AliHBTRun();
46 fTracks = new AliHBTRun();
49 /********************************************************************/
50 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs,
51 const Char_t* trackfilename, const Char_t* clusterfilename,
52 const Char_t* galicefilename):
54 fTrackFileName(trackfilename),
55 fClusterFileName(clusterfilename),
56 fGAliceFileName(galicefilename)
60 // trackfilename = "AliTPCtracks.root"
61 // clusterfilename = "AliTPCclusters.root"
62 // galicefilename = "" - this means: Do not open gAlice file -
63 // just leave the global pointer untached
65 fParticles = new AliHBTRun();
66 fTracks = new AliHBTRun();
69 /********************************************************************/
71 AliHBTReaderTPC::~AliHBTReaderTPC()
77 /********************************************************************/
79 AliHBTEvent* AliHBTReaderTPC::GetParticleEvent(Int_t n)
81 //returns Nth event with simulated particles
83 if(Read(fParticles,fTracks))
85 Error("GetParticleEvent","Error in reading");
88 return fParticles->GetEvent(n);
90 /********************************************************************/
92 AliHBTEvent* AliHBTReaderTPC::GetTrackEvent(Int_t n)
94 //returns Nth event with reconstructed tracks
96 if(Read(fParticles,fTracks))
98 Error("GetTrackEvent","Error in reading");
101 return fTracks->GetEvent(n);
103 /********************************************************************/
105 Int_t AliHBTReaderTPC::GetNumberOfPartEvents()
107 //returns number of events of particles
109 if ( Read(fParticles,fTracks))
111 Error("GetNumberOfPartEvents","Error in reading");
114 return fParticles->GetNumberOfEvents();
117 /********************************************************************/
118 Int_t AliHBTReaderTPC::GetNumberOfTrackEvents()
120 //returns number of events of tracks
122 if(Read(fParticles,fTracks))
124 Error("GetNumberOfTrackEvents","Error in reading");
127 return fTracks->GetNumberOfEvents();
129 /********************************************************************/
132 Int_t AliHBTReaderTPC::Read(AliHBTRun* particles, AliHBTRun *tracks)
134 //reads data and puts put to the particles and tracks objects
135 //reurns 0 if everything is OK
138 Int_t i; //iterator and some temprary values
140 Int_t totalNevents = 0;
141 TFile *aTracksFile;//file with tracks
142 TFile *aClustersFile;//file with clusters
143 TFile *aGAliceFile;//!ile name with galice
145 if (!particles) //check if an object is instatiated
147 Error("Read"," particles object must instatiated before passing it to the reader");
149 if (!tracks) //check if an object is instatiated
151 Error("Read"," tracks object must instatiated before passing it to the reader");
153 particles->Reset();//clear runs == delete all old events
156 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
157 tarray->SetOwner(); //set the ownership of the objects it contains
158 //when array is is deleted or cleared all objects
159 //that it contains are deleted
160 Int_t currentdir = 0;
163 if (fDirs) //if array with directories is supplied by user
165 Ndirs = fDirs->GetEntries(); //get the number if directories
169 Ndirs = 0; //if the array is not supplied read only from current directory
172 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
175 if( (i=OpenFiles(aTracksFile,aClustersFile,aGAliceFile,currentdir)) )
177 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
183 if (gAlice->TreeE())//check if tree E exists
185 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
186 Info("Read","________________________________________________________");
187 Info("Read","Found %d event(s) in directory %s",Nevents,GetDirName(currentdir).Data());
188 Info("Read","Setting Magnetic Field: B=%fT",gAlice->Field()->SolenoidField());
189 AliKalmanTrack::SetConvConst(1000/0.299792458/gAlice->Field()->SolenoidField());
192 {//if not return an error
193 Error("Read","Can not find Header tree (TreeE) in gAlice");
198 aClustersFile->cd();//set cluster file active
199 AliTPCParam *TPCParam= (AliTPCParam*)aClustersFile->Get("75x40_100x60_150x60");
202 TPCParam= (AliTPCParam*)aClustersFile->Get("75x40_100x60");
205 Error("Read","TPC parameters have not been found !\n");
212 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
214 Info("Read","Reading Event %d",currentEvent);
215 /**************************************/
216 /**************************************/
217 /**************************************/
219 aTracksFile->cd();//set track file active
221 Char_t treename[100];
222 sprintf(treename,"TreeT_TPC_%d",currentEvent);//prepare name of the tree
226 tracktree=(TTree*)aTracksFile->Get(treename);//get the tree
227 if (!tracktree) //check if we got the tree
228 {//if not return with error
229 Error("Read","Can't get a tree with TPC tracks !\n");
233 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
234 if (!trackbranch) ////check if we got the branch
235 {//if not return with error
236 Error("Read","Can't get a branch with TPC tracks !\n");
239 Int_t NTPCtracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
240 Info("Read","Found %d TPC tracks.",NTPCtracks);
241 //Copy tracks to array
243 AliTPCtrack *iotrack=0;
245 aClustersFile->cd();//set cluster file active
246 AliTPCtracker *tracker = new AliTPCtracker(TPCParam,currentEvent);//create the tacker for this event
247 if (!tracker) //check if it has created succeffuly
248 {//if not return with error
249 Error("Read","Can't get a tracker !\n");
252 tracker->LoadInnerSectors();
253 tracker->LoadOuterSectors();
255 for (i=0; i<NTPCtracks; i++) //loop over all tpc tracks
257 iotrack=new AliTPCtrack; //create new tracks
258 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
259 tracktree->GetEvent(i); //stream track i to the iotrack
260 tracker->CookLabel(iotrack,0.1); //calculate (cook) the label of the tpc track
261 //which is the label of corresponding simulated particle
262 tarray->AddLast(iotrack); //put the track in the array
265 aTracksFile->Delete(treename);//delete tree from memmory (and leave untached on disk)- we do not need it any more
266 aTracksFile->Delete("tracks");//delete branch from memmory
267 delete tracker; //delete tracker
275 Float_t phi, lam, pt;//angles and transverse momentum
276 Int_t label; //label of the current track
279 gAlice->GetEvent(currentEvent);
283 for (i=0; i<NTPCtracks; i++) //loop over all good tracks
285 iotrack = (AliTPCtrack*)tarray->At(i);
286 label = iotrack->GetLabel();
288 if (label < 0) continue;
290 TParticle *p = (TParticle*)gAlice->Particle(label);
292 if(p == 0x0) continue; //if returned pointer is NULL
293 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
295 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
296 //if not take next partilce
298 AliHBTParticle* part = new AliHBTParticle(*p);
299 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
300 //if it does not delete it and take next good track
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(), 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);
330 tarray->Clear(); //clear the array
332 /**************************************/
333 /**************************************/
334 /**************************************/
338 //save environment (resouces) --
339 //clean your place after the work
340 CloseFiles(aTracksFile,aClustersFile,aGAliceFile);
342 }while(currentdir < Ndirs);
350 /********************************************************************/
351 Int_t AliHBTReaderTPC::OpenFiles
352 (TFile*& aTracksFile, TFile*& aClustersFile, TFile*& agAliceFile,Int_t event)
354 //opens all the files
357 const TString& dirname = GetDirName(event);
360 Error("OpenFiles","Can not get directory name");
364 TString filename = dirname +"/"+ fTrackFileName;
365 aTracksFile = TFile::Open(filename.Data());
366 if ( aTracksFile == 0x0 )
368 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
371 if (!aTracksFile->IsOpen())
373 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
377 filename = dirname +"/"+ fClusterFileName;
378 aClustersFile = TFile::Open(filename.Data());
379 if ( aClustersFile == 0x0 )
381 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
384 if (!aClustersFile->IsOpen())
386 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
390 filename = dirname +"/"+ fGAliceFileName;
391 agAliceFile = TFile::Open(filename.Data());
392 if ( agAliceFile== 0x0)
394 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
397 if (!agAliceFile->IsOpen())
399 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
403 if (!(gAlice=(AliRun*)agAliceFile->Get("gAlice")))
405 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
411 /********************************************************************/
413 /********************************************************************/
415 void AliHBTReaderTPC::CloseFiles(TFile*& tracksFile, TFile*& clustersFile, TFile*& gAliceFile)
421 clustersFile->Close();
436 /********************************************************************/
438 /********************************************************************/
439 /********************************************************************/
440 /********************************************************************/