1 #include "AliHBTReaderKineTree.h"
6 #include <TObjString.h>
13 #include <AliHeader.h>
15 #include "AliHBTRun.h"
16 #include "AliHBTEvent.h"
17 #include "AliHBTParticle.h"
18 #include "AliHBTParticleCut.h"
20 ClassImp(AliHBTReaderKineTree)
21 /**********************************************************/
23 AliHBTReaderKineTree::
24 AliHBTReaderKineTree():fFileName("galice.root")
26 fParticles = new AliHBTRun();
30 AliHBTReaderKineTree::
31 AliHBTReaderKineTree(TString& fname):fFileName(fname)
33 fParticles = new AliHBTRun();
38 /**********************************************************/
39 AliHBTReaderKineTree::
40 AliHBTReaderKineTree(TObjArray* dirs,const Char_t *filename):AliHBTReader(dirs),fFileName(filename)
42 fParticles = new AliHBTRun();
45 /**********************************************************/
47 AliHBTEvent* AliHBTReaderKineTree::GetParticleEvent(Int_t n)
49 //returns Nth event with simulated particles
51 if(Read(fParticles,0x0))
53 Error("GetParticleEvent","Error in reading");
57 return fParticles->GetEvent(n);
60 /********************************************************************/
62 Int_t AliHBTReaderKineTree::GetNumberOfPartEvents()
64 //returns number of events of particles
66 if(Read(fParticles,0x0))
68 Error("GetNumberOfPartEvents","Error in reading");
71 return fParticles->GetNumberOfEvents();
75 /**********************************************************/
76 Int_t AliHBTReaderKineTree::
77 Read(AliHBTRun* particles, AliHBTRun *tracks)
79 cout<<"AliHBTReaderKineTree::Read()"<<endl;
80 if (!particles) //check if an object is instatiated
82 Error("Read"," particles object must instatiated before passing it to the reader");
85 particles->Reset();//clear runs == delete all old events
87 Int_t Ndirs;//total number of directories specified in fDirs array
88 Int_t Nevents; //number of events read in current directory
89 Int_t totalNevents = 0; //total number of read events
90 Int_t currentdir = 0; //number of current directory name is fDirs array
92 if (fDirs) //if array with directories is supplied by user
94 Ndirs = fDirs->GetEntries(); //get the number if directories
98 Ndirs = 0; //if the array is not supplied read only from current directory
101 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
103 cout<<"________________________________________________________\n";
104 TFile* fileK = OpenFile(currentdir);
105 TTree* treeE = (TTree*)fileK->Get("TE");
108 Nevents = (Int_t)treeE->GetEntries();
109 cout<<"Found "<<Nevents<<" in directory "<<GetDirName(currentdir)<<endl;
114 Error("Read","Cannot find Header Tree (TE)");
118 for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events
120 // cout<<"processing event "<<currentEvent<<" in current dir."<<endl;
121 AliStack* stack = GetStack(currentEvent,fileK);
124 Error("Read","Can not get stack for event %d",currentEvent);
127 Int_t npart = stack->GetNtrack();
129 for (Int_t i = 0;i<npart; i++)
132 TParticle * p = stack->Particle(i);
133 if (p->GetFirstMother() >= 0) continue;
135 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
136 //if not take next partilce
138 AliHBTParticle* part = new AliHBTParticle(*p);
139 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
140 //if it does not delete it and take next good track
141 particles->AddParticle(totalNevents,part);//put track and particle on the run
150 cout<<"Total read "<<nnn<<endl;
164 }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array
169 /**********************************************************/
170 AliStack* AliHBTReaderKineTree::GetStack(Int_t n, TFile* file)
172 AliHeader *header = new AliHeader();
173 TTree* treeE = (TTree*)file->Get("TE");
176 treeE->SetBranchAddress("Header", &header);
177 if (!treeE->GetEntry(n))
179 Error("GetEvent","Cannot find event:%dn",n);
187 Error("GetStack","Cannot find Header Tree (TE)n");
192 AliStack* stack = header->Stack();
195 if (!stack->GetEvent(n))
207 TFile* AliHBTReaderKineTree::OpenFile(Int_t n)
209 //opens file with kine tree
211 const TString& dirname = GetDirName(n);
214 Error("OpenFiles","Can not get directory name");
217 TString filename = dirname +"/"+ fFileName;
218 TFile *ret = TFile::Open(filename.Data());
222 Error("OpenFiles","Can't open file %s",filename.Data());
227 Error("OpenFiles","Can't open file %s",filename.Data());