]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/CorrelationsDPhi/FourierDecomposition/AliPool.cxx.txt
Moving fourier decomposition analysis code
[u/mrichter/AliRoot.git] / PWG4 / CorrelationsDPhi / FourierDecomposition / AliPool.cxx.txt
1 #include "AliPool.h.txt"
2
3 // ===================================================================
4 //                             KiddiePool
5 // ===================================================================
6
7 ClassImp(KiddiePool)
8
9 KiddiePool::~KiddiePool()
10 {
11   while (!fEvents.empty()) {
12     MiniEvent* fe= fEvents.front();
13     delete fe;
14     fe = 0;
15     fEvents.pop_front();
16   }
17 }
18
19 void 
20 KiddiePool::PrintInfo() const
21 {
22   cout << Form("%20s: %d events", "Pool capacity", fMixDepth) << endl;
23   cout << Form("%20s: %d events, %d tracks", "Current size", 
24                GetCurrentNEvents(), NTracksInPool()) << endl;
25   cout << Form("%20s: %.1f to %.1f", "Sub-event mult.", fMultMin, fMultMax) << endl;
26   cout << Form("%20s: %.1f to %.1f", "Z-vtx range", fZvtxMin, fZvtxMax) << endl;
27
28   return;
29 }
30
31 Bool_t 
32 KiddiePool::EventMatchesBin(Int_t mult, Double_t zvtx) const
33 {
34   return EventMatchesBin((Double_t) mult, zvtx);
35 }
36
37 Bool_t 
38 KiddiePool::EventMatchesBin(Double_t mult, Double_t zvtx) const
39 {
40   // Lower bin limit included; upper limit excluded.
41
42   Bool_t multOK = (mult >= fMultMin && mult < fMultMax);
43   Bool_t zvtxOK = (zvtx >= fZvtxMin && zvtx < fZvtxMax);
44   return (multOK && zvtxOK);
45 }
46
47 Int_t 
48 KiddiePool::NTracksInPool() const
49 {
50   // Number of tracks for this cent, zvtx bin; possibly includes many events.
51
52   Int_t ntrk=0;
53   for (Int_t i=0; i<(Int_t)fEvents.size(); ++i) {
54     ntrk += fNTracksInEvent.at(i);
55   }
56   return ntrk;
57 }
58
59 Int_t
60 KiddiePool::SetEventMultRange(Int_t multMin, Int_t multMax)
61 {
62   fMultMin = (Double_t)multMin;
63   fMultMax = (Double_t)multMax;
64   return 0;
65 }
66
67 Int_t
68 KiddiePool::SetEventMultRange(Double_t multMin, Double_t multMax)
69 {
70   fMultMin = multMin;
71   fMultMax = multMax;
72   return 0;
73 }
74
75 Int_t
76 KiddiePool::SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax)
77 {
78   fZvtxMin = zvtxMin;
79   fZvtxMax = zvtxMax;
80   return 0;
81 }
82
83 Int_t
84 KiddiePool::GlobalEventIndex(Int_t j) const
85 {
86   // Index returned from passing local pool event index.
87
88   if (j < 0 || j >= (Int_t)fEventIndex.size()) {
89     cout << "ERROR in KiddiePool::GlobalEventIndex(): "
90          << " Invalid index " << j << endl;
91     return -99;
92   }
93   return fEventIndex.at(j);
94 }
95
96 Int_t
97 KiddiePool::UpdatePool(MiniEvent* miniEvt)
98 {
99   // A rolling buffer (a double-ended queue) is updated by removing
100   // the oldest event, and appending the newest.
101
102   static Int_t iEvent = -1; 
103   iEvent++;
104
105   Int_t mult = miniEvt->size(); // # tracks in this (mini) event
106   Int_t nTrk = NTracksInPool();
107
108   if (nTrk < fTargetTrackDepth && ((nTrk + mult) >= fTargetTrackDepth)) 
109     fNTimes++;
110
111   // remove 0th element before appending this event
112   Bool_t removeFirstEvent = 0;
113   if (nTrk>fTargetTrackDepth) {
114     Int_t nTrksFirstEvent= fNTracksInEvent.front();
115     Int_t diff = nTrk - nTrksFirstEvent + mult;
116     if (diff>fTargetTrackDepth)
117       removeFirstEvent = 1;
118   }
119   if (removeFirstEvent) {
120     MiniEvent* oldestEvent = fEvents.front();
121     delete oldestEvent;
122     fEvents.pop_front();         // remove first track array 
123     fNTracksInEvent.pop_front(); // remove first int
124     fEventIndex.pop_front();
125   }
126
127   fNTracksInEvent.push_back(mult);
128   fEvents.push_back(miniEvt);
129   fEventIndex.push_back(iEvent);
130
131   if (fNTimes==1) {
132     fFirstFilled = kTRUE;
133     if (KiddiePool::fDebug) {
134       cout << "\nPool " << MultBinIndex() << ", " << ZvtxBinIndex() 
135            << " ready at event "<< iEvent;
136       PrintInfo();
137       cout << endl;
138     }
139     fNTimes++; // See this message exactly once/pool
140   } else {
141     fFirstFilled = kFALSE;
142   }
143
144   fWasUpdated = true;
145
146   if (KiddiePool::fDebug) {
147     cout << " Event " << fEventIndex.back();
148     cout << " PoolDepth = " << GetCurrentNEvents(); 
149     cout << " NTracksInCurrentEvent = " << " " << mult << endl;
150   }
151
152   return fEvents.size();
153 }
154
155 MiniEvent* 
156 KiddiePool::GetEvent(Int_t i) const
157 {
158   if (i<0 || i>=(Int_t)fEvents.size()) {
159     cout << "KiddiePool::GetEvent(" 
160          << i << "): Invalid index" << endl;
161     return 0x0;
162   }
163
164   MiniEvent* ev = fEvents.at(i);
165   return ev;
166 }
167
168 Int_t
169 KiddiePool::NTracksInEvent(Int_t iEvent) const
170 {
171   // Return number of tracks in iEvent, which is the local pool index.
172
173   Int_t n = -1;
174   Int_t curEvent = fEventIndex.back();
175   Int_t offset = curEvent - iEvent;
176   Int_t pos = fEventIndex.size() - offset - 1;
177
178   if (offset==0)
179     n = fNTracksInEvent.back();
180   else if (offset < 0 || iEvent < 0) {
181     n = 0;
182   }
183   else if (offset > 0 && offset <= (int)fEventIndex.size()) {
184     n = fNTracksInEvent.at(pos);
185   }
186   else
187     cout << "Event info no longer in memory" << endl;
188   return n;
189 }
190
191 // ===================================================================
192 //                          KiddiePoolManager
193 // ===================================================================
194
195
196 ClassImp(KiddiePoolManager)
197
198 KiddiePoolManager::KiddiePoolManager(Int_t depth,     Int_t minNTracks,
199                                      Int_t nMultBins, Double_t *multbins,
200                                      Int_t nZvtxBins, Double_t *zvtxbins) 
201 : fDebug(0), fNMultBins(0), fNZvtxBins(0), fEvPool(0), fTargetTrackDepth(minNTracks) 
202 {
203   // Constructor.
204
205   InitEventPools(depth, nMultBins, multbins, nZvtxBins, zvtxbins);
206   cout << "KiddiePoolManager initialized." << endl;
207 }
208
209 KiddiePoolManager::~KiddiePoolManager()
210 {
211   for (Int_t iM=0; iM<fNMultBins; iM++) {
212     for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
213       KiddiePool* pool = fEvPool.at(iM).at(iZ);
214       delete pool;
215     }
216   }
217 }
218
219 Int_t KiddiePoolManager::InitEventPools(Int_t depth, 
220                                        Int_t nMultBins, Double_t *multbin, 
221                                        Int_t nZvtxBins, Double_t *zvtxbin)
222 {
223   // Assign KiddiePoolManager members.
224
225   fNMultBins = nMultBins;
226   fNZvtxBins = nZvtxBins;
227
228   for (Int_t iM=0; iM<fNMultBins; iM++) {
229     std::vector<KiddiePool*> evp;
230     for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
231       evp.push_back(new KiddiePool(depth, 
232                                    multbin[iM], multbin[iM+1], 
233                                    zvtxbin[iZ], zvtxbin[iZ+1] ));
234     }
235     fEvPool.push_back(evp);
236   }
237   
238   for (Int_t iM=0; iM<nMultBins; iM++) {
239     for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
240       fEvPool.at(iM).at(iZ)->SetMultBinIndex(iM);
241       fEvPool.at(iM).at(iZ)->SetZvtxBinIndex(iZ);
242       fEvPool.at(iM).at(iZ)->SetTargetTrackDepth(fTargetTrackDepth);
243       fEvPool.at(iM).at(iZ)->SetDebug(fDebug);
244     }
245   }
246   
247   if (fDebug) {
248     cout << "fEvPool outer size: " << fEvPool.size() << endl;
249     for (Int_t iM=0; iM<nMultBins; iM++) {
250       for (Int_t iZ=0; iZ<nZvtxBins; iZ++) {
251         if(fEvPool.at(iM).at(iZ)) {
252           cout << "multiplicity bin: " << iM;
253           cout << ", z-vertex bin: " << iZ;
254           fEvPool.at(iM).at(iZ)->PrintInfo();
255         }
256       }
257     }
258   }
259   
260   return fEvPool.size();
261 }
262
263 KiddiePool*
264 KiddiePoolManager::GetEventPool(Int_t iMult, Int_t iZvtx) const
265 {
266   if (iMult < 0 || iMult >= fNMultBins) 
267     return 0x0;
268   if (iZvtx < 0 || iZvtx >= fNZvtxBins) 
269     return 0x0;
270   return fEvPool.at(iMult).at(iZvtx);
271 }
272
273 KiddiePool*
274 KiddiePoolManager::GetEventPool(Int_t centVal, Double_t zVtxVal) const
275 {
276   return GetEventPool((Double_t)centVal, zVtxVal);
277 }
278
279 KiddiePool*
280 KiddiePoolManager::GetEventPool(Double_t centVal, Double_t zVtxVal) const
281 {
282   // Return appropriate pool for this centrality and z-vertex value.
283
284   for (Int_t iM=0; iM<fNMultBins; iM++) {
285     for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
286       KiddiePool* pool = GetEventPool(iM, iZ);
287       if (pool->EventMatchesBin(centVal, zVtxVal))
288         return pool;
289     }
290   }
291   return 0x0;
292 }
293
294 Int_t
295 KiddiePoolManager::UpdatePools(MiniEvent* miniEvt)
296 {
297   // Call UpdatePool for all bins.
298
299   for (Int_t iM=0; iM<fNMultBins; iM++) {
300     for (Int_t iZ=0; iZ<fNZvtxBins; iZ++) {
301       if (fEvPool.at(iM).at(iZ)->UpdatePool(miniEvt) > -1)
302         break;
303     }
304   }
305   return 0;
306 }