1 #include "AliHBTReaderTPC.h"
11 #include <AliTPCtrack.h>
12 #include <AliTPCParam.h>
13 #include <AliTPCtracker.h>
15 #include "AliHBTRun.h"
16 #include "AliHBTEvent.h"
17 #include "AliHBTParticle.h"
18 #include "AliHBTParticleCut.h"
21 ClassImp(AliHBTReaderTPC)
22 //reader for TPC tracking
23 //needs galice.root, AliTPCtracks.root, AliTPCclusters.root, good_tracks_tpc
25 //more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
26 //Piotr.Skowronski@cern.ch
29 AliHBTReaderTPC(const Char_t* trackfilename,const Char_t* clusterfilename,
30 const Char_t* galicefilename):
31 fTrackFileName(trackfilename),fClusterFileName(clusterfilename),
32 fGAliceFileName(galicefilename)
36 // trackfilename = "AliTPCtracks.root"
37 // clusterfilename = "AliTPCclusters.root"
38 // galicefilename = "" - this means: Do not open gAlice file -
39 // just leave the global pointer untached
41 fParticles = new AliHBTRun();
42 fTracks = new AliHBTRun();
45 /********************************************************************/
47 AliHBTReaderTPC(TObjArray* dirs,
48 const Char_t* trackfilename = "AliTPCtracks.root",
49 const Char_t* clusterfilename = "AliTPCclusters.root",
50 const Char_t* galicefilename = "galice.root"):AliHBTReader(dirs),
51 fTrackFileName(trackfilename),
52 fClusterFileName(clusterfilename),fGAliceFileName(galicefilename)
57 // trackfilename = "AliTPCtracks.root"
58 // clusterfilename = "AliTPCclusters.root"
59 // galicefilename = "" - this means: Do not open gAlice file -
60 // just leave the global pointer untached
62 fParticles = new AliHBTRun();
63 fTracks = new AliHBTRun();
67 /********************************************************************/
69 AliHBTReaderTPC::~AliHBTReaderTPC()
75 /********************************************************************/
77 AliHBTEvent* AliHBTReaderTPC::GetParticleEvent(Int_t n)
79 //returns Nth event with simulated particles
81 if(Read(fParticles,fTracks))
83 Error("GetParticleEvent","Error in reading");
86 return fParticles->GetEvent(n);
88 /********************************************************************/
89 AliHBTEvent* AliHBTReaderTPC::GetTrackEvent(Int_t n)
91 //returns Nth event with reconstructed tracks
93 if(Read(fParticles,fTracks))
95 Error("GetTrackEvent","Error in reading");
98 return fTracks->GetEvent(n);
100 /********************************************************************/
102 Int_t AliHBTReaderTPC::GetNumberOfPartEvents()
104 //returns number of events of particles
106 if ( Read(fParticles,fTracks))
108 Error("GetNumberOfPartEvents","Error in reading");
111 return fParticles->GetNumberOfEvents();
114 /********************************************************************/
115 Int_t AliHBTReaderTPC::GetNumberOfTrackEvents()
117 //returns number of events of tracks
119 if(Read(fParticles,fTracks))
121 Error("GetNumberOfTrackEvents","Error in reading");
124 return fTracks->GetNumberOfEvents();
126 /********************************************************************/
129 Int_t AliHBTReaderTPC::Read(AliHBTRun* particles, AliHBTRun *tracks)
131 //reads data and puts put to the particles and tracks objects
132 //reurns 0 if everything is OK
134 Int_t i; //iterator and some temprary values
136 Int_t totalNevents = 0;
137 TFile *aTracksFile;//file with tracks
138 TFile *aClustersFile;//file with clusters
139 TFile *aGAliceFile;//!ile name with galice
141 if (!particles) //check if an object is instatiated
143 Error("Read"," particles object must instatiated before passing it to the reader");
145 if (!tracks) //check if an object is instatiated
147 Error("Read"," tracks object must instatiated before passing it to the reader");
149 particles->Reset();//clear runs == delete all old events
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;
157 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
160 if( (i=OpenFiles(aTracksFile,aClustersFile,aGAliceFile,currentdir)) )
162 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
167 if (gAlice->TreeE())//check if tree E exists
169 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
170 cout<<"________________________________________________________\n";
171 cout<<"Found "<<Nevents<<" event(s) in directory "<<GetDirName(currentdir)<<endl;
172 cout<<"Setting Magnetic Field. Factor is "<<gAlice->Field()->Factor()<<endl;
173 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());
176 {//if not return an error
177 Error("Read","Can not find Header tree (TreeE) in gAlice");
181 aClustersFile->cd();//set cluster file active
182 AliTPCParam *TPCParam= (AliTPCParam*)aClustersFile->Get("75x40_100x60");
185 Error("Read","TPC parameters have not been found !\n");
190 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
192 cout<<"Reading Event "<<currentEvent<<endl;
193 /**************************************/
194 /**************************************/
195 /**************************************/
197 aTracksFile->cd();//set track file active
199 Char_t treename[100];
200 sprintf(treename,"TreeT_TPC_%d",currentEvent);//prepare name of the tree
204 tracktree=(TTree*)aTracksFile->Get(treename);//get the tree
205 if (!tracktree) //check if we got the tree
206 {//if not return with error
207 Error("Read","Can't get a tree with TPC tracks !\n");
212 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
213 if (!trackbranch) ////check if we got the branch
214 {//if not return with error
215 Error("Read","Can't get a branch with TPC tracks !\n");
218 Int_t NTPCtracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
219 cout<<"Found "<<NTPCtracks<<" TPC tracks.\n";
220 //Copy tracks to array
222 AliTPCtrack *iotrack=0;
224 aClustersFile->cd();//set cluster file active
225 AliTPCtracker *tracker = new AliTPCtracker(TPCParam,currentEvent);//create the tacker for this event
226 if (!tracker) //check if it has created succeffuly
227 {//if not return with error
228 Error("Read","Can't get a tracker !\n");
231 tracker->LoadInnerSectors();
232 tracker->LoadOuterSectors();
234 for (i=0; i<NTPCtracks; i++) //loop over all tpc tracks
236 iotrack=new AliTPCtrack; //create new tracks
237 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
238 tracktree->GetEvent(i); //stream track i to the iotrack
239 tracker->CookLabel(iotrack,0.1); //calculate (cook) the label of the tpc track
240 //which is the label of corresponding simulated particle
241 tarray->AddLast(iotrack); //put the track in the array
244 aTracksFile->Delete(treename);//delete tree from memmory (and leave untached on disk)- we do not need it any more
245 aTracksFile->Delete("tracks");//delete branch from memmory
246 delete tracker; //delete tracker
254 Float_t phi, lam, pt;//angles and transverse momentum
255 Int_t label; //label of the current track
258 gAlice->GetEvent(currentEvent);
262 for (i=0; i<NTPCtracks; i++) //loop over all good tracks
264 iotrack = (AliTPCtrack*)tarray->At(i);
265 label = iotrack->GetLabel();
267 if (label < 0) continue;
269 TParticle *p = (TParticle*)gAlice->Particle(label);
271 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
272 //if not take next partilce
274 AliHBTParticle* part = new AliHBTParticle(*p);
275 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
276 //if it does not delete it and take next good track
279 iotrack->PropagateToVertex();
281 iotrack->GetExternalParameters(xk,par); //get properties of the track
282 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
283 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
284 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
286 pt=1.0/TMath::Abs(par[4]);
288 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
289 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
290 Double_t tpz = pt * lam; //track z coordinate of momentum
292 Double_t mass = p->GetMass();
293 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
295 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
296 if(Pass(track))//check if meets all criteria of any of our cuts
297 //if it does not delete it and take next good track
303 particles->AddParticle(totalNevents,part);//put track and particle on the run
304 tracks->AddParticle(totalNevents,track);
307 tarray->Clear(); //clear the array
309 /**************************************/
310 /**************************************/
311 /**************************************/
315 //save environment (resouces) --
316 //clean your place after the work
317 CloseFiles(aTracksFile,aClustersFile,aGAliceFile);
319 }while(currentdir < fDirs->GetEntries());
327 /********************************************************************/
328 Int_t AliHBTReaderTPC::OpenFiles
329 (TFile*& aTracksFile, TFile*& aClustersFile, TFile*& agAliceFile,Int_t event)
331 //opens all the files
334 const TString& dirname = GetDirName(event);
337 Error("OpenFiles","Can not get directory name");
341 TString filename = dirname +"/"+ fTrackFileName;
342 aTracksFile = TFile::Open(filename.Data());
343 if ( aTracksFile == 0x0 )
345 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
348 if (!aTracksFile->IsOpen())
350 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
354 filename = dirname +"/"+ fClusterFileName;
355 aClustersFile = TFile::Open(filename.Data());
356 if ( aClustersFile == 0x0 )
358 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
361 if (!aClustersFile->IsOpen())
363 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
367 filename = dirname +"/"+ fGAliceFileName;
368 agAliceFile = TFile::Open(filename.Data());
369 if ( agAliceFile== 0x0)
371 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
374 if (!agAliceFile->IsOpen())
376 Error("OpenFiles","Can't open file with TPC clusters named %s",filename.Data());
380 if (!(gAlice=(AliRun*)agAliceFile->Get("gAlice")))
382 Error("OpenFiles","gAlice have not been found on %s !\n",filename.Data());
388 /********************************************************************/
390 /********************************************************************/
392 void AliHBTReaderTPC::CloseFiles(TFile*& tracksFile, TFile*& clustersFile, TFile*& gAliceFile)
398 clustersFile->Close();
413 /********************************************************************/
415 /********************************************************************/
416 /********************************************************************/
417 /********************************************************************/