2 //_________________________________________________________________________
3 ///////////////////////////////////////////////////////////////////////////
7 // Reader Base class (reads particles and tracks and
8 // puts it to the AliAODRun 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 ReadsRec() const; specifies if reader is able to read simulated particles
16 // Bool_t ReadsSim() 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 "AliAODParticleCut.h"
38 #include "AliAODRun.h"
43 /*************************************************************************************/
45 AliReader::AliReader():
46 fCuts(new TObjArray()),
56 fBufferEvents(kFALSE),
64 /*************************************************************************************/
66 AliReader::AliReader(TObjArray* dirs):
67 fCuts(new TObjArray()),
77 fBufferEvents(kFALSE),
83 //ctor with array of directories to read as parameter
85 /*************************************************************************************/
86 AliReader::AliReader(const AliReader& in):
88 fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0),
89 fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0),
98 fBufferEvents(in.fBufferEvents),
107 AliReader::~AliReader()
117 delete fTrackCounter;
119 /*************************************************************************************/
121 AliReader& AliReader::operator=(const AliReader& 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;
137 fBufferEvents = in.fBufferEvents;
144 /*************************************************************************************/
146 Int_t AliReader::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 ( ReadsRec() && fEventRec)
172 fRunRec->SetEvent(fNEventsRead-1-fFirst,fEventRec);
173 if ( ReadsSim() && fEventSim)
174 fRunSim->SetEvent(fNEventsRead-1-fFirst,fEventSim);
178 /*************************************************************************************/
180 void AliReader::AddParticleCut(AliAODParticleCut* cut)
182 //sets the new cut. MAKES A COPY OF THE 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 AliAODParticleCut *c = (AliAODParticleCut*)cut->Clone();
192 /********************************************************************/
194 AliAOD* AliReader::GetEventSim(Int_t n)
196 //returns Nth event with simulated particles
197 if (ReadsSim() == kFALSE)
199 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
205 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
206 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
208 if (Read(fRunSim,fRunRec))
210 Error("GetParticleEvent","Error in reading");
213 else fIsRead = kTRUE;
215 return fRunSim->GetEvent(n);
217 /********************************************************************/
219 AliAOD* AliReader::GetEventRec(Int_t n)
221 //returns Nth event with reconstructed tracks
222 if (ReadsRec() == kFALSE)
224 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
229 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
230 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
232 if(Read(fRunSim,fRunRec))
234 Error("GetTrackEvent","Error in reading");
237 else fIsRead = kTRUE;
239 return fRunRec->GetEvent(n);
241 /********************************************************************/
243 Int_t AliReader::GetNumberOfSimEvents()
245 //returns number of events of particles
246 if (ReadsSim() == kFALSE)
248 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
254 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
255 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
257 if (Read(fRunSim,fRunRec))
259 Error("GetNumberOfPartEvents","Error in reading");
262 else fIsRead = kTRUE;
264 return fRunSim->GetNumberOfEvents();
266 /********************************************************************/
268 Int_t AliReader::GetNumberOfRecEvents()
270 //returns number of events of tracks
271 if (ReadsRec() == kFALSE)
273 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
278 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
279 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
281 if(Read(fRunSim,fRunRec))
283 Error("GetNumberOfTrackEvents","Error in reading");
286 else fIsRead = kTRUE;
288 return fRunRec->GetNumberOfEvents();
290 /********************************************************************/
292 Int_t AliReader::Read(AliAODRun* particles, AliAODRun *tracks)
294 //reads data and puts put to the particles and tracks objects
295 //reurns 0 if everything is OK
299 if ( ReadsSim() && (particles == 0x0) ) //check if an object is instatiated
301 Error("Read"," particles object must be instatiated before passing it to the reader");
304 if ( ReadsRec() && (tracks == 0x0) ) //check if an object is instatiated
306 Error("Read"," tracks object must be instatiated before passing it to the reader");
310 if (ReadsSim()) particles->Reset();//clear runs == delete all old events
311 if (ReadsRec()) tracks->Reset();
316 while(Next() == kFALSE)
318 if (ReadsRec()) tracks->SetEvent(i,fEventRec);
319 if (ReadsSim()) particles->SetEvent(i,fEventSim);
324 /*************************************************************************************/
326 Bool_t AliReader::Pass(AliAODParticle* 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 AliAODParticleCut &cut = *((AliAODParticleCut*)fCuts->At(i));
341 if(!cut.Pass(p)) return kFALSE; //accepted
344 return kTRUE;//not accepted
346 /*************************************************************************************/
348 Bool_t AliReader::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 AliAODParticleCut &cut = *((AliAODParticleCut*)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& AliReader::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 AliReader::Blend()
409 //randomly change positions of the particles after reading
410 //is used to check if some distributions (of many particle properties)
411 //depend on the order of particles
412 //(tracking gives particles Pt sorted)
414 if (fEventSim == 0x0) return;
416 for (Int_t i = 2; i < fEventSim->GetNumberOfParticles(); i++)
418 Int_t with = gRandom->Integer(i);
419 fEventSim->SwapParticles(i,with);
420 if (fEventRec) fEventRec->SwapParticles(i,with);
423 /*************************************************************************************/
425 void AliReader::WriteTrackCounter() const
427 //writes the counter histogram
429 if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite);
432 Warning("WriteTrackCounter","Counter is NULL");