1 #include "AliEventPoolManager.h"
5 void AliEventPool::PrintInfo() const
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;
16 Bool_t AliEventPool::EventMatchesBin(Int_t mult, Double_t zvtx) const
18 return EventMatchesBin((Double_t) mult, zvtx);
21 Bool_t AliEventPool::EventMatchesBin(Double_t mult, Double_t zvtx) const
23 // Lower bin limit included; upper limit excluded.
25 Bool_t multOK = (mult >= fMultMin && mult < fMultMax);
26 Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax);
27 return (multOK && zvtxOK);
30 Int_t AliEventPool::NTracksInPool() const
32 // Number of tracks for this cent, zvtx bin; possibly includes many
36 for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) {
37 ntrk += fNTracksInEvent.at(i);
42 Int_t AliEventPool::SetEventMultRange(Int_t multMin, Int_t multMax)
44 fMultMin = (Double_t)multMin;
45 fMultMax = (Double_t)multMax;
49 Int_t AliEventPool::SetEventMultRange(Double_t multMin, Double_t multMax)
56 Int_t AliEventPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
63 Int_t AliEventPool::GlobalEventIndex(Int_t j) const
65 // Index returned from passing local pool event index.
67 if (j < 0 || j >= (Int_t)fEventIndex.size()) {
68 cout << "ERROR in AliEventPool::GlobalEventIndex(): "
69 << " Invalid index " << j << endl;
72 return fEventIndex.at(j);
75 Int_t AliEventPool::UpdatePool(TObjArray *trk)
77 // A rolling buffer (a double-ended queue) is updated by removing
78 // the oldest event, and appending the newest.
80 static Int_t iEvent = -1;
83 Int_t mult = trk->GetEntries();
84 Int_t nTrk = NTracksInPool();
86 if (nTrk < fTargetTrackDepth && ((nTrk + mult) >= fTargetTrackDepth))
89 // remove 0th element before appending this event
90 Bool_t removeFirstEvent = 0;
91 if (nTrk>fTargetTrackDepth) {
92 Int_t nTrksFirstEvent= fNTracksInEvent.front();
93 Int_t diff = nTrk - nTrksFirstEvent + mult;
94 if (diff>fTargetTrackDepth)
97 if (removeFirstEvent) {
98 TObjArray *fa = fEvents.front();
100 fEvents.pop_front(); // remove first track array
101 fNTracksInEvent.pop_front(); // remove first int
102 fEventIndex.pop_front();
105 fNTracksInEvent.push_back(mult);
106 fEvents.push_back(trk);
107 fEventIndex.push_back(iEvent);
110 fFirstFilled = kTRUE;
111 if (AliEventPool::fDebug) {
112 cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex()
113 << " ready at event "<< iEvent;
117 fNTimes++; // See this message exactly once/pool
119 fFirstFilled = kFALSE;
124 if (AliEventPool::fDebug) {
125 cout << " Event " << fEventIndex.back();
126 cout << " PoolDepth = " << GetCurrentNEvents();
127 cout << " NTracksInCurrentEvent = " << NTracksInCurrentEvent();
130 return fEvents.size();
133 TObject* AliEventPool::GetRandomTrack() const
135 // Get any random track from the pool, sampled with uniform probability.
137 UInt_t ranEvt = gRandom->Integer(fEvents.size());
138 TObjArray *tca = fEvents.at(ranEvt);
139 UInt_t ranTrk = gRandom->Integer(tca->GetEntries());
140 TObject *trk = (TObject*)tca->At(ranTrk);
144 TObjArray* AliEventPool::GetEvent(Int_t i) const
146 if (i<0 || i>=(Int_t)fEvents.size()) {
147 cout << "AliEventPool::GetEvent("
148 << i << "): Invalid index" << endl;
152 TObjArray *tca = fEvents.at(i);
156 TObjArray* AliEventPool::GetRandomEvent() const
158 UInt_t ranEvt = gRandom->Integer(fEvents.size());
159 TObjArray *tca = fEvents.at(ranEvt);
163 Int_t AliEventPool::NTracksInEvent(Int_t iEvent) const
165 // Return number of tracks in iEvent, which is the local pool index.
168 Int_t curEvent = fEventIndex.back();
169 Int_t offset = curEvent - iEvent;
170 Int_t pos = fEventIndex.size() - offset - 1;
173 n = fNTracksInEvent.back();
174 else if (offset < 0 || iEvent < 0) {
177 else if (offset > 0 && offset <= (int)fEventIndex.size()) {
178 n = fNTracksInEvent.at(pos);
181 cout << "Event info no longer in memory" << endl;
185 ClassImp(AliEventPoolManager)
187 AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks,
188 Int_t nMultBins, Double_t *multbins,
189 Int_t nZvtxBins, Double_t *zvtxbins) :
190 fDebug(0), fNMultBins(0), fNZvtxBins(0), fEvPool(0), fTargetTrackDepth(minNTracks)
194 InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins);
195 cout << "AliEventPoolManager initialized." << endl;
198 Int_t AliEventPoolManager::InitEventPools(Int_t depth,
199 Int_t nMultBins, Double_t *multbin,
200 Int_t nZvtxBins, Double_t *zvtxbin)
202 // Assign AliEventPoolManager members.
204 fNMultBins = nMultBins;
205 fNZvtxBins = nZvtxBins;
207 for (Int_t iM=0; iM<nMultBins; iM++) {
208 std::vector<AliEventPool*> evp;
209 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
210 evp.push_back(new AliEventPool(depth,
211 multbin[iM], multbin[iM+1],
212 zvtxbin[iZ], zvtxbin[iZ+1] ));
214 fEvPool.push_back(evp);
217 for (Int_t iM=0; iM<nMultBins; iM++) {
218 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
219 fEvPool.at(iM).at(iZ)->SetMultBinIndex(iM);
220 fEvPool.at(iM).at(iZ)->SetZvtxBinIndex(iZ);
221 fEvPool.at(iM).at(iZ)->SetTargetTrackDepth(fTargetTrackDepth);
226 cout << "fEvPool outer size: " << fEvPool.size() << endl;
227 for (Int_t iM=0; iM<nMultBins; iM++) {
228 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
229 if(fEvPool.at(iM).at(iZ)) {
230 cout << "multiplicity bin: " << iM;
231 cout << ", z-vertex bin: " << iZ;
232 fEvPool.at(iM).at(iZ)->PrintInfo();
238 return fEvPool.size();
241 AliEventPool *AliEventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx) const
243 if (iMult < 0 || iMult >= fNMultBins)
245 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
247 return fEvPool.at(iMult).at(iZvtx);
250 AliEventPool *AliEventPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal) const
252 return GetEventPool((Double_t)centVal, zVtxVal);
255 AliEventPool *AliEventPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal) const
257 // Return appropriate pool for this centrality and z-vertex value.
259 for (Int_t iM=0; iM<fNMultBins; iM++) {
260 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
261 AliEventPool* pool = GetEventPool(iM, iZ);
262 if (pool->EventMatchesBin(centVal, zVtxVal))
269 Int_t AliEventPoolManager::UpdatePools(TObjArray *trk)
271 // Call UpdatePool for all bins.
273 for (Int_t iM=0; iM<fNMultBins; iM++) {
274 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
275 if (fEvPool.at(iM).at(iZ)->UpdatePool(trk) > -1)