Initial import.
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReader.cxx
CommitLineData
d7c6ab14 1// $Id$
2
3//_________________________________________________________________________
4///////////////////////////////////////////////////////////////////////////
5//
6// class AliJetParticlesReader
7//
8// loizides@ikf.uni-frankfurt.de
9///////////////////////////////////////////////////////////////////////////
10
11#include <TObjArray.h>
12#include <TClonesArray.h>
13#include <TClass.h>
14#include <TString.h>
15#include <TObjString.h>
16
17#include "AliJetEventParticles.h"
18#include "AliJetParticlesReader.h"
19
20
21ClassImp(AliJetParticlesReader)
22
23AliJetParticlesReader::AliJetParticlesReader()
24 : TNamed(),
25 fEventParticles(0),
26 fOwner(kTRUE),
27 fDirs(0),
28 fCurrentEvent(0),
29 fCurrentDir(0),
30 fNEventsRead(0),
31 fFirst(0),
32 fLast(0),
33 fPtMin(0),fPtMax(1000),
34 fEtaMin(-1),fEtaMax(1),
35 fPhiMin(0),fPhiMax(2*TMath::Pi())
36{
37}
38
39AliJetParticlesReader::AliJetParticlesReader(TObjArray *dirs)
40 : TNamed(),
41 fEventParticles(0),
42 fOwner(kTRUE),
43 fDirs(dirs),
44 fCurrentEvent(0),
45 fCurrentDir(0),
46 fNEventsRead(0),
47 fFirst(0),
48 fLast(0),
49 fPtMin(0),fPtMax(1000),
50 fEtaMin(-1),fEtaMax(1),
51 fPhiMin(0),fPhiMax(2*TMath::Pi())
52{
53}
54
55AliJetParticlesReader::~AliJetParticlesReader()
56{
57 if((fOwner) && (fEventParticles)) delete fEventParticles;
58}
59
60Int_t AliJetParticlesReader::Next()
61{
62 //moves to next event
63
64 //if asked to read up to event nb. fLast,
65 //and it is overcome, report no more events
66 if ((fNEventsRead > fLast) && (fLast > 0) ) return kFALSE;
67
68 do //if asked to read from event fFirst, rewind to it
69 {
70 if ( ReadNext() == kFALSE)
71 return kFALSE; //if no more evets, return it
72 } while (fNEventsRead < fFirst);
73
74 //here we have event
75
76 return kTRUE;
77}
78
79TString& AliJetParticlesReader::GetDirName(Int_t entry)
80{
81 //returns directory name of entry to read
82
83 TString* retval;//return value
84 if (fDirs == 0)
85 {
86 retval = new TString(".");
87 return *retval;
88 }
89
90 if ((entry>fDirs->GetEntries()) || (entry<0))
91 //if out of bounds return empty string
92 //note that entry==0 is accepted even if array is empty (size=0)
93 {
94 Error("GetDirName","Entry out of bounds");
95 retval = new TString();
96 return *retval;
97 }
98
99 if (fDirs->GetEntries() == 0)
100 {
101 retval = new TString(".");
102 return *retval;
103 }
104
105 TClass *objclass = fDirs->At(entry)->IsA();
106 TClass *stringclass = TObjString::Class();
107
108 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
109 if(dir == 0)
110 {
111 Error("GetDirName","Object in TObjArray is not a TObjString");
112 retval = new TString();
113 return *retval;
114 }
115
116 //Info("GetDirName","Returned ok %s",dir->String().Data());
117 return dir->String();
118}
119
120
121#if 0
122/*************************************************************************************/
123
124void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
125{
126 //sets the new cut
127
128 if (!cut) //if cut is NULL return with error
129 {
130 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
131 return;
132 }
133 AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
134 fCuts->Add(c);
135}
136/********************************************************************/
137
138AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n)
139 {
140 //returns Nth event with simulated particles
141 if (ReadsParticles() == kFALSE)
142 {
143 Error("GetParticleEvent","This reader is not able to provide simulated particles.");
144 return 0;
145 }
146
147 if (!fIsRead)
148 {
149 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
150 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
151
152 if (Read(fParticles,fTracks))
153 {
154 Error("GetParticleEvent","Error in reading");
155 return 0x0;
156 }
157 else fIsRead = kTRUE;
158 }
159 return fParticles->GetEvent(n);
160 }
161/********************************************************************/
162
163AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n)
164 {
165 //returns Nth event with reconstructed tracks
166 if (ReadsTracks() == kFALSE)
167 {
168 Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
169 return 0;
170 }
171 if (!fIsRead)
172 {
173 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
174 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
175
176 if(Read(fParticles,fTracks))
177 {
178 Error("GetTrackEvent","Error in reading");
179 return 0x0;
180 }
181 else fIsRead = kTRUE;
182 }
183 return fTracks->GetEvent(n);
184 }
185/********************************************************************/
186
187Int_t AliHBTReader::GetNumberOfPartEvents()
188 {
189 //returns number of events of particles
190 if (ReadsParticles() == kFALSE)
191 {
192 Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
193 return 0;
194 }
195
196 if (!fIsRead)
197 {
198 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
199 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
200
201 if (Read(fParticles,fTracks))
202 {
203 Error("GetNumberOfPartEvents","Error in reading");
204 return 0;
205 }
206 else fIsRead = kTRUE;
207 }
208 return fParticles->GetNumberOfEvents();
209 }
210/********************************************************************/
211
212Int_t AliHBTReader::GetNumberOfTrackEvents()
213 {
214 //returns number of events of tracks
215 if (ReadsTracks() == kFALSE)
216 {
217 Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
218 return 0;
219 }
220 if (!fIsRead)
221 {
222 if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
223 if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
224
225 if(Read(fParticles,fTracks))
226 {
227 Error("GetNumberOfTrackEvents","Error in reading");
228 return 0;
229 }
230 else fIsRead = kTRUE;
231 }
232 return fTracks->GetNumberOfEvents();
233 }
234/********************************************************************/
235
236Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
237{
238 //reads data and puts put to the particles and tracks objects
239 //reurns 0 if everything is OK
240 //
241 Info("Read","");
242
243 if ( ReadsParticles() && (particles == 0x0) ) //check if an object is instatiated
244 {
245 Error("Read"," particles object must be instatiated before passing it to the reader");
246 return 1;
247 }
248 if ( ReadsTracks() && (tracks == 0x0) ) //check if an object is instatiated
249 {
250 Error("Read"," tracks object must be instatiated before passing it to the reader");
251 return 1;
252 }
253
254 if (ReadsParticles()) particles->Reset();//clear runs == delete all old events
255 if (ReadsTracks()) tracks->Reset();
256
257 Rewind();
258
259 Int_t i = 0;
260 while(Next() == kFALSE)
261 {
262 if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent);
263 if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent);
264 i++;
265 }
266 return 0;
267}
268/*************************************************************************************/
269
270Bool_t AliHBTReader::Pass(AliHBTParticle* p)
271{
272 //Method examines whether particle meets all cut and particle type criteria
273
274 if(p==0x0)//of corse we not pass NULL pointers
275 {
276 Warning("Pass()","No Pasaran! We never accept NULL pointers");
277 return kTRUE;
278 }
279 //if no particle is specified, we pass all particles
280 //excluding NULL pointers, of course
281 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
282 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
283 {
284 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
285 if(!cut.Pass(p)) return kFALSE; //accepted
286 }
287
288 return kTRUE;//not accepted
289}
290/*************************************************************************************/
291
292Bool_t AliHBTReader::Pass(Int_t pid)
293{
294//this method checks if any of existing cuts accepts this pid particles
295//or any cuts accepts all particles
296
297 if(pid == 0)
298 return kTRUE;
299
300 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
301
302 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
303 {
304 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
305 //if some of cuts accepts all particles or some accepts particles of this type, accept
306 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
307 }
308 return kTRUE;
309}
310
311#endif