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;
18 Bool_t AliEventPool::EventMatchesBin(Int_t mult, Double_t zvtx) const
20 return EventMatchesBin((Double_t) mult, zvtx);
23 Bool_t AliEventPool::EventMatchesBin(Double_t mult, Double_t zvtx) const
25 // Lower bin limit included; upper limit excluded.
27 Bool_t multOK = (mult >= fMultMin && mult < fMultMax);
28 Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax);
29 return (multOK && zvtxOK);
32 Int_t AliEventPool::NTracksInPool() const
34 // Number of tracks for this cent, zvtx bin; possibly includes many
38 for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) {
39 ntrk += fNTracksInEvent.at(i);
44 Int_t AliEventPool::SetEventMultRange(Int_t multMin, Int_t multMax)
46 fMultMin = (Double_t)multMin;
47 fMultMax = (Double_t)multMax;
51 Int_t AliEventPool::SetEventMultRange(Double_t multMin, Double_t multMax)
58 Int_t AliEventPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
65 Int_t AliEventPool::GlobalEventIndex(Int_t j) const
67 // Index returned from passing local pool event index.
69 if (j < 0 || j >= (Int_t)fEventIndex.size()) {
70 cout << "ERROR in AliEventPool::GlobalEventIndex(): "
71 << " Invalid index " << j << endl;
74 return fEventIndex.at(j);
77 Int_t AliEventPool::UpdatePool(TObjArray *trk)
79 // A rolling buffer (a double-ended queue) is updated by removing
80 // the oldest event, and appending the newest.
82 // the ownership of <trk> is delegated to this class
84 static Int_t iEvent = -1;
87 Int_t mult = trk->GetEntries();
88 Int_t nTrk = NTracksInPool();
90 if (nTrk < fTargetTrackDepth && ((nTrk + mult) >= fTargetTrackDepth))
93 // remove 0th element before appending this event
94 Bool_t removeFirstEvent = 0;
95 if (nTrk>fTargetTrackDepth) {
96 Int_t nTrksFirstEvent= fNTracksInEvent.front();
97 Int_t diff = nTrk - nTrksFirstEvent + mult;
98 if (diff>fTargetTrackDepth)
101 if (removeFirstEvent) {
102 TObjArray *fa = fEvents.front();
104 fEvents.pop_front(); // remove first track array
105 fNTracksInEvent.pop_front(); // remove first int
106 fEventIndex.pop_front();
109 fNTracksInEvent.push_back(mult);
110 fEvents.push_back(trk);
111 fEventIndex.push_back(iEvent);
114 fFirstFilled = kTRUE;
115 if (AliEventPool::fDebug) {
116 cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex()
117 << " ready at event "<< iEvent;
121 fNTimes++; // See this message exactly once/pool
123 fFirstFilled = kFALSE;
128 if (AliEventPool::fDebug) {
129 cout << " Event " << fEventIndex.back();
130 cout << " PoolDepth = " << GetCurrentNEvents();
131 cout << " NTracksInCurrentEvent = " << NTracksInCurrentEvent();
134 return fEvents.size();
137 TObject* AliEventPool::GetRandomTrack() const
139 // Get any random track from the pool, sampled with uniform probability.
141 UInt_t ranEvt = gRandom->Integer(fEvents.size());
142 TObjArray *tca = fEvents.at(ranEvt);
143 UInt_t ranTrk = gRandom->Integer(tca->GetEntries());
144 TObject *trk = (TObject*)tca->At(ranTrk);
148 TObjArray* AliEventPool::GetEvent(Int_t i) const
150 if (i<0 || i>=(Int_t)fEvents.size()) {
151 cout << "AliEventPool::GetEvent("
152 << i << "): Invalid index" << endl;
156 TObjArray *tca = fEvents.at(i);
160 TObjArray* AliEventPool::GetRandomEvent() const
162 UInt_t ranEvt = gRandom->Integer(fEvents.size());
163 TObjArray *tca = fEvents.at(ranEvt);
167 Int_t AliEventPool::NTracksInEvent(Int_t iEvent) const
169 // Return number of tracks in iEvent, which is the local pool index.
172 Int_t curEvent = fEventIndex.back();
173 Int_t offset = curEvent - iEvent;
174 Int_t pos = fEventIndex.size() - offset - 1;
177 n = fNTracksInEvent.back();
178 else if (offset < 0 || iEvent < 0) {
181 else if (offset > 0 && offset <= (int)fEventIndex.size()) {
182 n = fNTracksInEvent.at(pos);
185 cout << "Event info no longer in memory" << endl;
189 ClassImp(AliEventPoolManager)
191 AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks,
192 Int_t nMultBins, Double_t *multbins,
193 Int_t nZvtxBins, Double_t *zvtxbins) :
194 fDebug(0), fNMultBins(0), fNZvtxBins(0), fEvPool(0), fTargetTrackDepth(minNTracks)
198 InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins);
199 cout << "AliEventPoolManager initialized." << endl;
202 Int_t AliEventPoolManager::InitEventPools(Int_t depth,
203 Int_t nMultBins, Double_t *multbin,
204 Int_t nZvtxBins, Double_t *zvtxbin)
206 // Assign AliEventPoolManager members.
208 fNMultBins = nMultBins;
209 fNZvtxBins = nZvtxBins;
211 for (Int_t iM=0; iM<nMultBins; iM++) {
212 std::vector<AliEventPool*> evp;
213 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
214 evp.push_back(new AliEventPool(depth,
215 multbin[iM], multbin[iM+1],
216 zvtxbin[iZ], zvtxbin[iZ+1] ));
218 fEvPool.push_back(evp);
221 for (Int_t iM=0; iM<nMultBins; iM++) {
222 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
223 fEvPool.at(iM).at(iZ)->SetMultBinIndex(iM);
224 fEvPool.at(iM).at(iZ)->SetZvtxBinIndex(iZ);
225 fEvPool.at(iM).at(iZ)->SetTargetTrackDepth(fTargetTrackDepth);
230 cout << "fEvPool outer size: " << fEvPool.size() << endl;
231 for (Int_t iM=0; iM<nMultBins; iM++) {
232 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
233 if(fEvPool.at(iM).at(iZ)) {
234 cout << "multiplicity bin: " << iM;
235 cout << ", z-vertex bin: " << iZ;
236 fEvPool.at(iM).at(iZ)->PrintInfo();
242 return fEvPool.size();
245 AliEventPool *AliEventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx) const
247 if (iMult < 0 || iMult >= fNMultBins)
249 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
251 return fEvPool.at(iMult).at(iZvtx);
254 AliEventPool *AliEventPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal) const
256 return GetEventPool((Double_t)centVal, zVtxVal);
259 AliEventPool *AliEventPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal) const
261 // Return appropriate pool for this centrality and z-vertex value.
263 for (Int_t iM=0; iM<fNMultBins; iM++) {
264 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
265 AliEventPool* pool = GetEventPool(iM, iZ);
266 if (pool->EventMatchesBin(centVal, zVtxVal))
273 Int_t AliEventPoolManager::UpdatePools(TObjArray *trk)
275 // Call UpdatePool for all bins.
277 for (Int_t iM=0; iM<fNMultBins; iM++) {
278 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
279 if (fEvPool.at(iM).at(iZ)->UpdatePool(trk) > -1)