1 #include "AliHBTReader.h"
4 #include <TObjString.h>
9 #include "AliHBTParticleCut.h"
10 #include "AliHBTEvent.h"
11 #include "AliHBTRun.h"
13 ClassImp(AliHBTReader)
16 /*************************************************************************************/
18 AliHBTReader::AliHBTReader():
19 fCuts(new TObjArray()),
29 fBufferEvents(kFALSE),
36 /*************************************************************************************/
38 AliHBTReader::AliHBTReader(TObjArray* dirs):
39 fCuts(new TObjArray()),
49 fBufferEvents(kFALSE),
54 //ctor with array of directories to read as parameter
56 /*************************************************************************************/
58 AliHBTReader::~AliHBTReader()
66 delete fParticlesEvent;
69 /*************************************************************************************/
71 Int_t AliHBTReader::Next()
74 if ((fNEventsRead > fLast) && (fLast > 0) ) return kTRUE;
78 if ( ReadNext() == kTRUE)
80 }while (fNEventsRead < fFirst);
86 if ( ReadsTracks() && fTracksEvent)
87 fTracks->SetEvent(fNEventsRead-1-fFirst,fTracksEvent);
88 if ( ReadsParticles() && fParticlesEvent)
89 fParticles->SetEvent(fNEventsRead-1-fFirst,fParticlesEvent);
93 /*************************************************************************************/
95 void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
99 if (!cut) //if cut is NULL return with error
101 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
104 AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
107 /********************************************************************/
109 AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n)
111 //returns Nth event with simulated particles
112 if (ReadsParticles() == kFALSE)
114 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
120 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
121 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
123 if (Read(fParticles,fTracks))
125 Error("GetParticleEvent","Error in reading");
128 else fIsRead = kTRUE;
130 return fParticles->GetEvent(n);
132 /********************************************************************/
134 AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n)
136 //returns Nth event with reconstructed tracks
137 if (ReadsTracks() == kFALSE)
139 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
144 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
145 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
147 if(Read(fParticles,fTracks))
149 Error("GetTrackEvent","Error in reading");
152 else fIsRead = kTRUE;
154 return fTracks->GetEvent(n);
156 /********************************************************************/
158 Int_t AliHBTReader::GetNumberOfPartEvents()
160 //returns number of events of particles
161 if (ReadsParticles() == kFALSE)
163 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
169 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
170 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
172 if (Read(fParticles,fTracks))
174 Error("GetNumberOfPartEvents","Error in reading");
177 else fIsRead = kTRUE;
179 return fParticles->GetNumberOfEvents();
181 /********************************************************************/
183 Int_t AliHBTReader::GetNumberOfTrackEvents()
185 //returns number of events of tracks
186 if (ReadsTracks() == kFALSE)
188 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
193 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
194 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
196 if(Read(fParticles,fTracks))
198 Error("GetNumberOfTrackEvents","Error in reading");
201 else fIsRead = kTRUE;
203 return fTracks->GetNumberOfEvents();
205 /********************************************************************/
207 Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
209 //reads data and puts put to the particles and tracks objects
210 //reurns 0 if everything is OK
214 if ( ReadsParticles() && (particles == 0x0) ) //check if an object is instatiated
216 Error("Read"," particles object must be instatiated before passing it to the reader");
219 if ( ReadsTracks() && (tracks == 0x0) ) //check if an object is instatiated
221 Error("Read"," tracks object must be instatiated before passing it to the reader");
225 if (ReadsParticles()) particles->Reset();//clear runs == delete all old events
226 if (ReadsTracks()) tracks->Reset();
231 while(Next() == kFALSE)
233 if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent);
234 if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent);
239 /*************************************************************************************/
241 Bool_t AliHBTReader::Pass(AliHBTParticle* p)
243 //Method examines whether particle meets all cut and particle type criteria
245 if(p==0x0)//of corse we not pass NULL pointers
247 Warning("Pass()","No Pasaran! We never accept NULL pointers");
250 //if no particle is specified, we pass all particles
251 //excluding NULL pointers, of course
252 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
253 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
255 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
256 if(!cut.Pass(p)) return kFALSE; //accepted
259 return kTRUE;//not accepted
261 /*************************************************************************************/
263 Bool_t AliHBTReader::Pass(Int_t pid)
265 //this method checks if any of existing cuts accepts this pid particles
266 //or any cuts accepts all particles
271 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
273 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
275 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
276 //if some of cuts accepts all particles or some accepts particles of this type, accept
277 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
281 /*************************************************************************************/
283 TString& AliHBTReader::GetDirName(Int_t entry)
285 //returns directory name of next one to read
286 TString* retval;//return value
289 retval = new TString(".");
293 if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
294 { //note that entry==0 is accepted even if array is empty (size=0)
295 Error("GetDirName","Name out of bounds");
296 retval = new TString();
300 if (fDirs->GetEntries() == 0)
302 retval = new TString(".");
306 TClass *objclass = fDirs->At(entry)->IsA();
307 TClass *stringclass = TObjString::Class();
309 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
313 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
314 retval = new TString();
317 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
318 return dir->String();
320 /*************************************************************************************/
322 void AliHBTReader::Blend()
324 //randomly change positions of the particles after reading
325 //is used to check if some distr depends on order of particles
326 //(tracking gives particles Pt sorted)
328 if (fParticlesEvent == 0x0) return;
330 for (Int_t i = 2; i < fParticlesEvent->GetNumberOfParticles(); i++)
332 Int_t with = gRandom->Integer(i);
333 fParticlesEvent->SwapParticles(i,with);
334 if (fTracksEvent) fTracksEvent->SwapParticles(i,with);