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