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