2 //_________________________________________________________________________
3 ///////////////////////////////////////////////////////////////////////////
8 // Reads particles and tracks and
9 // puts them to the AliAOD objects and eventually, if needed, buffers AliAODs in AliAODRun(s)
11 // User loops over events calling method Next. In case of success this method returns 0.
12 // In case of error or if there is no more events to read, non-0 value is returned
14 // Reading can be rewound to the beginning using method Rewind.
16 // Tracks are read to the fEventRec (contains reconstructed tracks)
17 // and fEventSim (corresponding MC simulated data) data members,
18 // that are of the type AliAOD.
20 // If a given reader has ability of reading both, reconstructed and simulated data,
21 // these are structured in AODs so a "n'th" simulated particle
22 // (the one stored in the fEventSim at slot n)
23 // corresponds to the n'th reconstructed track (the one stored in the fEventRec at slot n).
25 // The same reconstructed track can be present more than ones in the AOD,
26 // but with a different PID. In this case
27 // pointer to the corresponding MC simulated particles is also present more than ones.
28 // This situation happens if you want to read all particles
29 // with PID probability of being , e.g., pion higher than 60%
30 // and being kaon higher than 40%. Than, if a given track has probability Ppid(pi)=52% and Ppid(K)=48%
31 // than it is read twise.
33 // Provides functionality for both buffering and non-buffering reading
34 // This can be switched on/off via method SetEventBuffering(bool)
35 // The main method that inheriting classes need to implement is ReadNext()
36 // that read next event in queue.
39 // Bool_t ReadsRec() const; specifies if reader is able to read simulated particles
40 // Bool_t ReadsSim() const; specifies if reader is able to read reconstructed tracks
41 // void Rewind(); rewind reading to the beginning
43 // This class provides full functionality for reading from many sources
44 // User can provide TObjArray of TObjStrings (SetDirs method or via parameter
45 // in the constructor) which desribes paths of directories to search data in.
46 // If none specified current directory is searched.
48 // Piotr.Skowronski@cern.ch
50 ///////////////////////////////////////////////////////////////////////////
53 #include <TObjString.h>
54 #include <TObjArray.h>
59 #include "AliAODParticleCut.h"
61 #include "AliAODRun.h"
66 /*************************************************************************************/
68 AliReader::AliReader():
69 fCuts(new TObjArray()),
79 fBufferEvents(kFALSE),
87 /*************************************************************************************/
89 AliReader::AliReader(TObjArray* dirs):
90 fCuts(new TObjArray()),
100 fBufferEvents(kFALSE),
106 //ctor with array of directories to read as parameter
108 /*************************************************************************************/
109 AliReader::AliReader(const AliReader& in):
111 fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0),
112 fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0),
121 fBufferEvents(in.fBufferEvents),
130 AliReader::~AliReader()
140 delete fTrackCounter;
142 /*************************************************************************************/
144 AliReader& AliReader::operator=(const AliReader& in)
147 if (this == &in) return *this;
148 TNamed::operator=( (const TNamed&)in );
150 fCuts = (in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0;
151 fDirs = (in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0;
160 fBufferEvents = in.fBufferEvents;
167 /*************************************************************************************/
169 Int_t AliReader::Next()
171 //moves to next event
173 //if asked to read up to event nb. fLast, and it is overcome, report no more events
174 if ((fNEventsRead >= fLast) && (fLast > 0) ) return kTRUE;
176 if (fTrackCounter == 0x0)//create Track Counter
178 fTrackCounter = new TH1I("trackcounter","Track Counter",20000,0,20000);
179 fTrackCounter->SetDirectory(0x0);
182 do //if asked to read from event fFirst, rewind to it
184 if ( ReadNext() == kTRUE) //if no more evets, return it
186 }while (fNEventsRead < fFirst);
190 if (fBlend) Blend();//Mix particles order
192 if (fBufferEvents)//store events if buffering is on
194 if ( ReadsRec() && fEventRec)
195 fRunRec->SetEvent(fNEventsRead-1-fFirst,fEventRec);
196 if ( ReadsSim() && fEventSim)
197 fRunSim->SetEvent(fNEventsRead-1-fFirst,fEventSim);
201 /*************************************************************************************/
203 void AliReader::AddParticleCut(AliAODParticleCut* cut)
205 //sets the new cut. MAKES A COPY OF THE CUT !!!!
207 if (!cut) //if cut is NULL return with error
209 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
212 AliAODParticleCut *c = (AliAODParticleCut*)cut->Clone();
215 /********************************************************************/
217 AliAOD* AliReader::GetEventSim(Int_t n)
219 //returns Nth event with simulated particles
220 if (ReadsSim() == kFALSE)
222 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
228 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
229 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
231 if (Read(fRunSim,fRunRec))
233 Error("GetParticleEvent","Error in reading");
236 else fIsRead = kTRUE;
238 return fRunSim->GetEvent(n);
240 /********************************************************************/
242 AliAOD* AliReader::GetEventRec(Int_t n)
244 //returns Nth event with reconstructed tracks
245 if (ReadsRec() == kFALSE)
247 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
252 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
253 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
255 if(Read(fRunSim,fRunRec))
257 Error("GetTrackEvent","Error in reading");
260 else fIsRead = kTRUE;
262 return fRunRec->GetEvent(n);
264 /********************************************************************/
266 Int_t AliReader::GetNumberOfSimEvents()
268 //returns number of events of particles
269 if (ReadsSim() == kFALSE)
271 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
277 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
278 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
280 if (Read(fRunSim,fRunRec))
282 Error("GetNumberOfPartEvents","Error in reading");
285 else fIsRead = kTRUE;
287 return fRunSim->GetNumberOfEvents();
289 /********************************************************************/
291 Int_t AliReader::GetNumberOfRecEvents()
293 //returns number of events of tracks
294 if (ReadsRec() == kFALSE)
296 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
301 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
302 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
304 if(Read(fRunSim,fRunRec))
306 Error("GetNumberOfTrackEvents","Error in reading");
309 else fIsRead = kTRUE;
311 return fRunRec->GetNumberOfEvents();
313 /********************************************************************/
315 Int_t AliReader::Read(AliAODRun* particles, AliAODRun *tracks)
317 //reads data and puts put to the particles and tracks objects
318 //reurns 0 if everything is OK
322 if ( ReadsSim() && (particles == 0x0) ) //check if an object is instatiated
324 Error("Read"," particles object must be instatiated before passing it to the reader");
327 if ( ReadsRec() && (tracks == 0x0) ) //check if an object is instatiated
329 Error("Read"," tracks object must be instatiated before passing it to the reader");
333 if (ReadsSim()) particles->Reset();//clear runs == delete all old events
334 if (ReadsRec()) tracks->Reset();
339 while(Next() == kFALSE)
341 if (ReadsRec()) tracks->SetEvent(i,fEventRec);
342 if (ReadsSim()) particles->SetEvent(i,fEventSim);
347 /*************************************************************************************/
349 Bool_t AliReader::Rejected(AliVAODParticle* p)
351 //Method examines whether particle meets all cut and particle type criteria
353 if(p==0x0)//of corse we not pass NULL pointers
355 Warning("Rejected()","No Pasaran! We never accept NULL pointers");
358 //if no particle is specified, we pass all particles
359 //excluding NULL pointers, of course
360 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
361 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
363 AliAODParticleCut &cut = *((AliAODParticleCut*)fCuts->At(i));
364 if(!cut.Rejected(p)) return kFALSE; //accepted
367 return kTRUE;//not accepted
369 /*************************************************************************************/
371 Bool_t AliReader::Rejected(Int_t pid)
373 //this method checks if any of existing cuts accepts this pid particles
374 //or any cuts accepts all particles
379 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
381 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
383 AliAODParticleCut &cut = *((AliAODParticleCut*)fCuts->At(i));
384 //if some of cuts accepts all particles or some accepts particles of this type, accept
385 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
389 /*************************************************************************************/
391 TString AliReader::GetDirName(Int_t entry)
393 //returns directory name of next one to read
394 TString retval;//return value
409 if ( (entry >= fDirs->GetEntries()) || (entry < 0))//if out of bounds return empty string
410 { //note that entry==0 is accepted even if array is empty (size=0)
411 if ( (fDirs->GetEntries() == 0) && (entry == 0) )
416 if (AliVAODParticle::GetDebug() > 0)
418 Warning("GetDirName","Index %d out of bounds",entry);
424 TClass *objclass = fDirs->At(entry)->IsA();
425 TClass *stringclass = TObjString::Class();
427 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
431 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
434 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
435 retval = dir->String();
438 /*************************************************************************************/
440 void AliReader::Blend()
442 //randomly change positions of the particles after reading
443 //is used to check if some distributions (of many particle properties)
444 //depend on the order of particles
445 //(tracking gives particles Pt sorted)
450 npart = fEventSim->GetNumberOfParticles();
455 npart = fEventRec->GetNumberOfParticles();
461 for (Int_t i = 2; i < npart; i++)
463 Int_t with = gRandom->Integer(i);
464 // Info("Blend","%d %d",i, with);
465 if (fEventSim) fEventSim->SwapParticles(i,with);
466 if (fEventRec) fEventRec->SwapParticles(i,with);
469 /*************************************************************************************/
471 void AliReader::WriteTrackCounter() const
473 //writes the counter histogram
475 if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite);
478 Warning("WriteTrackCounter","Counter is NULL");