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