]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliEventPoolManager.cxx
-remove printouts
[u/mrichter/AliRoot.git] / ANALYSIS / AliEventPoolManager.cxx
CommitLineData
2a910c25 1#include "AliEventPoolManager.h"
2
c82bb898 3using std::cout;
4using std::endl;
2a910c25 5ClassImp(AliEventPool)
6
7void 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 19Bool_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 24Bool_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
34Int_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
46Int_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
53Int_t AliEventPool::SetEventMultRange(Double_t multMin, Double_t multMax)
54{
55 fMultMin = multMin;
56 fMultMax = multMax;
57 return 0;
58}
59
60Int_t AliEventPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
61{
62 fZvtxMin = zvtxMin;
63 fZvtxMax = zvtxMax;
64 return 0;
65}
66
6df75196 67Int_t AliEventPool::SetEventPsiRange(Double_t psiMin, Double_t psiMax)
68{
69 fPsiMin = psiMin;
70 fPsiMax = psiMax;
71 return 0;
72}
73
2a910c25 74Int_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
86Int_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
fa67180e 99 if (nTrk < fTargetTrackDepth && ((nTrk + mult) >= fTargetTrackDepth))
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
146TObject* 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
157TObjArray* 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
169TObjArray* AliEventPool::GetRandomEvent() const
170{
171 UInt_t ranEvt = gRandom->Integer(fEvents.size());
172 TObjArray *tca = fEvents.at(ranEvt);
173 return tca;
174}
175
176Int_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
198ClassImp(AliEventPoolManager)
199
200AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks,
6df75196 201 Int_t nMultBins, Double_t *multbins,
202 Int_t nZvtxBins, Double_t *zvtxbins) :
203fDebug(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 214AliEventPoolManager::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) :
218fDebug(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 228Int_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
6df75196 282
283AliEventPool *AliEventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx, Int_t iPsi) const
2a910c25 284{
285 if (iMult < 0 || iMult >= fNMultBins)
286 return 0x0;
287 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
288 return 0x0;
6df75196 289 if (iPsi < 0 || iPsi >= fNPsiBins)
290 return 0x0;
291
292 return fEvPool.at(fNZvtxBins*fNPsiBins*iMult + fNPsiBins*iZvtx + iPsi);
2a910c25 293}
294
6df75196 295AliEventPool *AliEventPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal, Double_t psiVal) const
2a910c25 296{
6df75196 297 return GetEventPool((Double_t)centVal, zVtxVal, psiVal);
2a910c25 298}
299
6df75196 300AliEventPool *AliEventPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal, Double_t psiVal) const
2a910c25 301{
302 // Return appropriate pool for this centrality and z-vertex value.
303
304 for (Int_t iM=0; iM<fNMultBins; iM++) {
305 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
6df75196 306 for (Int_t iP=0; iP<fNPsiBins; iP++) {
307 AliEventPool* pool = GetEventPool(iM, iZ, iP);
308 if (pool->EventMatchesBin(centVal, zVtxVal, psiVal))
309 return pool;
310 }
2a910c25 311 }
312 }
313 return 0x0;
314}
315
316Int_t AliEventPoolManager::UpdatePools(TObjArray *trk)
317{
318 // Call UpdatePool for all bins.
319
320 for (Int_t iM=0; iM<fNMultBins; iM++) {
321 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
6df75196 322 for (Int_t iP=0; iP<fNPsiBins; iP++) {
323 if (fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->UpdatePool(trk) > -1)
324 break;
325 }
2a910c25 326 }
327 }
328 return 0;
329}