]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGCF/Correlations/DPhi/FourierDecomposition/AliPool.cxx
lightweight event mixing classes (AliEvtPool and AliEvtPoolManager)
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / FourierDecomposition / AliPool.cxx
CommitLineData
7ae701ab 1#include "AliPool.h"
2
3// ===================================================================
4// AliEvtPool
5// ===================================================================
6
7ClassImp(AliEvtPool)
8
9AliEvtPool::~AliEvtPool()
10{
11 while (!fEvents.empty()) {
12 MiniEvent* fe= fEvents.front();
13 delete fe;
14 fe = 0;
15 fEvents.pop_front();
16 }
17}
18
19void
20AliEvtPool::PrintInfo() const
21{
22 cout << Form("%20s: %d events", "Pool capacity", fMixDepth) << endl;
23 cout << Form("%20s: %d events, %d tracks", "Current size",
24 GetCurrentNEvents(), NTracksInPool()) << endl;
25 cout << Form("%20s: %.1f to %.1f", "Sub-event mult.", fMultMin, fMultMax) << endl;
26 cout << Form("%20s: %.1f to %.1f", "Z-vtx range", fZvtxMin, fZvtxMax) << endl;
27
28 return;
29}
30
31Bool_t
32AliEvtPool::EventMatchesBin(Int_t mult, Double_t zvtx) const
33{
34 return EventMatchesBin((Double_t) mult, zvtx);
35}
36
37Bool_t
38AliEvtPool::EventMatchesBin(Double_t mult, Double_t zvtx) const
39{
40 // Lower bin limit included; upper limit excluded.
41
42 Bool_t multOK = (mult >= fMultMin && mult < fMultMax);
43 Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax);
44 return (multOK && zvtxOK);
45}
46
47Int_t
48AliEvtPool::NTracksInPool() const
49{
50 // Number of tracks for this cent, zvtx bin; possibly includes many events.
51
52 Int_t ntrk=0;
53 for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) {
54 ntrk += fNTracksInEvent.at(i);
55 }
56 return ntrk;
57}
58
59Int_t
60AliEvtPool::SetEventMultRange(Int_t multMin, Int_t multMax)
61{
62 fMultMin = (Double_t)multMin;
63 fMultMax = (Double_t)multMax;
64 return 0;
65}
66
67Int_t
68AliEvtPool::SetEventMultRange(Double_t multMin, Double_t multMax)
69{
70 fMultMin = multMin;
71 fMultMax = multMax;
72 return 0;
73}
74
75Int_t
76AliEvtPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
77{
78 fZvtxMin = zvtxMin;
79 fZvtxMax = zvtxMax;
80 return 0;
81}
82
83Int_t
84AliEvtPool::GlobalEventIndex(Int_t j) const
85{
86 // Index returned from passing local pool event index.
87
88 if (j < 0 || j >= (Int_t)fEventIndex.size()) {
89 cout << "ERROR in AliEvtPool::GlobalEventIndex(): "
90 << " Invalid index " << j << endl;
91 return -99;
92 }
93 return fEventIndex.at(j);
94}
95
96Int_t
97AliEvtPool::UpdatePool(MiniEvent* miniEvt)
98{
99 // A rolling buffer (a double-ended queue) is updated by removing
100 // the oldest event, and appending the newest.
101
102 static Int_t iEvent = -1;
103 iEvent++;
104
105 Int_t mult = miniEvt->size(); // # tracks in this (mini) event
106 Int_t nTrk = NTracksInPool();
107
108 if (nTrk < fTargetTrackDepth && ((nTrk + mult) >= fTargetTrackDepth))
109 fNTimes++;
110
111 // remove 0th element before appending this event
112 Bool_t removeFirstEvent = 0;
113 if (nTrk>fTargetTrackDepth) {
114 Int_t nTrksFirstEvent= fNTracksInEvent.front();
115 Int_t diff = nTrk - nTrksFirstEvent + mult;
116 if (diff>fTargetTrackDepth)
117 removeFirstEvent = 1;
118 }
119 if (removeFirstEvent) {
120 MiniEvent* oldestEvent = fEvents.front();
121 delete oldestEvent;
122 fEvents.pop_front(); // remove first track array
123 fNTracksInEvent.pop_front(); // remove first int
124 fEventIndex.pop_front();
125 }
126
127 fNTracksInEvent.push_back(mult);
128 fEvents.push_back(miniEvt);
129 fEventIndex.push_back(iEvent);
130
131 if (fNTimes==1) {
132 fFirstFilled = kTRUE;
133 if (AliEvtPool::fDebug) {
134 cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex()
135 << " ready at event "<< iEvent;
136 PrintInfo();
137 cout << endl;
138 }
139 fNTimes++; // See this message exactly once/pool
140 } else {
141 fFirstFilled = kFALSE;
142 }
143
144 fWasUpdated = true;
145
146 if (AliEvtPool::fDebug) {
147 cout << " Event " << fEventIndex.back();
148 cout << " PoolDepth = " << GetCurrentNEvents();
149 cout << " NTracksInCurrentEvent = " << " " << mult << endl;
150 }
151
152 return fEvents.size();
153}
154
155MiniEvent*
156AliEvtPool::GetEvent(Int_t i) const
157{
158 if (i<0 || i>=(Int_t)fEvents.size()) {
159 cout << "AliEvtPool::GetEvent("
160 << i << "): Invalid index" << endl;
161 return 0x0;
162 }
163
164 MiniEvent* ev = fEvents.at(i);
165 return ev;
166}
167
168Int_t
169AliEvtPool::NTracksInEvent(Int_t iEvent) const
170{
171 // Return number of tracks in iEvent, which is the local pool index.
172
173 Int_t n = -1;
174 Int_t curEvent = fEventIndex.back();
175 Int_t offset = curEvent - iEvent;
176 Int_t pos = fEventIndex.size() - offset - 1;
177
178 if (offset==0)
179 n = fNTracksInEvent.back();
180 else if (offset < 0 || iEvent < 0) {
181 n = 0;
182 }
183 else if (offset > 0 && offset <= (int)fEventIndex.size()) {
184 n = fNTracksInEvent.at(pos);
185 }
186 else
187 cout << "Event info no longer in memory" << endl;
188 return n;
189}
190
191// ===================================================================
192// AliEvtPoolManager
193// ===================================================================
194
195
196ClassImp(AliEvtPoolManager)
197
198AliEvtPoolManager::AliEvtPoolManager(Int_t depth, Int_t minNTracks,
199 Int_t nMultBins, Double_t *multbins,
200 Int_t nZvtxBins, Double_t *zvtxbins)
201: fDebug(0), fNMultBins(0), fNZvtxBins(0), fEvPool(0), fTargetTrackDepth(minNTracks)
202{
203 // Constructor.
204
205 InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins);
206 cout << "AliEvtPoolManager initialized." << endl;
207}
208
209AliEvtPoolManager::~AliEvtPoolManager()
210{
211 for (Int_t iM=0; iM<fNMultBins; iM++) {
212 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
213 AliEvtPool* pool = fEvPool.at(iM).at(iZ);
214 delete pool;
215 }
216 }
217}
218
219Int_t AliEvtPoolManager::InitEventPools(Int_t depth,
220 Int_t nMultBins, Double_t *multbin,
221 Int_t nZvtxBins, Double_t *zvtxbin)
222{
223 // Assign AliEvtPoolManager members.
224
225 fNMultBins = nMultBins;
226 fNZvtxBins = nZvtxBins;
227
228 for (Int_t iM=0; iM<fNMultBins; iM++) {
229 std::vector<AliEvtPool*> evp;
230 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
231 evp.push_back(new AliEvtPool(depth,
232 multbin[iM], multbin[iM+1],
233 zvtxbin[iZ], zvtxbin[iZ+1] ));
234 }
235 fEvPool.push_back(evp);
236 }
237
238 for (Int_t iM=0; iM<nMultBins; iM++) {
239 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
240 fEvPool.at(iM).at(iZ)->SetMultBinIndex(iM);
241 fEvPool.at(iM).at(iZ)->SetZvtxBinIndex(iZ);
242 fEvPool.at(iM).at(iZ)->SetTargetTrackDepth(fTargetTrackDepth);
243 fEvPool.at(iM).at(iZ)->SetDebug(fDebug);
244 }
245 }
246
247 if (fDebug) {
248 cout << "fEvPool outer size: " << fEvPool.size() << endl;
249 for (Int_t iM=0; iM<nMultBins; iM++) {
250 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
251 if(fEvPool.at(iM).at(iZ)) {
252 cout << "multiplicity bin: " << iM;
253 cout << ", z-vertex bin: " << iZ;
254 fEvPool.at(iM).at(iZ)->PrintInfo();
255 }
256 }
257 }
258 }
259
260 return fEvPool.size();
261}
262
263AliEvtPool*
264AliEvtPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx) const
265{
266 if (iMult < 0 || iMult >= fNMultBins)
267 return 0x0;
268 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
269 return 0x0;
270 return fEvPool.at(iMult).at(iZvtx);
271}
272
273AliEvtPool*
274AliEvtPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal) const
275{
276 return GetEventPool((Double_t)centVal, zVtxVal);
277}
278
279AliEvtPool*
280AliEvtPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal) const
281{
282 // Return appropriate pool for this centrality and z-vertex value.
283
284 for (Int_t iM=0; iM<fNMultBins; iM++) {
285 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
286 AliEvtPool* pool = GetEventPool(iM, iZ);
287 if (pool->EventMatchesBin(centVal, zVtxVal))
288 return pool;
289 }
290 }
291 return 0x0;
292}
293
294Int_t
295AliEvtPoolManager::UpdatePools(MiniEvent* miniEvt)
296{
297 // Call UpdatePool for all bins.
298
299 for (Int_t iM=0; iM<fNMultBins; iM++) {
300 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
301 if (fEvPool.at(iM).at(iZ)->UpdatePool(miniEvt) > -1)
302 break;
303 }
304 }
305 return 0;
306}