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