81f7fe9f |
1 | #include "AliHBTReaderKineTree.h" |
2 | |
3 | #include <iostream.h> |
4 | //#include <fstream.h> |
5 | #include <TString.h> |
6 | #include <TObjString.h> |
7 | #include <TTree.h> |
8 | #include <TFile.h> |
9 | #include <TParticle.h> |
10 | |
11 | #include <AliRun.h> |
12 | #include <AliStack.h> |
13 | #include <AliHeader.h> |
14 | |
15 | #include "AliHBTRun.h" |
16 | #include "AliHBTEvent.h" |
17 | #include "AliHBTParticle.h" |
18 | #include "AliHBTParticleCut.h" |
19 | |
20 | ClassImp(AliHBTReaderKineTree) |
21 | /**********************************************************/ |
22 | |
23 | AliHBTReaderKineTree:: |
24 | AliHBTReaderKineTree():fFileName("galice.root") |
25 | { |
26 | fParticles = new AliHBTRun(); |
27 | fIsRead = kFALSE; |
28 | } |
29 | |
30 | AliHBTReaderKineTree:: |
31 | AliHBTReaderKineTree(TString& fname):fFileName(fname) |
32 | { |
33 | fParticles = new AliHBTRun(); |
34 | fIsRead = kFALSE; |
35 | } |
36 | |
37 | |
38 | /**********************************************************/ |
39 | AliHBTReaderKineTree:: |
40 | AliHBTReaderKineTree(TObjArray* dirs,const Char_t *filename):AliHBTReader(dirs),fFileName(filename) |
41 | { |
42 | fParticles = new AliHBTRun(); |
43 | fIsRead = kFALSE; |
44 | } |
45 | /**********************************************************/ |
46 | |
47 | AliHBTEvent* AliHBTReaderKineTree::GetParticleEvent(Int_t n) |
48 | { |
49 | //returns Nth event with simulated particles |
50 | if (!fIsRead) |
51 | if(Read(fParticles,0x0)) |
52 | { |
53 | Error("GetParticleEvent","Error in reading"); |
54 | return 0x0; |
55 | } |
56 | |
57 | return fParticles->GetEvent(n); |
58 | } |
59 | |
60 | /********************************************************************/ |
61 | |
62 | Int_t AliHBTReaderKineTree::GetNumberOfPartEvents() |
63 | { |
64 | //returns number of events of particles |
65 | if (!fIsRead) |
66 | if(Read(fParticles,0x0)) |
67 | { |
68 | Error("GetNumberOfPartEvents","Error in reading"); |
69 | return 0; |
70 | } |
71 | return fParticles->GetNumberOfEvents(); |
72 | } |
73 | |
74 | |
75 | /**********************************************************/ |
76 | Int_t AliHBTReaderKineTree:: |
77 | Read(AliHBTRun* particles, AliHBTRun *tracks) |
78 | { |
79 | if (!particles) //check if an object is instatiated |
80 | { |
81 | Error("Read"," particles object must instatiated before passing it to the reader"); |
82 | return 1; |
83 | } |
84 | particles->Reset();//clear runs == delete all old events |
85 | |
86 | Int_t Ndirs;//total number of directories specified in fDirs array |
87 | Int_t Nevents; //number of events read in current directory |
88 | Int_t totalNevents = 0; //total number of read events |
89 | Int_t currentdir = 0; //number of current directory name is fDirs array |
90 | |
91 | if (fDirs) //if array with directories is supplied by user |
92 | { |
93 | Ndirs = fDirs->GetEntries(); //get the number if directories |
94 | } |
95 | else |
96 | { |
97 | Ndirs = 0; //if the array is not supplied read only from current directory |
98 | } |
99 | |
100 | do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./" |
101 | { |
102 | cout<<"________________________________________________________\n"; |
103 | TFile* fileK = OpenFile(currentdir); |
104 | TTree* treeE = (TTree*)fileK->Get("TE"); |
105 | if(treeE) |
106 | { |
107 | Nevents = (Int_t)treeE->GetEntries(); |
108 | cout<<"Found "<<Nevents<<" in directory "<<GetDirName(currentdir)<<endl; |
109 | fileK->Delete("TE"); |
110 | } |
111 | else |
112 | { |
113 | Error("Read","Cannot find Header Tree (TE)"); |
114 | Nevents = 0; |
115 | } |
116 | |
117 | for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events |
118 | { |
119 | // cout<<"processing event "<<currentEvent<<" in current dir."<<endl; |
120 | AliStack* stack = GetStack(currentEvent,fileK); |
121 | if (!stack) |
122 | { |
123 | Error("Read","Can not get stack for event %d",currentEvent); |
124 | continue; |
125 | } |
126 | Int_t npart = stack->GetNtrack(); |
127 | Int_t nnn = 0; |
128 | for (Int_t i = 0;i<npart; i++) |
129 | { |
130 | |
131 | TParticle * p = stack->Particle(i); |
132 | if (p->GetFirstMother() >= 0) continue; |
133 | |
134 | if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type |
135 | //if not take next partilce |
136 | |
137 | AliHBTParticle* part = new AliHBTParticle(*p); |
138 | if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts |
139 | //if it does not delete it and take next good track |
140 | particles->AddParticle(totalNevents,part);//put track and particle on the run |
141 | |
142 | if ( (nnn%100) == 0) |
143 | { |
144 | cout<<nnn<<"\r"; |
145 | fflush(0); |
146 | } |
147 | nnn++; |
148 | } |
149 | cout<<"Total read "<<nnn<<endl; |
150 | delete stack; |
151 | totalNevents++; |
152 | } |
153 | delete gAlice; |
154 | gAlice = 0; |
155 | if (fileK) |
156 | { |
157 | fileK->Close(); |
158 | delete fileK; |
159 | fileK = 0; |
160 | } |
161 | |
162 | currentdir++; |
163 | }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array |
164 | fIsRead = kTRUE; |
165 | return 0; |
166 | } |
167 | |
168 | /**********************************************************/ |
169 | AliStack* AliHBTReaderKineTree::GetStack(Int_t n, TFile* file) |
170 | { |
171 | AliHeader *header = new AliHeader(); |
172 | TTree* treeE = (TTree*)file->Get("TE"); |
173 | if(treeE) |
174 | { |
175 | treeE->SetBranchAddress("Header", &header); |
176 | if (!treeE->GetEntry(n)) |
177 | { |
178 | Error("GetEvent","Cannot find event:%dn",n); |
179 | delete header; |
180 | treeE->Delete("TE"); |
181 | return 0x0; |
182 | } |
183 | } |
184 | else |
185 | { |
186 | Error("GetStack","Cannot find Header Tree (TE)n"); |
187 | delete header; |
188 | return 0x0; |
189 | } |
190 | |
191 | AliStack* stack = header->Stack(); |
192 | if (stack) |
193 | { |
194 | if (!stack->GetEvent(n)) |
195 | { |
196 | delete header; |
197 | treeE->Delete("TE"); |
198 | return 0x0; |
199 | } |
200 | } |
201 | delete header; |
202 | treeE->Delete("TE"); |
203 | return stack; |
204 | } |
205 | |
206 | TFile* AliHBTReaderKineTree::OpenFile(Int_t n) |
207 | { |
208 | //opens file with kine tree |
209 | |
210 | const TString& dirname = GetDirName(n); |
211 | if (dirname == "") |
212 | { |
213 | Error("OpenFiles","Can not get directory name"); |
214 | return 0x0; |
215 | } |
216 | TString filename = dirname +"/"+ fFileName; |
217 | TFile *ret = TFile::Open(filename.Data()); |
218 | |
219 | if ( ret == 0x0) |
220 | { |
221 | Error("OpenFiles","Can't open file %s",filename.Data()); |
222 | return 0x0; |
223 | } |
224 | if (!ret->IsOpen()) |
225 | { |
226 | Error("OpenFiles","Can't open file %s",filename.Data()); |
227 | return 0x0; |
228 | } |
229 | |
230 | return ret; |
231 | } |