1 #include "AliHBTReader.h"
2 //_________________________________________________________________________
3 ///////////////////////////////////////////////////////////////////////////
7 // Reader Base class (reads particles and tracks and
8 // puts it to the AliHBTRun objects
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.
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
19 // reading of next event is triggered via method Next()
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.
26 // Piotr.Skowronski@cern.ch
27 ///////////////////////////////////////////////////////////////////////////
30 #include <TObjString.h>
31 #include <TObjArray.h>
36 #include "AliHBTParticleCut.h"
37 #include "AliHBTEvent.h"
38 #include "AliHBTRun.h"
40 ClassImp(AliHBTReader)
43 /*************************************************************************************/
45 AliHBTReader::AliHBTReader():
46 fCuts(new TObjArray()),
56 fBufferEvents(kFALSE),
64 /*************************************************************************************/
66 AliHBTReader::AliHBTReader(TObjArray* dirs):
67 fCuts(new TObjArray()),
77 fBufferEvents(kFALSE),
83 //ctor with array of directories to read as parameter
85 /*************************************************************************************/
86 AliHBTReader::AliHBTReader(const AliHBTReader& in):
88 fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0),
89 fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0),
98 fBufferEvents(in.fBufferEvents),
107 AliHBTReader::~AliHBTReader()
115 delete fParticlesEvent;
117 delete fTrackCounter;
119 /*************************************************************************************/
121 AliHBTReader& AliHBTReader::operator=(const AliHBTReader& in)
124 if (this == &in) return *this;
125 TNamed::operator=( (const TNamed&)in );
127 fCuts = (in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0;
128 fDirs = (in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0;
133 fParticlesEvent = 0x0;
137 fBufferEvents = in.fBufferEvents;
144 /*************************************************************************************/
146 Int_t AliHBTReader::Next()
148 //moves to next event
150 //if asked to read up to event nb. fLast, and it is overcome, report no more events
151 if ((fNEventsRead > fLast) && (fLast > 0) ) return kTRUE;
153 if (fTrackCounter == 0x0)//create Track Counter
155 fTrackCounter = new TH1I("trackcounter","Track Counter",20000,0,20000);
156 fTrackCounter->SetDirectory(0x0);
159 do //if asked to read from event fFirst, rewind to it
161 if ( ReadNext() == kTRUE) //if no more evets, return it
163 }while (fNEventsRead < fFirst);
167 if (fBlend) Blend();//Mix particles order
169 if (fBufferEvents)//store events if buffering is on
171 if ( ReadsTracks() && fTracksEvent)
172 fTracks->SetEvent(fNEventsRead-1-fFirst,fTracksEvent);
173 if ( ReadsParticles() && fParticlesEvent)
174 fParticles->SetEvent(fNEventsRead-1-fFirst,fParticlesEvent);
178 /*************************************************************************************/
180 void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
184 if (!cut) //if cut is NULL return with error
186 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
189 AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
192 /********************************************************************/
194 AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n)
196 //returns Nth event with simulated particles
197 if (ReadsParticles() == kFALSE)
199 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
205 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
206 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
208 if (Read(fParticles,fTracks))
210 Error("GetParticleEvent","Error in reading");
213 else fIsRead = kTRUE;
215 return fParticles->GetEvent(n);
217 /********************************************************************/
219 AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n)
221 //returns Nth event with reconstructed tracks
222 if (ReadsTracks() == kFALSE)
224 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
229 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
230 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
232 if(Read(fParticles,fTracks))
234 Error("GetTrackEvent","Error in reading");
237 else fIsRead = kTRUE;
239 return fTracks->GetEvent(n);
241 /********************************************************************/
243 Int_t AliHBTReader::GetNumberOfPartEvents()
245 //returns number of events of particles
246 if (ReadsParticles() == kFALSE)
248 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
254 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
255 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
257 if (Read(fParticles,fTracks))
259 Error("GetNumberOfPartEvents","Error in reading");
262 else fIsRead = kTRUE;
264 return fParticles->GetNumberOfEvents();
266 /********************************************************************/
268 Int_t AliHBTReader::GetNumberOfTrackEvents()
270 //returns number of events of tracks
271 if (ReadsTracks() == kFALSE)
273 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
278 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
279 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
281 if(Read(fParticles,fTracks))
283 Error("GetNumberOfTrackEvents","Error in reading");
286 else fIsRead = kTRUE;
288 return fTracks->GetNumberOfEvents();
290 /********************************************************************/
292 Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
294 //reads data and puts put to the particles and tracks objects
295 //reurns 0 if everything is OK
299 if ( ReadsParticles() && (particles == 0x0) ) //check if an object is instatiated
301 Error("Read"," particles object must be instatiated before passing it to the reader");
304 if ( ReadsTracks() && (tracks == 0x0) ) //check if an object is instatiated
306 Error("Read"," tracks object must be instatiated before passing it to the reader");
310 if (ReadsParticles()) particles->Reset();//clear runs == delete all old events
311 if (ReadsTracks()) tracks->Reset();
316 while(Next() == kFALSE)
318 if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent);
319 if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent);
324 /*************************************************************************************/
326 Bool_t AliHBTReader::Pass(AliHBTParticle* p)
328 //Method examines whether particle meets all cut and particle type criteria
330 if(p==0x0)//of corse we not pass NULL pointers
332 Warning("Pass()","No Pasaran! We never accept NULL pointers");
335 //if no particle is specified, we pass all particles
336 //excluding NULL pointers, of course
337 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
338 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
340 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
341 if(!cut.Pass(p)) return kFALSE; //accepted
344 return kTRUE;//not accepted
346 /*************************************************************************************/
348 Bool_t AliHBTReader::Pass(Int_t pid)
350 //this method checks if any of existing cuts accepts this pid particles
351 //or any cuts accepts all particles
356 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
358 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
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;
366 /*************************************************************************************/
368 TString& AliHBTReader::GetDirName(Int_t entry)
370 //returns directory name of next one to read
371 TString* retval;//return value
374 retval = new TString(".");
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();
385 if (fDirs->GetEntries() == 0)
387 retval = new TString(".");
391 TClass *objclass = fDirs->At(entry)->IsA();
392 TClass *stringclass = TObjString::Class();
394 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
398 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
399 retval = new TString();
402 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
403 return dir->String();
405 /*************************************************************************************/
407 void AliHBTReader::Blend()
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)
413 if (fParticlesEvent == 0x0) return;
415 for (Int_t i = 2; i < fParticlesEvent->GetNumberOfParticles(); i++)
417 Int_t with = gRandom->Integer(i);
418 fParticlesEvent->SwapParticles(i,with);
419 if (fTracksEvent) fTracksEvent->SwapParticles(i,with);
422 /*************************************************************************************/
424 void AliHBTReader::WriteTrackCounter() const
426 //writes the counter histogram
428 if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite);
431 Warning("WriteTrackCounter","Counter is NULL");