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