1 #include "AliEventPoolManager.h"
7 void AliEventPool::PrintInfo() const
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;
14 cout << Form("%20s: %.1f to %.1f", "Psi range", fPsiMin, fPsiMax) << endl;
19 Bool_t AliEventPool::EventMatchesBin(Int_t mult, Double_t zvtx, Double_t psi) const
21 return EventMatchesBin((Double_t) mult, zvtx, psi);
24 Bool_t AliEventPool::EventMatchesBin(Double_t mult, Double_t zvtx, Double_t psi) const
26 // Lower bin limit included; upper limit excluded.
28 Bool_t multOK = (mult >= fMultMin && mult < fMultMax);
29 Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax);
30 Bool_t psiOK = (psi >= fPsiMin && psi < fPsiMax);
31 return (multOK && zvtxOK && psiOK);
34 Int_t AliEventPool::NTracksInPool() const
36 // Number of tracks for this cent, zvtx bin; possibly includes many
40 for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) {
41 ntrk += fNTracksInEvent.at(i);
46 Int_t AliEventPool::SetEventMultRange(Int_t multMin, Int_t multMax)
48 fMultMin = (Double_t)multMin;
49 fMultMax = (Double_t)multMax;
53 Int_t AliEventPool::SetEventMultRange(Double_t multMin, Double_t multMax)
60 Int_t AliEventPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
67 Int_t AliEventPool::SetEventPsiRange(Double_t psiMin, Double_t psiMax)
74 Int_t AliEventPool::GlobalEventIndex(Int_t j) const
76 // Index returned from passing local pool event index.
78 if (j < 0 || j >= (Int_t)fEventIndex.size()) {
79 cout << "ERROR in AliEventPool::GlobalEventIndex(): "
80 << " Invalid index " << j << endl;
83 return fEventIndex.at(j);
86 Int_t AliEventPool::UpdatePool(TObjArray *trk)
88 // A rolling buffer (a double-ended queue) is updated by removing
89 // the oldest event, and appending the newest.
91 // the ownership of <trk> is delegated to this class
93 static Int_t iEvent = -1;
96 Int_t mult = trk->GetEntries();
97 Int_t nTrk = NTracksInPool();
99 if (!IsReady() && IsReady(nTrk + mult, GetCurrentNEvents() + 1))
102 // remove 0th element before appending this event
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;
110 if (removeFirstEvent) {
111 TObjArray *fa = fEvents.front();
113 fEvents.pop_front(); // remove first track array
114 fNTracksInEvent.pop_front(); // remove first int
115 fEventIndex.pop_front();
118 fNTracksInEvent.push_back(mult);
119 fEvents.push_back(trk);
120 fEventIndex.push_back(iEvent);
123 fFirstFilled = kTRUE;
124 if (AliEventPool::fDebug) {
125 cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex()
126 << " ready at event "<< iEvent;
130 fNTimes++; // See this message exactly once/pool
132 fFirstFilled = kFALSE;
137 if (AliEventPool::fDebug) {
138 cout << " Event " << fEventIndex.back();
139 cout << " PoolDepth = " << GetCurrentNEvents();
140 cout << " NTracksInCurrentEvent = " << NTracksInCurrentEvent();
143 return fEvents.size();
146 TObject* AliEventPool::GetRandomTrack() const
148 // Get any random track from the pool, sampled with uniform probability.
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);
157 TObjArray* AliEventPool::GetEvent(Int_t i) const
159 if (i<0 || i>=(Int_t)fEvents.size()) {
160 cout << "AliEventPool::GetEvent("
161 << i << "): Invalid index" << endl;
165 TObjArray *tca = fEvents.at(i);
169 TObjArray* AliEventPool::GetRandomEvent() const
171 UInt_t ranEvt = gRandom->Integer(fEvents.size());
172 TObjArray *tca = fEvents.at(ranEvt);
176 Int_t AliEventPool::NTracksInEvent(Int_t iEvent) const
178 // Return number of tracks in iEvent, which is the local pool index.
181 Int_t curEvent = fEventIndex.back();
182 Int_t offset = curEvent - iEvent;
183 Int_t pos = fEventIndex.size() - offset - 1;
186 n = fNTracksInEvent.back();
187 else if (offset < 0 || iEvent < 0) {
190 else if (offset > 0 && offset <= (int)fEventIndex.size()) {
191 n = fNTracksInEvent.at(pos);
194 cout << "Event info no longer in memory" << endl;
198 ClassImp(AliEventPoolManager)
200 AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks,
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)
206 // without Event plane bins
208 Double_t psibins[2] = {-999.,999.};
210 InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins, nPsiBins, psibins);
211 cout << "AliEventPoolManager initialized." << endl;
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)
222 InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins, nPsiBins, psibins);
223 cout << "AliEventPoolManager initialized." << endl;
228 Int_t AliEventPoolManager::InitEventPools(Int_t depth,
229 Int_t nMultBins, Double_t *multbin,
230 Int_t nZvtxBins, Double_t *zvtxbin,
231 Int_t nPsiBins, Double_t *psibin)
233 // Assign AliEventPoolManager members. (with Event plane)
235 fNMultBins = nMultBins;
236 fNZvtxBins = nZvtxBins;
237 fNPsiBins = nPsiBins;
239 for (Int_t iM=0; iM<nMultBins; iM++) {
240 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
241 for (Int_t iP=0; iP<nPsiBins; iP++) {
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] ));
252 for (Int_t iM=0; iM<nMultBins; iM++) {
253 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
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);
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++) {
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();
279 return fEvPool.size();
282 void AliEventPoolManager::SetTargetValues(Int_t trackDepth, Float_t fraction, Int_t events)
284 // sets target values (when a pool becomes ready) in all event pools
286 fTargetTrackDepth = trackDepth;
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);
298 AliEventPool *AliEventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx, Int_t iPsi) const
300 if (iMult < 0 || iMult >= fNMultBins)
302 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
304 if (iPsi < 0 || iPsi >= fNPsiBins)
307 return fEvPool.at(fNZvtxBins*fNPsiBins*iMult + fNPsiBins*iZvtx + iPsi);
310 AliEventPool *AliEventPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal, Double_t psiVal) const
312 return GetEventPool((Double_t)centVal, zVtxVal, psiVal);
315 AliEventPool *AliEventPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal, Double_t psiVal) const
317 // Return appropriate pool for this centrality and z-vertex value.
319 for (Int_t iM=0; iM<fNMultBins; iM++) {
320 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
321 for (Int_t iP=0; iP<fNPsiBins; iP++) {
322 AliEventPool* pool = GetEventPool(iM, iZ, iP);
323 if (pool->EventMatchesBin(centVal, zVtxVal, psiVal))
331 Int_t AliEventPoolManager::UpdatePools(TObjArray *trk)
333 // Call UpdatePool for all bins.
335 for (Int_t iM=0; iM<fNMultBins; iM++) {
336 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
337 for (Int_t iP=0; iP<fNPsiBins; iP++) {
338 if (fEvPool.at(fNZvtxBins*fNPsiBins*iM + fNPsiBins*iZ + iP)->UpdatePool(trk) > -1)