3 #include "EventPoolManager.h"
5 ClassImp(GenericEventPool)
7 void GenericEventPool::PrintInfo() const
9 cout << " --- --- --- " << endl;
10 cout << Form("%20s: %d", "Pool capacity", fMixDepth) << endl;
11 cout << Form("%20s: %d", "Current depth", Depth()) << endl;
12 cout << Form("%20s: %d to %d", "Mult. range", fMultMin, fMultMax) << endl;
13 cout << Form("%20s: %.1f to %.1f", "Z-vtx range", fZvtxMin, fZvtxMax) << endl;
18 Bool_t GenericEventPool::EventMatchesBin(Int_t mult, Double_t zvtx) const
20 // N.B. Lower bin limit included; upper limit excluded.
22 Bool_t multOK = (mult >= fMultMin && mult < fMultMax);
23 Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax);
24 return (multOK && zvtxOK);
27 Int_t GenericEventPool::TracksInPool() const
30 for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) {
31 ntrk += fNTracksInEvent.at(i);
36 Int_t GenericEventPool::SetEventMultRange(Int_t multMin, Int_t multMax)
43 Int_t GenericEventPool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
50 Int_t GenericEventPool::UpdatePool(Int_t iEvent, const MyHeader *ev, TObjArray *trk)
52 // Initialize at any chosen starting event
54 Int_t mult = trk->GetEntries();
55 Double_t zvtx = ev->fVz;
57 if (!EventMatchesBin(mult, zvtx)) {
62 // Should see evsize = trsize (= fMixDepth once full).
63 Int_t evsize = fEvents.size();
64 Int_t ntsize = fNTracksInEvent.size();
67 cout << "WARNING: Event array and track counter array sizes do not match."
68 << " evsize = " << evsize
69 << " ntsize = " << ntsize
72 Bool_t firstReachedCapacity = false;
73 if (evsize == fMixDepth - 1)
74 firstReachedCapacity = true;
76 // remove 0th element before appending this event
77 if (evsize >= fMixDepth) {
78 TObjArray *fa = fEvents.front();
81 fEvents.pop_front(); // remove first track array
82 fNTracksInEvent.pop_front(); // remove first int
83 fEventIndex.pop_front();
86 fNTracksInEvent.push_back(mult);
87 fEvents.push_back(trk);
88 fEventIndex.push_back(iEvent);
90 if (firstReachedCapacity) {
91 cout << "Pool " << MultBinIndex() << ", " << ZvtxBinIndex()
92 << " ready at event "<< iEvent;
99 if (fDebug && print) {
100 cout << " Event " << fEventIndex.back();
101 cout << " PoolDepth = " << Depth();
102 cout << " NTracks = " << NTracksInCurrentEvent();
103 cout << " TracksInPool = " << TracksInPool();
106 return fEvents.size();
109 TObject* GenericEventPool::GetRandomTrack() const
111 UInt_t ranEvt = gRandom->Integer(fEvents.size());
112 TObjArray *tca = fEvents.at(ranEvt);
113 UInt_t ranTrk = gRandom->Integer(tca->GetEntries());
114 TObject *trk = (TObject*)tca->At(ranTrk);
118 TObjArray* GenericEventPool::GetRandomEvent() const
120 UInt_t ranEvt = gRandom->Integer(fEvents.size());
121 TObjArray *tca = fEvents.at(ranEvt);
125 Int_t GenericEventPool::NTracksInEvent(Int_t iEvent) const
128 Int_t curEvent = fEventIndex.back();
129 Int_t offset = curEvent - iEvent;
130 Int_t pos = fEventIndex.size() - offset - 1;
133 n = fNTracksInEvent.back();
134 else if (offset < 0 || iEvent < 0) {
137 else if (offset > 0 && offset <= (int)fEventIndex.size()) {
138 n = fNTracksInEvent.at(pos);
141 cout << "Event info no longer in memory" << endl;
145 ClassImp(EventPoolManager)
147 Int_t EventPoolManager::InitEventPools(Int_t depth,
148 Int_t nMultBins, Int_t *multbin,
149 Int_t nZvtxBins, Double_t *zvtxbin)
151 // First assign EventPoolManager members
152 fNMultBins = nMultBins;
153 fNZvtxBins = nZvtxBins;
155 for (Int_t iM=0; iM<nMultBins; iM++) {
156 std::vector<GenericEventPool*> evp;
157 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
158 evp.push_back(new GenericEventPool(depth,
159 multbin[iM], multbin[iM+1],
160 zvtxbin[iZ], zvtxbin[iZ+1] ));
162 fEvPool.push_back(evp);
165 for (Int_t iM=0; iM<nMultBins; iM++) {
166 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
167 fEvPool.at(iM).at(iZ)->SetMultBinIndex(iM);
168 fEvPool.at(iM).at(iZ)->SetZvtxBinIndex(iZ);
173 cout << "fEvPool outer size: " << fEvPool.size() << endl;
174 for (Int_t iM=0; iM<nMultBins; iM++) {
175 for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
176 if(fEvPool.at(iM).at(iZ)) {
177 cout << "multiplicity bin: " << iM;
178 cout << ", z-vertex bin: " << iZ;
179 fEvPool.at(iM).at(iZ)->PrintInfo();
185 return fEvPool.size();
188 GenericEventPool *EventPoolManager::GetEventPool(Int_t iMult, Int_t iZvtx) const
190 if (iMult < 0 || iMult >= fNMultBins)
192 if (iZvtx < 0 || iZvtx >= fNZvtxBins)
194 return fEvPool.at(iMult).at(iZvtx);
197 Int_t EventPoolManager::UpdatePools(Int_t iEvent, const MyHeader* ev, TObjArray *trk)
199 for (Int_t iM=0; iM<fNMultBins; iM++) {
200 for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
201 if (fEvPool.at(iM).at(iZ)->UpdatePool(iEvent, ev, trk)>-1)