]>
Commit | Line | Data |
---|---|---|
2a910c25 | 1 | #include "AliEventPoolManager.h" |
2 | ||
c82bb898 | 3 | using std::cout; |
4 | using std::endl; | |
2a910c25 | 5 | ClassImp(AliEventPool) |
6 | ||
7 | void AliEventPool::PrintInfo() const | |
8 | { | |
9 | cout << Form("%20s: %d events", "Pool capacity", fMixDepth) << endl; | |
10 | cout << Form("%20s: %d events, %d tracks", "Current size", | |
11 | GetCurrentNEvents(), NTracksInPool()) << endl; | |
12 | cout << Form("%20s: %.1f to %.1f", "Sub-event mult.", fMultMin, fMultMax) << endl; | |
13 | cout << Form("%20s: %.1f to %.1f", "Z-vtx range", fZvtxMin, fZvtxMax) << endl; | |
6df75196 | 14 | cout << Form("%20s: %.1f to %.1f", "Psi range", fPsiMin, fPsiMax) << endl; |
2a910c25 | 15 | |
16 | return; | |
17 | } | |
18 | ||
6df75196 | 19 | Bool_t AliEventPool::EventMatchesBin(Int_t mult, Double_t zvtx, Double_t psi) const |
2a910c25 | 20 | { |
6df75196 | 21 | return EventMatchesBin((Double_t) mult, zvtx, psi); |
2a910c25 | 22 | } |
23 | ||
6df75196 | 24 | Bool_t AliEventPool::EventMatchesBin(Double_t mult, Double_t zvtx, Double_t psi) const |
2a910c25 | 25 | { |
26 | // Lower bin limit included; upper limit excluded. | |
27 | ||
28 | Bool_t multOK = (mult >= fMultMin && mult < fMultMax); | |
29 | Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax); | |
6df75196 | 30 | Bool_t psiOK = (psi >= fPsiMin && psi < fPsiMax); |
31 | return (multOK && zvtxOK && psiOK); | |
2a910c25 | 32 | } |
33 | ||
34 | Int_t AliEventPool::NTracksInPool() const | |
35 | { | |
36 | // Number of tracks for this cent, zvtx bin; possibly includes many | |
37 | // events. | |
38 | ||
39 | Int_t ntrk=0; | |
40 | for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) { | |
41 | ntrk += fNTracksInEvent.at(i); | |
42 | } | |
43 | return ntrk; | |
44 | } | |
45 | ||
46 | Int_t AliEventPool::SetEventMultRange(Int_t multMin, Int_t multMax) | |
47 | { | |
48 | fMultMin = (Double_t)multMin; | |
49 | fMultMax = (Double_t)multMax; | |
50 | return 0; | |
51 | } | |
52 | ||
53 | Int_t AliEventPool::SetEventMultRange(Double_t multMin, Double_t multMax) | |
54 | { | |
55 | fMultMin = multMin; | |
56 | fMultMax = multMax; | |
57 | return 0; | |
58 | } | |
59 | ||
60 | Int_t AliEventPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax) | |
61 | { | |
62 | fZvtxMin = zvtxMin; | |
63 | fZvtxMax = zvtxMax; | |
64 | return 0; | |
65 | } | |
66 | ||
6df75196 | 67 | Int_t AliEventPool::SetEventPsiRange(Double_t psiMin, Double_t psiMax) |
68 | { | |
69 | fPsiMin = psiMin; | |
70 | fPsiMax = psiMax; | |
71 | return 0; | |
72 | } | |
73 | ||
2a910c25 | 74 | Int_t AliEventPool::GlobalEventIndex(Int_t j) const |
75 | { | |
76 | // Index returned from passing local pool event index. | |
77 | ||
78 | if (j < 0 || j >= (Int_t)fEventIndex.size()) { | |
79 | cout << "ERROR in AliEventPool::GlobalEventIndex(): " | |
80 | << " Invalid index " << j << endl; | |
81 | return -99; | |
82 | } | |
83 | return fEventIndex.at(j); | |
84 | } | |
85 | ||
86 | Int_t AliEventPool::UpdatePool(TObjArray *trk) | |
87 | { | |
88 | // A rolling buffer (a double-ended queue) is updated by removing | |
89 | // the oldest event, and appending the newest. | |
c05ff6be | 90 | // |
91 | // the ownership of <trk> is delegated to this class | |
2a910c25 | 92 | |
93 | static Int_t iEvent = -1; | |
94 | iEvent++; | |
95 | ||
96 | Int_t mult = trk->GetEntries(); | |
fa67180e | 97 | Int_t nTrk = NTracksInPool(); |
2a910c25 | 98 | |
f0df9076 | 99 | if (!IsReady() && IsReady(nTrk + mult, GetCurrentNEvents() + 1)) |
2a910c25 | 100 | fNTimes++; |
fa67180e | 101 | |
2a910c25 | 102 | // remove 0th element before appending this event |
fa67180e | 103 | Bool_t removeFirstEvent = 0; |
104 | if (nTrk>fTargetTrackDepth) { | |
105 | Int_t nTrksFirstEvent= fNTracksInEvent.front(); | |
106 | Int_t diff = nTrk - nTrksFirstEvent + mult; | |
107 | if (diff>fTargetTrackDepth) | |
108 | removeFirstEvent = 1; | |
109 | } | |
110 | if (removeFirstEvent) { | |
2a910c25 | 111 | TObjArray *fa = fEvents.front(); |
112 | delete fa; | |
113 | fEvents.pop_front(); // remove first track array | |
114 | fNTracksInEvent.pop_front(); // remove first int | |
115 | fEventIndex.pop_front(); | |
2a910c25 | 116 | } |
117 | ||
118 | fNTracksInEvent.push_back(mult); | |
119 | fEvents.push_back(trk); | |
120 | fEventIndex.push_back(iEvent); | |
2a910c25 | 121 | |
122 | if (fNTimes==1) { | |
fa67180e | 123 | fFirstFilled = kTRUE; |
db48ae1a | 124 | if (AliEventPool::fDebug) { |
d94cc49b | 125 | cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex() |
126 | << " ready at event "<< iEvent; | |
127 | PrintInfo(); | |
128 | cout << endl; | |
129 | } | |
2a910c25 | 130 | fNTimes++; // See this message exactly once/pool |
fa67180e | 131 | } else { |
132 | fFirstFilled = kFALSE; | |
2a910c25 | 133 | } |
134 | ||
135 | fWasUpdated = true; | |
136 | ||
137 | if (AliEventPool::fDebug) { | |
138 | cout << " Event " << fEventIndex.back(); | |
139 | cout << " PoolDepth = " << GetCurrentNEvents(); | |
140 | cout << " NTracksInCurrentEvent = " << NTracksInCurrentEvent(); | |
141 | } | |
142 | ||
143 | return fEvents.size(); | |
144 | } | |
145 | ||
146 | TObject* AliEventPool::GetRandomTrack() const | |
147 | { | |
148 | // Get any random track from the pool, sampled with uniform probability. | |
149 | ||
150 | UInt_t ranEvt = gRandom->Integer(fEvents.size()); | |
151 | TObjArray *tca = fEvents.at(ranEvt); | |
152 | UInt_t ranTrk = gRandom->Integer(tca->GetEntries()); | |
153 | TObject *trk = (TObject*)tca->At(ranTrk); | |
154 | return trk; | |
155 | } | |
156 | ||
157 | TObjArray* AliEventPool::GetEvent(Int_t i) const | |
158 | { | |
159 | if (i<0 || i>=(Int_t)fEvents.size()) { | |
160 | cout << "AliEventPool::GetEvent(" | |
161 | << i << "): Invalid index" << endl; | |
162 | return 0x0; | |
163 | } | |
164 | ||
165 | TObjArray *tca = fEvents.at(i); | |
166 | return tca; | |
167 | } | |
168 | ||
169 | TObjArray* AliEventPool::GetRandomEvent() const | |
170 | { | |
171 | UInt_t ranEvt = gRandom->Integer(fEvents.size()); | |
172 | TObjArray *tca = fEvents.at(ranEvt); | |
173 | return tca; | |
174 | } | |
175 | ||
176 | Int_t AliEventPool::NTracksInEvent(Int_t iEvent) const | |
177 | { | |
178 | // Return number of tracks in iEvent, which is the local pool index. | |
179 | ||
180 | Int_t n = -1; | |
181 | Int_t curEvent = fEventIndex.back(); | |
182 | Int_t offset = curEvent - iEvent; | |
183 | Int_t pos = fEventIndex.size() - offset - 1; | |
184 | ||
185 | if (offset==0) | |
186 | n = fNTracksInEvent.back(); | |
187 | else if (offset < 0 || iEvent < 0) { | |
188 | n = 0; | |
189 | } | |
190 | else if (offset > 0 && offset <= (int)fEventIndex.size()) { | |
191 | n = fNTracksInEvent.at(pos); | |
192 | } | |
193 | else | |
194 | cout << "Event info no longer in memory" << endl; | |
195 | return n; | |
196 | } | |
197 | ||
198 | ClassImp(AliEventPoolManager) | |
199 | ||
200 | AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks, | |
6df75196 | 201 | Int_t nMultBins, Double_t *multbins, |
202 | Int_t nZvtxBins, Double_t *zvtxbins) : | |
203 | fDebug(0), fNMultBins(0), fNZvtxBins(0), fNPsiBins(0), fEvPool(0), fTargetTrackDepth(minNTracks) | |
2a910c25 | 204 | { |
205 | // Constructor. | |
6df75196 | 206 | // without Event plane bins |
207 | Int_t nPsiBins = 1; | |
208 | Double_t psibins[2] = {-999.,999.}; | |
2a910c25 | 209 | |
6df75196 | 210 | InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins, nPsiBins, psibins); |
2a910c25 | 211 | cout << "AliEventPoolManager initialized." << endl; |
212 | } | |
213 | ||
6df75196 | 214 | AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks, |
215 | Int_t nMultBins, Double_t *multbins, | |
216 | Int_t nZvtxBins, Double_t *zvtxbins, | |
217 | Int_t nPsiBins, Double_t *psibins) : | |
218 | fDebug(0), fNMultBins(0), fNZvtxBins(0), fNPsiBins(0), fEvPool(0), fTargetTrackDepth(minNTracks) | |
219 | { | |
220 | // Constructor. | |
221 | ||
222 | InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins, nPsiBins, psibins); | |
223 | cout << "AliEventPoolManager initialized." << endl; | |
224 | } | |
225 | ||
226 | ||
227 | ||
2a910c25 | 228 | Int_t AliEventPoolManager::InitEventPools(Int_t depth, |
6df75196 | 229 | Int_t nMultBins, Double_t *multbin, |
230 | Int_t nZvtxBins, Double_t *zvtxbin, | |
231 | Int_t nPsiBins, Double_t *psibin) | |
2a910c25 | 232 | { |
6df75196 | 233 | // Assign AliEventPoolManager members. (with Event plane) |
2a910c25 | 234 | |
235 | fNMultBins = nMultBins; | |
236 | fNZvtxBins = nZvtxBins; | |
6df75196 | 237 | fNPsiBins = nPsiBins; |
238 | ||
2a910c25 | 239 | for (Int_t iM=0; iM<nMultBins; iM++) { |
2a910c25 | 240 | for (Int_t iZ=0; iZ<nZvtxBins; iZ++) { |
6df75196 | 241 | for (Int_t iP=0; iP<nPsiBins; iP++) { |
242 | ||
243 | fEvPool.push_back(new AliEventPool(depth, | |
244 | multbin[iM], multbin[iM+1], | |
245 | zvtxbin[iZ], zvtxbin[iZ+1], | |
246 | psibin[iP], psibin[iP+1] )); | |
247 | } | |
2a910c25 | 248 | } |
2a910c25 | 249 | } |
250 | ||
6df75196 | 251 | |
2a910c25 | 252 | for (Int_t iM=0; iM<nMultBins; iM++) { |
253 | for (Int_t iZ=0; iZ<nZvtxBins; iZ++) { | |
6df75196 | 254 | for (Int_t iP=0; iP<nPsiBins; iP++) { |
255 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->SetMultBinIndex(iM); | |
256 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->SetZvtxBinIndex(iZ); | |
257 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->SetPsiBinIndex(iP); | |
258 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->SetTargetTrackDepth(fTargetTrackDepth); | |
259 | } | |
2a910c25 | 260 | } |
261 | } | |
6df75196 | 262 | |
2a910c25 | 263 | if (0) { |
264 | cout << "fEvPool outer size: " << fEvPool.size() << endl; | |
265 | for (Int_t iM=0; iM<nMultBins; iM++) { | |
266 | for (Int_t iZ=0; iZ<nZvtxBins; iZ++) { | |
6df75196 | 267 | for (Int_t iP=0; iP<nPsiBins; iP++) { |
268 | if(fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)) { | |
269 | cout << "multiplicity bin: " << iM; | |
270 | cout << ", z-vertex bin: " << iZ; | |
271 | cout << ", psi bin: " << iP; | |
272 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->PrintInfo(); | |
273 | } | |
2a910c25 | 274 | } |
275 | } | |
276 | } | |
277 | } | |
278 | ||
279 | return fEvPool.size(); | |
280 | } | |
281 | ||
f0df9076 | 282 | void AliEventPoolManager::SetTargetValues(Int_t trackDepth, Float_t fraction, Int_t events) |
283 | { | |
284 | // sets target values (when a pool becomes ready) in all event pools | |
285 | ||
286 | fTargetTrackDepth = trackDepth; | |
287 | ||
288 | for (Int_t iM=0; iM<fNMultBins; iM++) { | |
289 | for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) { | |
290 | for (Int_t iP=0; iP<fNPsiBins; iP++) { | |
291 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->SetTargetTrackDepth(trackDepth, fraction); | |
292 | fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->SetTargetEvents(events); | |
293 | } | |
294 | } | |
295 | } | |
296 | } | |
6df75196 | 297 | |
298 | AliEventPool *AliEventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx, Int_t iPsi) const | |
2a910c25 | 299 | { |
300 | if (iMult < 0 || iMult >= fNMultBins) | |
301 | return 0x0; | |
302 | if (iZvtx < 0 || iZvtx >= fNZvtxBins) | |
303 | return 0x0; | |
6df75196 | 304 | if (iPsi < 0 || iPsi >= fNPsiBins) |
305 | return 0x0; | |
306 | ||
307 | return fEvPool.at(fNZvtxBins*fNPsiBins*iMult + fNPsiBins*iZvtx + iPsi); | |
2a910c25 | 308 | } |
309 | ||
6df75196 | 310 | AliEventPool *AliEventPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal, Double_t psiVal) const |
2a910c25 | 311 | { |
6df75196 | 312 | return GetEventPool((Double_t)centVal, zVtxVal, psiVal); |
2a910c25 | 313 | } |
314 | ||
6df75196 | 315 | AliEventPool *AliEventPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal, Double_t psiVal) const |
2a910c25 | 316 | { |
317 | // Return appropriate pool for this centrality and z-vertex value. | |
318 | ||
319 | for (Int_t iM=0; iM<fNMultBins; iM++) { | |
320 | for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) { | |
6df75196 | 321 | for (Int_t iP=0; iP<fNPsiBins; iP++) { |
322 | AliEventPool* pool = GetEventPool(iM, iZ, iP); | |
323 | if (pool->EventMatchesBin(centVal, zVtxVal, psiVal)) | |
324 | return pool; | |
325 | } | |
2a910c25 | 326 | } |
327 | } | |
328 | return 0x0; | |
329 | } | |
330 | ||
331 | Int_t AliEventPoolManager::UpdatePools(TObjArray *trk) | |
332 | { | |
333 | // Call UpdatePool for all bins. | |
334 | ||
335 | for (Int_t iM=0; iM<fNMultBins; iM++) { | |
336 | for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) { | |
6df75196 | 337 | for (Int_t iP=0; iP<fNPsiBins; iP++) { |
338 | if (fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->UpdatePool(trk) > -1) | |
339 | break; | |
340 | } | |
2a910c25 | 341 | } |
342 | } | |
343 | return 0; | |
344 | } |