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 nTrkA = NTracksInPool();
88 if (nTrkA < fTargetTrackDepth && ((nTrkA + mult) >= fTargetTrackDepth))
91 // remove 0th element before appending this event
92 if (NTracksInPool() >= fTargetTrackDepth) {
93 TObjArray *fa = fEvents.front();
95 fEvents.pop_front(); // remove first track array
96 fNTracksInEvent.pop_front(); // remove first int
97 fEventIndex.pop_front();
98 nTrkB = NTracksInPool();
101 fNTracksInEvent.push_back(mult);
102 fEvents.push_back(trk);
103 fEventIndex.push_back(iEvent);
104 nTrkC = NTracksInPool();
107 if (AliEventPool::fDebug) {
108 cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex()
109 << " ready at event "<< iEvent;
113 fNTimes++; // See this message exactly once/pool
118 if (AliEventPool::fDebug) {
119 cout << " Event " << fEventIndex.back();
120 cout << " PoolDepth = " << GetCurrentNEvents();
121 cout << " NTracksInCurrentEvent = " << NTracksInCurrentEvent();
124 return fEvents.size();
127 TObject* AliEventPool::GetRandomTrack() const
129 // Get any random track from the pool, sampled with uniform probability.
131 UInt_t ranEvt = gRandom->Integer(fEvents.size());
132 TObjArray *tca = fEvents.at(ranEvt);
133 UInt_t ranTrk = gRandom->Integer(tca->GetEntries());
134 TObject *trk = (TObject*)tca->At(ranTrk);
138 TObjArray* AliEventPool::GetEvent(Int_t i) const
140 if (i<0 || i>=(Int_t)fEvents.size()) {
141 cout << "AliEventPool::GetEvent("
142 << i << "): Invalid index" << endl;
146 TObjArray *tca = fEvents.at(i);
150 TObjArray* AliEventPool::GetRandomEvent() const
152 UInt_t ranEvt = gRandom->Integer(fEvents.size());
153 TObjArray *tca = fEvents.at(ranEvt);
157 Int_t AliEventPool::NTracksInEvent(Int_t iEvent) const
159 // Return number of tracks in iEvent, which is the local pool index.
162 Int_t curEvent = fEventIndex.back();
163 Int_t offset = curEvent - iEvent;
164 Int_t pos = fEventIndex.size() - offset - 1;
167 n = fNTracksInEvent.back();
168 else if (offset < 0 || iEvent < 0) {
171 else if (offset > 0 && offset <= (int)fEventIndex.size()) {
172 n = fNTracksInEvent.at(pos);
175 cout << "Event info no longer in memory" << endl;
179 ClassImp(AliEventPoolManager)
181 AliEventPoolManager::AliEventPoolManager(Int_t depth, Int_t minNTracks,
182 Int_t nMultBins, Double_t *multbins,
183 Int_t nZvtxBins, Double_t *zvtxbins) :
184 fDebug(0), fNMultBins(0), fNZvtxBins(0), fEvPool(0), fTargetTrackDepth(minNTracks)
188 InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins);
189 cout << "AliEventPoolManager initialized." << endl;
192 Int_t AliEventPoolManager::InitEventPools(Int_t depth,
193 Int_t nMultBins, Double_t *multbin,
194 Int_t nZvtxBins, Double_t *zvtxbin)
196 // Assign AliEventPoolManager members.
198 fNMultBins = nMultBins;
199 fNZvtxBins = nZvtxBins;
201 for (Int_t iM=0; iM<nMultBins; iM++) {
202 std::vector<AliEventPool*> evp;
203 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
204 evp.push_back(new AliEventPool(depth,
205 multbin[iM], multbin[iM+1],
206 zvtxbin[iZ], zvtxbin[iZ+1] ));
208 fEvPool.push_back(evp);
211 for (Int_t iM=0; iM<nMultBins; iM++) {
212 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
213 fEvPool.at(iM).at(iZ)->SetMultBinIndex(iM);
214 fEvPool.at(iM).at(iZ)->SetZvtxBinIndex(iZ);
215 fEvPool.at(iM).at(iZ)->SetTargetTrackDepth(fTargetTrackDepth);
220 cout << "fEvPool outer size: " << fEvPool.size() << endl;
221 for (Int_t iM=0; iM<nMultBins; iM++) {
222 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
223 if(fEvPool.at(iM).at(iZ)) {
224 cout << "multiplicity bin: " << iM;
225 cout << ", z-vertex bin: " << iZ;
226 fEvPool.at(iM).at(iZ)->PrintInfo();
232 return fEvPool.size();
235 AliEventPool *AliEventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx) const
237 if (iMult < 0 || iMult >= fNMultBins)
239 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
241 return fEvPool.at(iMult).at(iZvtx);
244 AliEventPool *AliEventPoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal) const
246 return GetEventPool((Double_t)centVal, zVtxVal);
249 AliEventPool *AliEventPoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal) const
251 // Return appropriate pool for this centrality and z-vertex value.
253 for (Int_t iM=0; iM<fNMultBins; iM++) {
254 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
255 AliEventPool* pool = GetEventPool(iM, iZ);
256 if (pool->EventMatchesBin(centVal, zVtxVal))
263 Int_t AliEventPoolManager::UpdatePools(TObjArray *trk)
265 // Call UpdatePool for all bins.
267 for (Int_t iM=0; iM<fNMultBins; iM++) {
268 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
269 if (fEvPool.at(iM).at(iZ)->UpdatePool(trk) > -1)