1b446896 |
1 | #include "AliHBTReader.h" |
2 | |
0fdcc83d |
3 | #include <TString.h> |
4 | #include <TObjString.h> |
5 | #include <TObjArray.h> |
6 | #include <TClass.h> |
0fdcc83d |
7 | |
1b446896 |
8 | #include "AliHBTParticleCut.h" |
bed069a4 |
9 | #include "AliHBTEvent.h" |
10 | #include "AliHBTRun.h" |
88cb7938 |
11 | |
1b446896 |
12 | ClassImp(AliHBTReader) |
13 | //pure virtual |
bed069a4 |
14 | |
1b446896 |
15 | /*************************************************************************************/ |
16 | |
bed069a4 |
17 | AliHBTReader::AliHBTReader(): |
18 | fCuts(new TObjArray()), |
19 | fDirs(0x0), |
20 | fCurrentEvent(0), |
21 | fCurrentDir(0), |
22 | fNEventsRead(0), |
23 | fTracksEvent(0x0), |
24 | fParticlesEvent(0x0), |
25 | fParticles(0x0), |
26 | fTracks(0x0), |
27 | fIsRead(kFALSE), |
28 | fBufferEvents(kFALSE) |
1b446896 |
29 | { |
30 | //constructor |
1b446896 |
31 | } |
bed069a4 |
32 | /*************************************************************************************/ |
1b446896 |
33 | |
bed069a4 |
34 | AliHBTReader::AliHBTReader(TObjArray* dirs): |
35 | fCuts(new TObjArray()), |
36 | fDirs(dirs), |
37 | fCurrentEvent(0), |
38 | fCurrentDir(0), |
39 | fNEventsRead(0), |
40 | fTracksEvent(0x0), |
41 | fParticlesEvent(0x0), |
42 | fParticles(0x0), |
43 | fTracks(0x0), |
44 | fIsRead(kFALSE), |
45 | fBufferEvents(kFALSE) |
46 | { |
47 | //ctor with array of directories to read as parameter |
48 | } |
1b446896 |
49 | /*************************************************************************************/ |
50 | |
51 | AliHBTReader::~AliHBTReader() |
52 | { |
53 | //destructor |
36ee4bd5 |
54 | if(fCuts) |
55 | { |
56 | fCuts->SetOwner(); |
57 | delete fCuts; |
58 | } |
bed069a4 |
59 | delete fParticlesEvent; |
60 | delete fTracksEvent; |
1b446896 |
61 | } |
bed069a4 |
62 | /*************************************************************************************/ |
1b446896 |
63 | |
bed069a4 |
64 | Int_t AliHBTReader::Next() |
65 | { |
66 | //moves to next event |
67 | if ( ReadNext() == kTRUE) |
68 | return kTRUE; |
69 | |
70 | if (fBufferEvents) |
71 | { |
72 | if ( ReadsTracks() && fTracksEvent) |
73 | fTracks->SetEvent(fNEventsRead-1,fTracksEvent); |
74 | if ( ReadsParticles() && fParticlesEvent) |
75 | fParticles->SetEvent(fNEventsRead-1,fParticlesEvent); |
76 | } |
77 | return kFALSE; |
78 | } |
1b446896 |
79 | /*************************************************************************************/ |
80 | |
81 | void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut) |
82 | { |
83 | //sets the new cut |
84 | |
85 | if (!cut) //if cut is NULL return with error |
86 | { |
87 | Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut "); |
88 | return; |
89 | } |
90 | AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone(); |
91 | fCuts->Add(c); |
92 | } |
bed069a4 |
93 | /********************************************************************/ |
94 | |
95 | AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n) |
96 | { |
97 | //returns Nth event with simulated particles |
98 | if (ReadsParticles() == kFALSE) |
99 | { |
100 | Error("GetParticleEvent","This reader is not able to provide simulated particles."); |
101 | return 0; |
102 | } |
103 | |
104 | if (!fIsRead) |
105 | { |
106 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); |
107 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); |
108 | |
109 | if (Read(fParticles,fTracks)) |
110 | { |
111 | Error("GetParticleEvent","Error in reading"); |
112 | return 0x0; |
113 | } |
114 | else fIsRead = kTRUE; |
115 | } |
116 | return fParticles->GetEvent(n); |
117 | } |
118 | /********************************************************************/ |
119 | |
120 | AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n) |
121 | { |
122 | //returns Nth event with reconstructed tracks |
123 | if (ReadsTracks() == kFALSE) |
124 | { |
125 | Error("GetTrackEvent","This reader is not able to provide recosntructed tracks."); |
126 | return 0; |
127 | } |
128 | if (!fIsRead) |
129 | { |
130 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); |
131 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); |
132 | |
133 | if(Read(fParticles,fTracks)) |
134 | { |
135 | Error("GetTrackEvent","Error in reading"); |
136 | return 0x0; |
137 | } |
138 | else fIsRead = kTRUE; |
139 | } |
140 | return fTracks->GetEvent(n); |
141 | } |
142 | /********************************************************************/ |
1b446896 |
143 | |
bed069a4 |
144 | Int_t AliHBTReader::GetNumberOfPartEvents() |
145 | { |
146 | //returns number of events of particles |
147 | if (ReadsParticles() == kFALSE) |
148 | { |
149 | Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles."); |
150 | return 0; |
151 | } |
152 | |
153 | if (!fIsRead) |
154 | { |
155 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); |
156 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); |
157 | |
158 | if (Read(fParticles,fTracks)) |
159 | { |
160 | Error("GetNumberOfPartEvents","Error in reading"); |
161 | return 0; |
162 | } |
163 | else fIsRead = kTRUE; |
164 | } |
165 | return fParticles->GetNumberOfEvents(); |
166 | } |
167 | /********************************************************************/ |
168 | |
169 | Int_t AliHBTReader::GetNumberOfTrackEvents() |
170 | { |
171 | //returns number of events of tracks |
172 | if (ReadsTracks() == kFALSE) |
173 | { |
174 | Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks."); |
175 | return 0; |
176 | } |
177 | if (!fIsRead) |
178 | { |
179 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); |
180 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); |
181 | |
182 | if(Read(fParticles,fTracks)) |
183 | { |
184 | Error("GetNumberOfTrackEvents","Error in reading"); |
185 | return 0; |
186 | } |
187 | else fIsRead = kTRUE; |
188 | } |
189 | return fTracks->GetNumberOfEvents(); |
190 | } |
191 | /********************************************************************/ |
192 | |
193 | Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks) |
194 | { |
195 | //reads data and puts put to the particles and tracks objects |
196 | //reurns 0 if everything is OK |
197 | // |
198 | Info("Read",""); |
199 | |
4d91c73a |
200 | if ( ReadsParticles() && (particles == 0x0) ) //check if an object is instatiated |
bed069a4 |
201 | { |
202 | Error("Read"," particles object must be instatiated before passing it to the reader"); |
203 | return 1; |
204 | } |
4d91c73a |
205 | if ( ReadsTracks() && (tracks == 0x0) ) //check if an object is instatiated |
bed069a4 |
206 | { |
207 | Error("Read"," tracks object must be instatiated before passing it to the reader"); |
208 | return 1; |
209 | } |
4d91c73a |
210 | |
211 | if (ReadsParticles()) particles->Reset();//clear runs == delete all old events |
212 | if (ReadsTracks()) tracks->Reset(); |
bed069a4 |
213 | |
214 | Rewind(); |
215 | |
216 | Int_t i = 0; |
217 | while(Next() == kFALSE) |
218 | { |
219 | if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent); |
220 | if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent); |
221 | i++; |
222 | } |
223 | return 0; |
224 | } |
1b446896 |
225 | /*************************************************************************************/ |
226 | |
227 | Bool_t AliHBTReader::Pass(AliHBTParticle* p) |
88cb7938 |
228 | { |
1b446896 |
229 | //Method examines whether particle meets all cut and particle type criteria |
230 | |
231 | if(p==0x0)//of corse we not pass NULL pointers |
232 | { |
233 | Warning("Pass()","No Pasaran! We never accept NULL pointers"); |
234 | return kTRUE; |
235 | } |
236 | //if no particle is specified, we pass all particles |
237 | //excluding NULL pointers, of course |
e526d37c |
238 | if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles |
1b446896 |
239 | for(Int_t i=0; i<fCuts->GetEntriesFast(); i++) |
240 | { |
241 | AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i)); |
242 | if(!cut.Pass(p)) return kFALSE; //accepted |
243 | } |
244 | |
245 | return kTRUE;//not accepted |
88cb7938 |
246 | } |
1b446896 |
247 | /*************************************************************************************/ |
248 | |
249 | Bool_t AliHBTReader::Pass(Int_t pid) |
250 | { |
251 | //this method checks if any of existing cuts accepts this pid particles |
252 | //or any cuts accepts all particles |
253 | |
254 | if(pid == 0) |
255 | return kTRUE; |
e526d37c |
256 | |
257 | if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles |
1b446896 |
258 | |
259 | for(Int_t i=0; i<fCuts->GetEntriesFast(); i++) |
260 | { |
261 | AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i)); |
262 | //if some of cuts accepts all particles or some accepts particles of this type, accept |
263 | if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE; |
264 | } |
265 | return kTRUE; |
266 | } |
267 | /*************************************************************************************/ |
0fdcc83d |
268 | |
269 | TString& AliHBTReader::GetDirName(Int_t entry) |
bed069a4 |
270 | { |
271 | //returns directory name of next one to read |
272 | TString* retval;//return value |
273 | if (fDirs == 0x0) |
274 | { |
275 | retval = new TString("."); |
276 | return *retval; |
277 | } |
278 | |
279 | if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string |
280 | { //note that entry==0 is accepted even if array is empty (size=0) |
281 | Error("GetDirName","Name out of bounds"); |
282 | retval = new TString(); |
283 | return *retval; |
284 | } |
285 | |
286 | if (fDirs->GetEntries() == 0) |
287 | { |
288 | retval = new TString("."); |
289 | return *retval; |
290 | } |
291 | |
292 | TClass *objclass = fDirs->At(entry)->IsA(); |
293 | TClass *stringclass = TObjString::Class(); |
294 | |
295 | TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry)); |
296 | |
297 | if(dir == 0x0) |
298 | { |
299 | Error("GetDirName","Object in TObjArray is not a TObjString or its descendant"); |
300 | retval = new TString(); |
301 | return *retval; |
302 | } |
303 | if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data()); |
304 | return dir->String(); |
305 | } |
0fdcc83d |
306 | |