1 #include "AliHBTReader.h"
4 #include <TObjString.h>
10 #include "AliHBTParticleCut.h"
11 #include "AliHBTEvent.h"
12 #include "AliHBTRun.h"
14 ClassImp(AliHBTReader)
17 /*************************************************************************************/
19 AliHBTReader::AliHBTReader():
20 fCuts(new TObjArray()),
30 fBufferEvents(kFALSE),
38 /*************************************************************************************/
40 AliHBTReader::AliHBTReader(TObjArray* dirs):
41 fCuts(new TObjArray()),
51 fBufferEvents(kFALSE),
57 //ctor with array of directories to read as parameter
59 /*************************************************************************************/
61 AliHBTReader::~AliHBTReader()
69 delete fParticlesEvent;
73 /*************************************************************************************/
75 Int_t AliHBTReader::Next()
79 //if asked to read up to event nb. fLast, and it is overcome, report no more events
80 if ((fNEventsRead > fLast) && (fLast > 0) ) return kTRUE;
82 if (fTrackCounter == 0x0)//create Track Counter
84 fTrackCounter = new TH1I("trackcounter","Track Counter",20000,0,20000);
85 fTrackCounter->SetDirectory(0x0);
88 do //if asked to read from event fFirst, rewind to it
90 if ( ReadNext() == kTRUE) //if no more evets, return it
92 }while (fNEventsRead < fFirst);
96 if (fBlend) Blend();//Mix particles order
98 if (fBufferEvents)//store events if buffering is on
100 if ( ReadsTracks() && fTracksEvent)
101 fTracks->SetEvent(fNEventsRead-1-fFirst,fTracksEvent);
102 if ( ReadsParticles() && fParticlesEvent)
103 fParticles->SetEvent(fNEventsRead-1-fFirst,fParticlesEvent);
107 /*************************************************************************************/
109 void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
113 if (!cut) //if cut is NULL return with error
115 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
118 AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
121 /********************************************************************/
123 AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n)
125 //returns Nth event with simulated particles
126 if (ReadsParticles() == kFALSE)
128 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
134 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
135 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
137 if (Read(fParticles,fTracks))
139 Error("GetParticleEvent","Error in reading");
142 else fIsRead = kTRUE;
144 return fParticles->GetEvent(n);
146 /********************************************************************/
148 AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n)
150 //returns Nth event with reconstructed tracks
151 if (ReadsTracks() == kFALSE)
153 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
158 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
159 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
161 if(Read(fParticles,fTracks))
163 Error("GetTrackEvent","Error in reading");
166 else fIsRead = kTRUE;
168 return fTracks->GetEvent(n);
170 /********************************************************************/
172 Int_t AliHBTReader::GetNumberOfPartEvents()
174 //returns number of events of particles
175 if (ReadsParticles() == kFALSE)
177 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
183 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
184 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
186 if (Read(fParticles,fTracks))
188 Error("GetNumberOfPartEvents","Error in reading");
191 else fIsRead = kTRUE;
193 return fParticles->GetNumberOfEvents();
195 /********************************************************************/
197 Int_t AliHBTReader::GetNumberOfTrackEvents()
199 //returns number of events of tracks
200 if (ReadsTracks() == kFALSE)
202 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
207 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
208 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
210 if(Read(fParticles,fTracks))
212 Error("GetNumberOfTrackEvents","Error in reading");
215 else fIsRead = kTRUE;
217 return fTracks->GetNumberOfEvents();
219 /********************************************************************/
221 Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
223 //reads data and puts put to the particles and tracks objects
224 //reurns 0 if everything is OK
228 if ( ReadsParticles() && (particles == 0x0) ) //check if an object is instatiated
230 Error("Read"," particles object must be instatiated before passing it to the reader");
233 if ( ReadsTracks() && (tracks == 0x0) ) //check if an object is instatiated
235 Error("Read"," tracks object must be instatiated before passing it to the reader");
239 if (ReadsParticles()) particles->Reset();//clear runs == delete all old events
240 if (ReadsTracks()) tracks->Reset();
245 while(Next() == kFALSE)
247 if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent);
248 if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent);
253 /*************************************************************************************/
255 Bool_t AliHBTReader::Pass(AliHBTParticle* p)
257 //Method examines whether particle meets all cut and particle type criteria
259 if(p==0x0)//of corse we not pass NULL pointers
261 Warning("Pass()","No Pasaran! We never accept NULL pointers");
264 //if no particle is specified, we pass all particles
265 //excluding NULL pointers, of course
266 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
267 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
269 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
270 if(!cut.Pass(p)) return kFALSE; //accepted
273 return kTRUE;//not accepted
275 /*************************************************************************************/
277 Bool_t AliHBTReader::Pass(Int_t pid)
279 //this method checks if any of existing cuts accepts this pid particles
280 //or any cuts accepts all particles
285 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
287 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
289 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
290 //if some of cuts accepts all particles or some accepts particles of this type, accept
291 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
295 /*************************************************************************************/
297 TString& AliHBTReader::GetDirName(Int_t entry)
299 //returns directory name of next one to read
300 TString* retval;//return value
303 retval = new TString(".");
307 if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
308 { //note that entry==0 is accepted even if array is empty (size=0)
309 Error("GetDirName","Name out of bounds");
310 retval = new TString();
314 if (fDirs->GetEntries() == 0)
316 retval = new TString(".");
320 TClass *objclass = fDirs->At(entry)->IsA();
321 TClass *stringclass = TObjString::Class();
323 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
327 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
328 retval = new TString();
331 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
332 return dir->String();
334 /*************************************************************************************/
336 void AliHBTReader::Blend()
338 //randomly change positions of the particles after reading
339 //is used to check if some distr depends on order of particles
340 //(tracking gives particles Pt sorted)
342 if (fParticlesEvent == 0x0) return;
344 for (Int_t i = 2; i < fParticlesEvent->GetNumberOfParticles(); i++)
346 Int_t with = gRandom->Integer(i);
347 fParticlesEvent->SwapParticles(i,with);
348 if (fTracksEvent) fTracksEvent->SwapParticles(i,with);
351 /*************************************************************************************/
353 void AliHBTReader::WriteTrackCounter() const
355 //writes the counter histogram
357 if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite);
360 Warning("WriteTrackCounter","Counter is NULL");