1 #include "AliHBTReaderTPC.h"
9 #include <AliTPCtrack.h>
10 #include <AliTPCParam.h>
11 #include <AliTPCtracker.h>
14 #include "AliHBTRun.h"
15 #include "AliHBTEvent.h"
16 #include "AliHBTParticle.h"
17 #include "AliHBTParticleCut.h"
20 ClassImp(AliHBTReaderTPC)
21 //reader for TPC tracking
22 //needs galice.root, AliTPCtracks.root, AliTPCclusters.root, good_tracks_tpc
24 //more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
25 //Piotr.Skowronski@cern.ch
28 AliHBTReaderTPC(const Char_t* trackfilename,const Char_t* clusterfilename,
29 const Char_t* goodtracksfilename,const Char_t* galicefilename):
30 fTrackFileName(trackfilename),fClusterFileName(clusterfilename),
31 fGAliceFileName(galicefilename),
32 fGoodTPCTracksFileName(goodtracksfilename)
34 //constructor, only file names are set
36 // trackfilename = "AliTPCtracks.root"
37 // clusterfilename = "AliTPCclusters.root"
38 // goodtracksfilename = "good_tracks_tpc"
39 // galicefilename = "" - this means: Do not open gAlice file -
40 // just leave the global pointer untached
42 fParticles = new AliHBTRun();
43 fTracks = new AliHBTRun();
45 fTracksFile = 0x0; //files are opened during reading only
50 /********************************************************************/
52 AliHBTReaderTPC::~AliHBTReaderTPC()
58 /********************************************************************/
60 AliHBTEvent* AliHBTReaderTPC::GetParticleEvent(Int_t n)
62 //returns Nth event with simulated particles
63 if (!fIsRead) Read(fParticles,fTracks);
64 return fParticles->GetEvent(n);
66 /********************************************************************/
67 AliHBTEvent* AliHBTReaderTPC::GetTrackEvent(Int_t n)
69 //returns Nth event with reconstructed tracks
70 if (!fIsRead) Read(fParticles,fTracks);
71 return fTracks->GetEvent(n);
73 /********************************************************************/
75 Int_t AliHBTReaderTPC::GetNumberOfPartEvents()
77 //returns number of events of particles
78 if (!fIsRead) Read(fParticles,fTracks);
79 return fParticles->GetNumberOfEvents();
82 /********************************************************************/
83 Int_t AliHBTReaderTPC::GetNumberOfTrackEvents()
85 //returns number of events of tracks
86 if (!fIsRead) Read(fParticles,fTracks);
87 return fTracks->GetNumberOfEvents();
89 /********************************************************************/
92 Int_t AliHBTReaderTPC::Read(AliHBTRun* particles, AliHBTRun *tracks)
94 //reads data and puts put to the particles and tracks objects
95 //reurns 0 if everything is OK
97 Int_t i; //iterator and some temprary values
99 if (!particles) //check if an object is instatiated
101 Error("AliHBTReaderTPC::Read"," particles object must instatiated before passing it to the reader");
103 if (!tracks) //check if an object is instatiated
105 Error("AliHBTReaderTPC::Read"," tracks object must instatiated before passing it to the reader");
107 particles->Reset();//clear runs == delete all old events
110 if( (i=OpenFiles()) )
112 Error("AliHBTReaderTPC::Read","Exiting due to problems with opening files. Errorcode %d",i);
116 AliGoodTracks *goodTPCTracks = new AliGoodTracks(fGoodTPCTracksFileName);
119 Error("AliHBTReaderTPC::Read","Exiting due to problems with opening files. Errorcode %d",i);
124 if (gAlice->TreeE())//check if tree E exists
126 Nevents = (Int_t)gAlice->TreeE()->GetEntries();//if yes get number of events in gAlice
127 cout<<"Found "<<Nevents<<endl;
130 {//if not return an error
131 Error("AliHBTReaderPPprod::Read","Can not find Header tree (TreeE) in gAlice");
135 fClustersFile->cd();//set cluster file active
136 AliTPCParam *TPCParam= (AliTPCParam*)fClustersFile->Get("75x40_100x60");
139 Error("AliHBTReaderTPC::Read","TPC parameters have not been found !\n");
143 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
144 tarray->SetOwner(); //set the ownership of the objects it contains
145 //when array is is deleted or cleared all objects
146 //that it contains are deleted
148 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
150 cout<<"Reading Event "<<currentEvent<<endl;
151 /**************************************/
152 /**************************************/
153 /**************************************/
154 fTracksFile->cd();//set track file active
156 Char_t treename[100];
157 sprintf(treename,"TreeT_TPC_%d",currentEvent);//prepare name of the tree
161 tracktree=(TTree*)fTracksFile->Get(treename);//get the tree
162 if (!tracktree) //check if we got the tree
163 {//if not return with error
164 Error("AliHBTReaderTPC::Read","Can't get a tree with TPC tracks !\n");
168 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
169 if (!trackbranch) ////check if we got the branch
170 {//if not return with error
171 Error("AliHBTReaderTPC::Read","Can't get a branch with TPC tracks !\n");
174 Int_t NTPCtracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
175 cout<<"Found "<<NTPCtracks<<" TPC tracks.\n";
176 //Copy tracks to array
178 AliTPCtrack *iotrack=0;
180 fClustersFile->cd();//set cluster file active
181 AliTPCtracker *tracker = new AliTPCtracker(TPCParam,currentEvent);//create the tacker for this event
182 if (!tracker) //check if it has created succeffuly
183 {//if not return with error
184 Error("AliHBTReaderTPC::Read","Can't get a tracker !\n");
187 tracker->LoadInnerSectors();
188 tracker->LoadOuterSectors();
190 for (i=0; i<NTPCtracks; i++) //loop over all tpc tracks
192 iotrack=new AliTPCtrack; //create new tracks
193 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
194 tracktree->GetEvent(i); //stream track i to the iotrack
195 tracker->CookLabel(iotrack,0.1); //calculate (cook) the label of the tpc track
196 //which is the label of corresponding simulated particle
197 tarray->AddLast(iotrack); //put the track in the array
200 fTracksFile->Delete(treename);//delete tree from memmory (and leave untached on disk)- we do not need it any more
201 fTracksFile->Delete("tracks");//delete branch from memmory
202 delete tracker; //delete tracker
208 Int_t & ngood = goodTPCTracks->fGoodInEvent[currentEvent]; //number of good tracks in the current event
212 Float_t phi, lam, pt;//angles and transverse momentum
213 Int_t label; //label of the current track
214 Bool_t found; //flag indicated wether we managed to match good_tpc_track with track
216 for (i=0; i<ngood; i++) //loop over all good tracks
218 const struct GoodTrack & gt = goodTPCTracks->GetTrack(currentEvent,i); //get ith goog track
220 if(Pass(gt.code)) continue; //check if we are intersted with particles of this type
221 //if not take next partilce
224 found = kFALSE; //guard in case we don't find track with such a label
225 for (Int_t j=0;j<NTPCtracks;j++)//lopp over all tpc tracks
227 iotrack = (AliTPCtrack*)tarray->At(j);
228 if (iotrack->GetLabel() == label) //if the label is the same
230 found = kTRUE; //we found the track
234 if(!found) //check if we found the track
237 "Sth is going wrong with tracks - there is no TPC track corresponding to goodtrack.\nGood tack label %d",label);
238 continue; //put comunicate on the screen and continue loop
241 Double_t mass = TDatabasePDG::Instance()->GetParticle(gt.code)->Mass();//CMS mass of this particle
242 Double_t pEtot = TMath::Sqrt(gt.px*gt.px + gt.py*gt.py + gt.pz*gt.pz + mass*mass); //particle total energy
244 AliHBTParticle* part = new AliHBTParticle(gt.code, gt.px, gt.py, gt.pz, pEtot, gt.x, gt.y, gt.z, 0.0);
245 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
246 //if it does not delete it and take next good track
248 iotrack->PropagateTo(gt.x);
249 iotrack->GetExternalParameters(xk,par); //get properties of the track
250 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
251 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
252 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
254 pt=1.0/TMath::Abs(par[4]);
256 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
257 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
258 Double_t tpz = pt * lam; //track z coordinate of momentum
260 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
262 AliHBTParticle* track = new AliHBTParticle(gt.code, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
263 if(Pass(track)) { delete track;continue;}//check if meets all criteria of any of our cuts
264 //if it does not delete it and take next good track
266 particles->AddParticle(currentEvent,part);//put track and particle on the run
267 tracks->AddParticle(currentEvent,track);
270 tarray->Clear(); //clear the array
272 /**************************************/
273 /**************************************/
274 /**************************************/
277 //save environment (resouces) --
278 //clean your place after the work
281 delete goodTPCTracks;
286 /********************************************************************/
287 Int_t AliHBTReaderTPC::OpenFiles()
289 //opens all the files
291 fTracksFile=TFile::Open(fTrackFileName.Data());
292 if (!fTracksFile->IsOpen())
294 Error("AliHBTReaderTPC::OpenFiles","Can't open file with tacks named ",fTrackFileName.Data());
300 fClustersFile=TFile::Open(fClusterFileName.Data());
301 if (!fClustersFile->IsOpen())
303 Error("AliHBTReaderTPC::OpenFiles","Can't open file with TPC clusters named ",fClusterFileName.Data());
312 /********************************************************************/
314 void AliHBTReaderTPC::CloseFiles()
317 fTracksFile->Close();
318 fClustersFile->Close();
321 /********************************************************************/
323 /********************************************************************/
324 /********************************************************************/
325 /********************************************************************/
328 AliGoodTracks::~AliGoodTracks()
331 delete [] fGoodInEvent;
332 for (Int_t i = 0;i<fNevents;i++)
336 /********************************************************************/
337 AliGoodTracks::AliGoodTracks(const TString& infilename)
340 cout<<"AliGoodTracks::AliGoodTracks() ....\n";
343 cerr<<"There is no gAlice"<<endl;
348 if (!gAlice->TreeE())
350 cerr<<"Can not find Header tree (TreeE) in gAlice"<<endl;
355 fNevents = (Int_t)gAlice->TreeE()->GetEntries();
357 cout<<fNevents<<" FOUND"<<endl;
358 ifstream in(infilename.Data());
362 cerr<<"Can not open file with Good TPC Tracks named:"<<infilename.Data()<<endl;
368 fGoodInEvent = new Int_t[fNevents];
369 fData = new struct GoodTrack* [fNevents];
372 for( i = 0;i<fNevents;i++)
375 fData[i] = new struct GoodTrack[50000];
381 if(fGoodInEvent[evno]>=50000)
383 cerr<<"AliGoodTracks::AliGoodTracks() : Not enough place in the array\n";
386 in>>fData[evno][fGoodInEvent[evno]].lab;
387 in>>fData[evno][fGoodInEvent[evno]].code;
388 in>>fData[evno][fGoodInEvent[evno]].px;
389 in>>fData[evno][fGoodInEvent[evno]].py;
390 in>>fData[evno][fGoodInEvent[evno]].pz;
391 in>>fData[evno][fGoodInEvent[evno]].x;
392 in>>fData[evno][fGoodInEvent[evno]].y;
393 in>>fData[evno][fGoodInEvent[evno]].z;
396 cout<<fData[evno][fGoodInEvent[evno]].lab;
397 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].code;
398 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].px;
399 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].py;
400 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].pz;
401 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].x;
402 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].y;
403 cout<<" ";cout<<fData[evno][fGoodInEvent[evno]].z;
406 fGoodInEvent[evno]++;
409 cout<<"AliGoodTracks::AliGoodTracks() .... Done\n";
414 const GoodTrack& AliGoodTracks::GetTrack(Int_t event, Int_t n) const
417 if( (event>fNevents) || (event<0))
419 gAlice->Fatal("AliGoodTracks::GetTrack","No such Event %d",event);
421 if( (n>fGoodInEvent[event]) || (n<0))
423 gAlice->Fatal("AliGoodTracks::GetTrack","No such Good TPC Track %d",n);
425 return fData[event][n];