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 <TGliteXmlEventlist.h>
61 #include "AliAODParticleCut.h"
63 #include "AliAODRun.h"
68 /*************************************************************************************/
70 AliReader::AliReader():
72 fCuts(new TObjArray()),
82 fBufferEvents(kFALSE),
90 /*************************************************************************************/
92 AliReader::AliReader(TObjArray* dirs):
94 fCuts(new TObjArray()),
104 fBufferEvents(kFALSE),
110 //ctor with array of directories to read as parameter
112 /*************************************************************************************/
113 AliReader::AliReader(const AliReader& in):
115 fEventList((in.fEventList)?(TGliteXmlEventlist*)in.fEventList->Clone():0x0),
116 fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0),
117 fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0),
126 fBufferEvents(in.fBufferEvents),
135 AliReader::~AliReader()
145 delete fTrackCounter;
148 /*************************************************************************************/
150 AliReader& AliReader::operator=(const AliReader& in)
153 if (this == &in) return *this;
154 TNamed::operator=( (const TNamed&)in );
156 fCuts = (in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0;
157 fDirs = (in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0;
166 fBufferEvents = in.fBufferEvents;
173 /*************************************************************************************/
175 Int_t AliReader::Next()
177 //moves to next event
179 //if asked to read up to event nb. fLast, and it is overcome, report no more events
180 if ((fNEventsRead >= fLast) && (fLast > 0) ) return kTRUE;
182 if (fTrackCounter == 0x0)//create Track Counter
184 fTrackCounter = new TH1I("trackcounter","Track Counter",20000,0,20000);
185 fTrackCounter->SetDirectory(0x0);
188 do //if asked to read from event fFirst, rewind to it
190 if ( ReadNext() == kTRUE) //if no more evets, return it
192 }while (fNEventsRead < fFirst);
196 if (fBlend) Blend();//Mix particles order
198 if (fBufferEvents)//store events if buffering is on
200 if ( ReadsRec() && fEventRec)
201 fRunRec->SetEvent(fNEventsRead-1-fFirst,fEventRec);
202 if ( ReadsSim() && fEventSim)
203 fRunSim->SetEvent(fNEventsRead-1-fFirst,fEventSim);
207 /*************************************************************************************/
209 void AliReader::AddParticleCut(AliAODParticleCut* cut)
211 //sets the new cut. MAKES A COPY OF THE CUT !!!!
213 if (!cut) //if cut is NULL return with error
215 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
218 AliAODParticleCut *c = (AliAODParticleCut*)cut->Clone();
221 /********************************************************************/
223 AliAOD* AliReader::GetEventSim(Int_t n)
225 //returns Nth event with simulated particles
226 if (ReadsSim() == kFALSE)
228 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
234 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
235 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
237 if (Read(fRunSim,fRunRec))
239 Error("GetParticleEvent","Error in reading");
242 else fIsRead = kTRUE;
244 return fRunSim->GetEvent(n);
246 /********************************************************************/
248 AliAOD* AliReader::GetEventRec(Int_t n)
250 //returns Nth event with reconstructed tracks
251 if (ReadsRec() == kFALSE)
253 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
258 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
259 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
261 if(Read(fRunSim,fRunRec))
263 Error("GetTrackEvent","Error in reading");
266 else fIsRead = kTRUE;
268 return fRunRec->GetEvent(n);
270 /********************************************************************/
272 Int_t AliReader::GetNumberOfSimEvents()
274 //returns number of events of particles
275 if (ReadsSim() == kFALSE)
277 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
283 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
284 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
286 if (Read(fRunSim,fRunRec))
288 Error("GetNumberOfPartEvents","Error in reading");
291 else fIsRead = kTRUE;
293 return fRunSim->GetNumberOfEvents();
295 /********************************************************************/
297 Int_t AliReader::GetNumberOfRecEvents()
299 //returns number of events of tracks
300 if (ReadsRec() == kFALSE)
302 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
307 if (ReadsSim() && (fRunSim == 0x0)) fRunSim = new AliAODRun();
308 if (ReadsRec() && (fRunRec == 0x0)) fRunRec = new AliAODRun();
310 if(Read(fRunSim,fRunRec))
312 Error("GetNumberOfTrackEvents","Error in reading");
315 else fIsRead = kTRUE;
317 return fRunRec->GetNumberOfEvents();
319 /********************************************************************/
321 Int_t AliReader::Read(AliAODRun* particles, AliAODRun *tracks)
323 //reads data and puts put to the particles and tracks objects
324 //reurns 0 if everything is OK
328 if ( ReadsSim() && (particles == 0x0) ) //check if an object is instatiated
330 Error("Read"," particles object must be instatiated before passing it to the reader");
333 if ( ReadsRec() && (tracks == 0x0) ) //check if an object is instatiated
335 Error("Read"," tracks object must be instatiated before passing it to the reader");
339 if (ReadsSim()) particles->Reset();//clear runs == delete all old events
340 if (ReadsRec()) tracks->Reset();
345 while(Next() == kFALSE)
347 if (ReadsRec()) tracks->SetEvent(i,fEventRec);
348 if (ReadsSim()) particles->SetEvent(i,fEventSim);
353 /*************************************************************************************/
355 Bool_t AliReader::Rejected(AliVAODParticle* p)
357 //Method examines whether particle meets all cut and particle type criteria
359 if(p==0x0)//of corse we not pass NULL pointers
361 Warning("Rejected()","No Pasaran! We never accept NULL pointers");
364 //if no particle is specified, we pass all particles
365 //excluding NULL pointers, of course
366 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
367 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
369 AliAODParticleCut &cut = *((AliAODParticleCut*)fCuts->At(i));
370 if(!cut.Rejected(p)) return kFALSE; //accepted
373 return kTRUE;//not accepted
375 /*************************************************************************************/
377 Bool_t AliReader::Rejected(Int_t pid)
379 //this method checks if any of existing cuts accepts this pid particles
380 //or any cuts accepts all particles
385 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
387 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
389 AliAODParticleCut &cut = *((AliAODParticleCut*)fCuts->At(i));
390 //if some of cuts accepts all particles or some accepts particles of this type, accept
391 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
395 /*************************************************************************************/
397 TString AliReader::GetDirName(Int_t entry)
399 //returns directory name of next one to read
400 TString retval;//return value
415 if ( (entry >= fDirs->GetEntries()) || (entry < 0))//if out of bounds return empty string
416 { //note that entry==0 is accepted even if array is empty (size=0)
417 if ( (fDirs->GetEntries() == 0) && (entry == 0) )
422 if (AliVAODParticle::GetDebug() > 0)
424 Warning("GetDirName","Index %d out of bounds",entry);
430 TClass *objclass = fDirs->At(entry)->IsA();
431 TClass *stringclass = TObjString::Class();
433 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
437 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
440 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
441 retval = dir->String();
444 /*************************************************************************************/
446 void AliReader::Blend()
448 //randomly change positions of the particles after reading
449 //is used to check if some distributions (of many particle properties)
450 //depend on the order of particles
451 //(tracking gives particles Pt sorted)
456 npart = fEventSim->GetNumberOfParticles();
461 npart = fEventRec->GetNumberOfParticles();
467 for (Int_t i = 2; i < npart; i++)
469 Int_t with = gRandom->Integer(i);
470 // Info("Blend","%d %d",i, with);
471 if (fEventSim) fEventSim->SwapParticles(i,with);
472 if (fEventRec) fEventRec->SwapParticles(i,with);
475 /*************************************************************************************/
477 void AliReader::WriteTrackCounter() const
479 //writes the counter histogram
481 if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite);
484 Warning("WriteTrackCounter","Counter is NULL");