1 #include "AliHBTReader.h"
4 #include <TObjString.h>
8 #include "AliHBTParticleCut.h"
9 #include "AliHBTEvent.h"
10 #include "AliHBTRun.h"
12 ClassImp(AliHBTReader)
15 /*************************************************************************************/
17 AliHBTReader::AliHBTReader():
18 fCuts(new TObjArray()),
32 /*************************************************************************************/
34 AliHBTReader::AliHBTReader(TObjArray* dirs):
35 fCuts(new TObjArray()),
47 //ctor with array of directories to read as parameter
49 /*************************************************************************************/
51 AliHBTReader::~AliHBTReader()
59 delete fParticlesEvent;
62 /*************************************************************************************/
64 Int_t AliHBTReader::Next()
67 if ( ReadNext() == kTRUE)
72 if ( ReadsTracks() && fTracksEvent)
73 fTracks->SetEvent(fNEventsRead-1,fTracksEvent);
74 if ( ReadsParticles() && fParticlesEvent)
75 fParticles->SetEvent(fNEventsRead-1,fParticlesEvent);
79 /*************************************************************************************/
81 void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
85 if (!cut) //if cut is NULL return with error
87 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
90 AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
93 /********************************************************************/
95 AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n)
97 //returns Nth event with simulated particles
98 if (ReadsParticles() == kFALSE)
100 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
106 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
107 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
109 if (Read(fParticles,fTracks))
111 Error("GetParticleEvent","Error in reading");
114 else fIsRead = kTRUE;
116 return fParticles->GetEvent(n);
118 /********************************************************************/
120 AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n)
122 //returns Nth event with reconstructed tracks
123 if (ReadsTracks() == kFALSE)
125 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
130 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
131 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
133 if(Read(fParticles,fTracks))
135 Error("GetTrackEvent","Error in reading");
138 else fIsRead = kTRUE;
140 return fTracks->GetEvent(n);
142 /********************************************************************/
144 Int_t AliHBTReader::GetNumberOfPartEvents()
146 //returns number of events of particles
147 if (ReadsParticles() == kFALSE)
149 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
155 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
156 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
158 if (Read(fParticles,fTracks))
160 Error("GetNumberOfPartEvents","Error in reading");
163 else fIsRead = kTRUE;
165 return fParticles->GetNumberOfEvents();
167 /********************************************************************/
169 Int_t AliHBTReader::GetNumberOfTrackEvents()
171 //returns number of events of tracks
172 if (ReadsTracks() == kFALSE)
174 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
179 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
180 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
182 if(Read(fParticles,fTracks))
184 Error("GetNumberOfTrackEvents","Error in reading");
187 else fIsRead = kTRUE;
189 return fTracks->GetNumberOfEvents();
191 /********************************************************************/
193 Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
195 //reads data and puts put to the particles and tracks objects
196 //reurns 0 if everything is OK
200 if (!particles) //check if an object is instatiated
202 Error("Read"," particles object must be instatiated before passing it to the reader");
205 if (!tracks) //check if an object is instatiated
207 Error("Read"," tracks object must be instatiated before passing it to the reader");
210 particles->Reset();//clear runs == delete all old events
216 while(Next() == kFALSE)
218 if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent);
219 if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent);
224 /*************************************************************************************/
226 Bool_t AliHBTReader::Pass(AliHBTParticle* p)
228 //Method examines whether particle meets all cut and particle type criteria
230 if(p==0x0)//of corse we not pass NULL pointers
232 Warning("Pass()","No Pasaran! We never accept NULL pointers");
235 //if no particle is specified, we pass all particles
236 //excluding NULL pointers, of course
237 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
238 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
240 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
241 if(!cut.Pass(p)) return kFALSE; //accepted
244 return kTRUE;//not accepted
246 /*************************************************************************************/
248 Bool_t AliHBTReader::Pass(Int_t pid)
250 //this method checks if any of existing cuts accepts this pid particles
251 //or any cuts accepts all particles
256 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
258 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
260 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
261 //if some of cuts accepts all particles or some accepts particles of this type, accept
262 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
266 /*************************************************************************************/
268 TString& AliHBTReader::GetDirName(Int_t entry)
270 //returns directory name of next one to read
271 TString* retval;//return value
274 retval = new TString(".");
278 if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
279 { //note that entry==0 is accepted even if array is empty (size=0)
280 Error("GetDirName","Name out of bounds");
281 retval = new TString();
285 if (fDirs->GetEntries() == 0)
287 retval = new TString(".");
291 TClass *objclass = fDirs->At(entry)->IsA();
292 TClass *stringclass = TObjString::Class();
294 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
298 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
299 retval = new TString();
302 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
303 return dir->String();