]>
Commit | Line | Data |
---|---|---|
1b446896 | 1 | #include "AliHBTReader.h" |
73e4d3b7 | 2 | //_________________________________________________________________________ |
3 | /////////////////////////////////////////////////////////////////////////// | |
4 | // | |
5 | // class AliHBTReader | |
6 | // | |
7 | // Reader Base class (reads particles and tracks and | |
8 | // puts it to the AliHBTRun objects | |
9 | // | |
10 | // Provides functionality for both buffering and non-buffering reading | |
11 | // This can be switched on/off via method SetEventBuffering(bool) | |
12 | // The main method that inheriting classes need to implement is ReadNext() | |
13 | // that read next event in queue. | |
14 | // The others are: | |
15 | // Bool_t ReadsTracks() const; specifies if reader is able to read simulated particles | |
16 | // Bool_t ReadsParticles() const; specifies if reader is able to read reconstructed tracks | |
17 | // void Rewind(); rewind reading to the beginning | |
18 | // | |
19 | // reading of next event is triggered via method Next() | |
20 | // | |
21 | // This class provides full functionality for reading from many sources | |
22 | // User can provide TObjArray of TObjString (SetDirs method or via parameter | |
23 | // in constructor) which desribes paths of directories to search data in. | |
24 | // If none specified current directory is searched. | |
25 | // | |
26 | // Piotr.Skowronski@cern.ch | |
27 | /////////////////////////////////////////////////////////////////////////// | |
1b446896 | 28 | |
0fdcc83d | 29 | #include <TString.h> |
30 | #include <TObjString.h> | |
31 | #include <TObjArray.h> | |
32 | #include <TClass.h> | |
fe1a3526 | 33 | #include <TRandom.h> |
bfb09ece | 34 | #include <TH1.h> |
0fdcc83d | 35 | |
1b446896 | 36 | #include "AliHBTParticleCut.h" |
bed069a4 | 37 | #include "AliHBTEvent.h" |
38 | #include "AliHBTRun.h" | |
88cb7938 | 39 | |
1b446896 | 40 | ClassImp(AliHBTReader) |
41 | //pure virtual | |
bed069a4 | 42 | |
1b446896 | 43 | /*************************************************************************************/ |
44 | ||
bed069a4 | 45 | AliHBTReader::AliHBTReader(): |
46 | fCuts(new TObjArray()), | |
47 | fDirs(0x0), | |
48 | fCurrentEvent(0), | |
49 | fCurrentDir(0), | |
50 | fNEventsRead(0), | |
51 | fTracksEvent(0x0), | |
52 | fParticlesEvent(0x0), | |
53 | fParticles(0x0), | |
54 | fTracks(0x0), | |
55 | fIsRead(kFALSE), | |
4f36d7b8 | 56 | fBufferEvents(kFALSE), |
57 | fBlend(kFALSE), | |
58 | fFirst(0), | |
bfb09ece | 59 | fLast(0), |
60 | fTrackCounter(0x0) | |
1b446896 | 61 | { |
62 | //constructor | |
1b446896 | 63 | } |
bed069a4 | 64 | /*************************************************************************************/ |
1b446896 | 65 | |
bed069a4 | 66 | AliHBTReader::AliHBTReader(TObjArray* dirs): |
67 | fCuts(new TObjArray()), | |
68 | fDirs(dirs), | |
69 | fCurrentEvent(0), | |
70 | fCurrentDir(0), | |
71 | fNEventsRead(0), | |
72 | fTracksEvent(0x0), | |
73 | fParticlesEvent(0x0), | |
74 | fParticles(0x0), | |
75 | fTracks(0x0), | |
76 | fIsRead(kFALSE), | |
4f36d7b8 | 77 | fBufferEvents(kFALSE), |
78 | fBlend(kFALSE), | |
79 | fFirst(0), | |
bfb09ece | 80 | fLast(0), |
81 | fTrackCounter(0x0) | |
bed069a4 | 82 | { |
83 | //ctor with array of directories to read as parameter | |
84 | } | |
1b446896 | 85 | /*************************************************************************************/ |
73e4d3b7 | 86 | AliHBTReader::AliHBTReader(const AliHBTReader& in): |
87 | TNamed(in), | |
88 | fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0), | |
89 | fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0), | |
90 | fCurrentEvent(0), | |
91 | fCurrentDir(0), | |
92 | fNEventsRead(0), | |
93 | fTracksEvent(0x0), | |
94 | fParticlesEvent(0x0), | |
95 | fParticles(0x0), | |
96 | fTracks(0x0), | |
97 | fIsRead(kFALSE), | |
98 | fBufferEvents(in.fBufferEvents), | |
99 | fBlend(in.fBlend), | |
100 | fFirst(in.fFirst), | |
101 | fLast(in.fLast), | |
102 | fTrackCounter(0x0) | |
103 | { | |
104 | //cpy constructor | |
105 | } | |
1b446896 | 106 | |
107 | AliHBTReader::~AliHBTReader() | |
108 | { | |
109 | //destructor | |
36ee4bd5 | 110 | if(fCuts) |
111 | { | |
112 | fCuts->SetOwner(); | |
113 | delete fCuts; | |
114 | } | |
bed069a4 | 115 | delete fParticlesEvent; |
116 | delete fTracksEvent; | |
bfb09ece | 117 | delete fTrackCounter; |
1b446896 | 118 | } |
bed069a4 | 119 | /*************************************************************************************/ |
1b446896 | 120 | |
73e4d3b7 | 121 | AliHBTReader& AliHBTReader::operator=(const AliHBTReader& in) |
122 | { | |
123 | //Assigment operator | |
88378f71 | 124 | if (this == &in) return *this; |
125 | TNamed::operator=( (const TNamed&)in ); | |
126 | ||
73e4d3b7 | 127 | fCuts = (in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0; |
128 | fDirs = (in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0; | |
129 | fCurrentEvent = 0; | |
130 | fCurrentDir = 0; | |
131 | fNEventsRead = 0; | |
132 | fTracksEvent = 0x0; | |
133 | fParticlesEvent = 0x0; | |
134 | fParticles = 0x0; | |
135 | fTracks = 0x0; | |
136 | fIsRead = kFALSE; | |
137 | fBufferEvents = in.fBufferEvents; | |
138 | fBlend = in.fBlend; | |
139 | fFirst = in.fFirst; | |
140 | fLast = in.fLast; | |
141 | fTrackCounter = 0x0; | |
855663d9 | 142 | return *this; |
73e4d3b7 | 143 | } |
144 | /*************************************************************************************/ | |
145 | ||
bed069a4 | 146 | Int_t AliHBTReader::Next() |
147 | { | |
148 | //moves to next event | |
bfb09ece | 149 | |
150 | //if asked to read up to event nb. fLast, and it is overcome, report no more events | |
4b308880 | 151 | if ((fNEventsRead > fLast) && (fLast > 0) ) return kTRUE; |
bfb09ece | 152 | |
153 | if (fTrackCounter == 0x0)//create Track Counter | |
4f36d7b8 | 154 | { |
bfb09ece | 155 | fTrackCounter = new TH1I("trackcounter","Track Counter",20000,0,20000); |
156 | fTrackCounter->SetDirectory(0x0); | |
157 | } | |
158 | ||
159 | do //if asked to read from event fFirst, rewind to it | |
160 | { | |
161 | if ( ReadNext() == kTRUE) //if no more evets, return it | |
4f36d7b8 | 162 | return kTRUE; |
163 | }while (fNEventsRead < fFirst); | |
bfb09ece | 164 | |
165 | //here we have event | |
bed069a4 | 166 | |
bfb09ece | 167 | if (fBlend) Blend();//Mix particles order |
fe1a3526 | 168 | |
bfb09ece | 169 | if (fBufferEvents)//store events if buffering is on |
bed069a4 | 170 | { |
171 | if ( ReadsTracks() && fTracksEvent) | |
4f36d7b8 | 172 | fTracks->SetEvent(fNEventsRead-1-fFirst,fTracksEvent); |
bed069a4 | 173 | if ( ReadsParticles() && fParticlesEvent) |
4f36d7b8 | 174 | fParticles->SetEvent(fNEventsRead-1-fFirst,fParticlesEvent); |
bed069a4 | 175 | } |
176 | return kFALSE; | |
177 | } | |
1b446896 | 178 | /*************************************************************************************/ |
179 | ||
180 | void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut) | |
181 | { | |
182 | //sets the new cut | |
183 | ||
184 | if (!cut) //if cut is NULL return with error | |
185 | { | |
186 | Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut "); | |
187 | return; | |
188 | } | |
189 | AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone(); | |
190 | fCuts->Add(c); | |
191 | } | |
bed069a4 | 192 | /********************************************************************/ |
193 | ||
194 | AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n) | |
195 | { | |
196 | //returns Nth event with simulated particles | |
197 | if (ReadsParticles() == kFALSE) | |
198 | { | |
199 | Error("GetParticleEvent","This reader is not able to provide simulated particles."); | |
200 | return 0; | |
201 | } | |
202 | ||
203 | if (!fIsRead) | |
204 | { | |
205 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); | |
206 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); | |
207 | ||
208 | if (Read(fParticles,fTracks)) | |
209 | { | |
210 | Error("GetParticleEvent","Error in reading"); | |
211 | return 0x0; | |
212 | } | |
213 | else fIsRead = kTRUE; | |
214 | } | |
215 | return fParticles->GetEvent(n); | |
216 | } | |
217 | /********************************************************************/ | |
218 | ||
219 | AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n) | |
220 | { | |
221 | //returns Nth event with reconstructed tracks | |
222 | if (ReadsTracks() == kFALSE) | |
223 | { | |
224 | Error("GetTrackEvent","This reader is not able to provide recosntructed tracks."); | |
225 | return 0; | |
226 | } | |
227 | if (!fIsRead) | |
228 | { | |
229 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); | |
230 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); | |
231 | ||
232 | if(Read(fParticles,fTracks)) | |
233 | { | |
234 | Error("GetTrackEvent","Error in reading"); | |
235 | return 0x0; | |
236 | } | |
237 | else fIsRead = kTRUE; | |
238 | } | |
239 | return fTracks->GetEvent(n); | |
240 | } | |
241 | /********************************************************************/ | |
1b446896 | 242 | |
bed069a4 | 243 | Int_t AliHBTReader::GetNumberOfPartEvents() |
244 | { | |
245 | //returns number of events of particles | |
246 | if (ReadsParticles() == kFALSE) | |
247 | { | |
248 | Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles."); | |
249 | return 0; | |
250 | } | |
251 | ||
252 | if (!fIsRead) | |
253 | { | |
254 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); | |
255 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); | |
256 | ||
257 | if (Read(fParticles,fTracks)) | |
258 | { | |
259 | Error("GetNumberOfPartEvents","Error in reading"); | |
260 | return 0; | |
261 | } | |
262 | else fIsRead = kTRUE; | |
263 | } | |
264 | return fParticles->GetNumberOfEvents(); | |
265 | } | |
266 | /********************************************************************/ | |
267 | ||
268 | Int_t AliHBTReader::GetNumberOfTrackEvents() | |
269 | { | |
270 | //returns number of events of tracks | |
271 | if (ReadsTracks() == kFALSE) | |
272 | { | |
273 | Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks."); | |
274 | return 0; | |
275 | } | |
276 | if (!fIsRead) | |
277 | { | |
278 | if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun(); | |
279 | if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun(); | |
280 | ||
281 | if(Read(fParticles,fTracks)) | |
282 | { | |
283 | Error("GetNumberOfTrackEvents","Error in reading"); | |
284 | return 0; | |
285 | } | |
286 | else fIsRead = kTRUE; | |
287 | } | |
288 | return fTracks->GetNumberOfEvents(); | |
289 | } | |
290 | /********************************************************************/ | |
291 | ||
292 | Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks) | |
293 | { | |
294 | //reads data and puts put to the particles and tracks objects | |
295 | //reurns 0 if everything is OK | |
296 | // | |
297 | Info("Read",""); | |
298 | ||
4d91c73a | 299 | if ( ReadsParticles() && (particles == 0x0) ) //check if an object is instatiated |
bed069a4 | 300 | { |
301 | Error("Read"," particles object must be instatiated before passing it to the reader"); | |
302 | return 1; | |
303 | } | |
4d91c73a | 304 | if ( ReadsTracks() && (tracks == 0x0) ) //check if an object is instatiated |
bed069a4 | 305 | { |
306 | Error("Read"," tracks object must be instatiated before passing it to the reader"); | |
307 | return 1; | |
308 | } | |
4d91c73a | 309 | |
310 | if (ReadsParticles()) particles->Reset();//clear runs == delete all old events | |
311 | if (ReadsTracks()) tracks->Reset(); | |
bed069a4 | 312 | |
313 | Rewind(); | |
314 | ||
315 | Int_t i = 0; | |
316 | while(Next() == kFALSE) | |
317 | { | |
318 | if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent); | |
319 | if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent); | |
320 | i++; | |
321 | } | |
322 | return 0; | |
323 | } | |
1b446896 | 324 | /*************************************************************************************/ |
325 | ||
cea0a066 | 326 | Bool_t AliHBTReader::Rejected(AliHBTParticle* p) |
88cb7938 | 327 | { |
1b446896 | 328 | //Method examines whether particle meets all cut and particle type criteria |
329 | ||
330 | if(p==0x0)//of corse we not pass NULL pointers | |
331 | { | |
cea0a066 | 332 | Warning("Rejected()","No Pasaran! We never accept NULL pointers"); |
1b446896 | 333 | return kTRUE; |
334 | } | |
335 | //if no particle is specified, we pass all particles | |
336 | //excluding NULL pointers, of course | |
e526d37c | 337 | if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles |
1b446896 | 338 | for(Int_t i=0; i<fCuts->GetEntriesFast(); i++) |
339 | { | |
340 | AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i)); | |
cea0a066 | 341 | if(!cut.Rejected(p)) return kFALSE; //accepted |
1b446896 | 342 | } |
343 | ||
344 | return kTRUE;//not accepted | |
88cb7938 | 345 | } |
1b446896 | 346 | /*************************************************************************************/ |
347 | ||
cea0a066 | 348 | Bool_t AliHBTReader::Rejected(Int_t pid) |
1b446896 | 349 | { |
350 | //this method checks if any of existing cuts accepts this pid particles | |
351 | //or any cuts accepts all particles | |
352 | ||
353 | if(pid == 0) | |
354 | return kTRUE; | |
e526d37c | 355 | |
356 | if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles | |
1b446896 | 357 | |
358 | for(Int_t i=0; i<fCuts->GetEntriesFast(); i++) | |
359 | { | |
360 | AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i)); | |
361 | //if some of cuts accepts all particles or some accepts particles of this type, accept | |
362 | if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE; | |
363 | } | |
364 | return kTRUE; | |
365 | } | |
366 | /*************************************************************************************/ | |
0fdcc83d | 367 | |
368 | TString& AliHBTReader::GetDirName(Int_t entry) | |
bed069a4 | 369 | { |
370 | //returns directory name of next one to read | |
371 | TString* retval;//return value | |
372 | if (fDirs == 0x0) | |
373 | { | |
374 | retval = new TString("."); | |
375 | return *retval; | |
376 | } | |
377 | ||
378 | if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string | |
379 | { //note that entry==0 is accepted even if array is empty (size=0) | |
380 | Error("GetDirName","Name out of bounds"); | |
381 | retval = new TString(); | |
382 | return *retval; | |
383 | } | |
384 | ||
385 | if (fDirs->GetEntries() == 0) | |
386 | { | |
387 | retval = new TString("."); | |
388 | return *retval; | |
389 | } | |
390 | ||
391 | TClass *objclass = fDirs->At(entry)->IsA(); | |
392 | TClass *stringclass = TObjString::Class(); | |
393 | ||
394 | TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry)); | |
395 | ||
396 | if(dir == 0x0) | |
397 | { | |
398 | Error("GetDirName","Object in TObjArray is not a TObjString or its descendant"); | |
399 | retval = new TString(); | |
400 | return *retval; | |
401 | } | |
402 | if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data()); | |
403 | return dir->String(); | |
404 | } | |
fe1a3526 | 405 | /*************************************************************************************/ |
0fdcc83d | 406 | |
fe1a3526 | 407 | void AliHBTReader::Blend() |
408 | { | |
409 | //randomly change positions of the particles after reading | |
410 | //is used to check if some distr depends on order of particles | |
411 | //(tracking gives particles Pt sorted) | |
4b308880 | 412 | |
413 | if (fParticlesEvent == 0x0) return; | |
414 | ||
fe1a3526 | 415 | for (Int_t i = 2; i < fParticlesEvent->GetNumberOfParticles(); i++) |
416 | { | |
417 | Int_t with = gRandom->Integer(i); | |
418 | fParticlesEvent->SwapParticles(i,with); | |
419 | if (fTracksEvent) fTracksEvent->SwapParticles(i,with); | |
420 | } | |
421 | } | |
bfb09ece | 422 | /*************************************************************************************/ |
423 | ||
424 | void AliHBTReader::WriteTrackCounter() const | |
425 | { | |
426 | //writes the counter histogram | |
427 | ||
428 | if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite); | |
429 | else | |
430 | { | |
431 | Warning("WriteTrackCounter","Counter is NULL"); | |
432 | } | |
433 | } |