]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/EventMixing/AliMixEventPool.cxx
Fix for MixInfo Histogram to show correctly values in first bin.
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / AliMixEventPool.cxx
CommitLineData
c5e33610 1//
2// Class AliMixEventPool
3//
b425275c 4// AliMixEventPool is used to find
c5e33610 5// similar events
6//
7// author:
8// Martin Vala (martin.vala@cern.ch)
9//
10
11#include <TEntryList.h>
12
13#include "AliLog.h"
14#include "AliMixEventCutObj.h"
15
16#include "AliMixEventPool.h"
17
18ClassImp(AliMixEventPool)
19
20//_________________________________________________________________________________________________
b425275c 21AliMixEventPool::AliMixEventPool(const char *name, const char *title) : TNamed(name, title),
22 fListOfEntryList(),
23 fListOfEventCuts(),
24 fBinNumber(0),
25 fBufferSize(0),
26 fMixNumber(0)
27{
28 //
29 // Default constructor.
30 //
31 AliDebug(AliLog::kDebug + 5, "<-");
32 AliDebug(AliLog::kDebug + 5, "->");
c5e33610 33}
34//_________________________________________________________________________________________________
b425275c 35AliMixEventPool::AliMixEventPool(const AliMixEventPool &obj) : TNamed(obj),
36 fListOfEntryList(obj.fListOfEntryList),
37 fListOfEventCuts(obj.fListOfEventCuts),
38 fBinNumber(obj.fBinNumber),
39 fBufferSize(obj.fBufferSize),
40 fMixNumber(obj.fMixNumber)
41{
42 //
43 // Copy constructor
44 //
45 AliDebug(AliLog::kDebug + 5, "<-");
46 AliDebug(AliLog::kDebug + 5, "->");
c5e33610 47}
b425275c 48
c5e33610 49//_________________________________________________________________________________________________
b425275c 50AliMixEventPool& AliMixEventPool::operator=(const AliMixEventPool& obj)
51{
52 //
53 // Assigned operator
54 //
55 if (&obj != this) {
56 TNamed::operator=(obj);
57 fListOfEntryList = obj.fListOfEntryList;
58 fListOfEventCuts = obj.fListOfEventCuts;
59 fBinNumber = obj.fBinNumber;
60 fBufferSize = obj.fBufferSize;
61 fMixNumber = obj.fMixNumber;
62 }
63 return *this;
c5e33610 64}
c5e33610 65
b425275c 66
67//_________________________________________________________________________________________________
68AliMixEventPool::~AliMixEventPool()
69{
70 //
71 // Destructor
72 //
73 AliDebug(AliLog::kDebug + 5, "<-");
74 AliDebug(AliLog::kDebug + 5, "->");
c5e33610 75}
76//_________________________________________________________________________________________________
b425275c 77void AliMixEventPool::AddCut(AliMixEventCutObj *cut)
78{
79 //
80 // Adds cut
81 //
82 if (cut) fListOfEventCuts.Add(new AliMixEventCutObj(*cut));
c5e33610 83}
84//_________________________________________________________________________________________________
b425275c 85void AliMixEventPool::Print(const Option_t *option) const
86{
87 //
88 // Prints usefull information
89 //
90 TObjArrayIter next(&fListOfEventCuts);
91 // Int_t c=0;
92 AliMixEventCutObj *cut;
93 while ((cut = (AliMixEventCutObj *) next())) {
94 cut->Print(option);
95 }
96 AliDebug(AliLog::kDebug, Form("NumOfEntryList %d", fListOfEntryList.GetEntries()));
97 TEntryList *el;
98 for (Int_t i = 0; i < fListOfEntryList.GetEntries(); i++) {
99 el = (TEntryList *) fListOfEntryList.At(i);
100 AliDebug(AliLog::kDebug, Form("EntryList[%d] %lld", i, el->GetN()));
101 }
102}
103//_________________________________________________________________________________________________
104Int_t AliMixEventPool::Init()
105{
106 //
107 // Init event pool
108 //
109 AliDebug(AliLog::kDebug + 5, "<-");
110 CreateEntryListsRecursivly(fListOfEventCuts.GetEntries() - 1);
111 fBinNumber++;
112 AliDebug(AliLog::kDebug, Form("fBinnumber = %d", fBinNumber));
113 AddEntryList();
114 AliDebug(AliLog::kDebug + 5, "->");
115 return 0;
c5e33610 116}
117
118//_________________________________________________________________________________________________
b425275c 119void AliMixEventPool::CreateEntryListsRecursivly(Int_t index)
120{
121 //
122 // Helper function which create entrylist recursivly
123 //
124 AliDebug(AliLog::kDebug + 5, "<-");
125 AliMixEventCutObj *cut;
126 if (index >= 0) {
f2db2f8e 127 AliDebug(AliLog::kDebug + 1, Form("index = %d", index));
b425275c 128 cut = dynamic_cast<AliMixEventCutObj *>(fListOfEventCuts.At(index));
781b6757 129 if (!cut) return;
b425275c 130 cut->Reset();
131 while (cut->HasMore()) {
132 cut->AddStep();
133 CreateEntryListsRecursivly(index - 1);
134 if (cut->HasMore()) {
135 fBinNumber++;
f2db2f8e 136 AliDebug(AliLog::kDebug + 1, Form("fBinnumber = %d", fBinNumber));
b425275c 137 AddEntryList();
138 // PrintCurrentCutIntervals();
139 }
c5e33610 140 }
b425275c 141 }
142 AliDebug(AliLog::kDebug + 5, "->");
143}
c5e33610 144
b425275c 145//_________________________________________________________________________________________________
146TEntryList *AliMixEventPool::AddEntryList()
147{
148 //
149 // Adds endtry list
150 //
151 AliDebug(AliLog::kDebug + 5, "<-");
152 TObjArrayIter next(&fListOfEventCuts);
153 AliMixEventCutObj *cut;
154 while ((cut = (AliMixEventCutObj *) next())) {
155 if (cut) cut->PrintCurrentInterval();
156 }
157 TEntryList *el = new TEntryList;
158 fListOfEntryList.Add(el);
f2db2f8e 159 AliDebug(AliLog::kDebug + 1, Form("Number in Entry list -> %lld", el->GetN()));
b425275c 160 AliDebug(AliLog::kDebug + 5, "->");
161 return el;
c5e33610 162}
163
164//_________________________________________________________________________________________________
b425275c 165Bool_t AliMixEventPool::AddEntry(Long64_t entry, AliVEvent *ev)
166{
167 //
168 // Adds entry to correct entry list
169 //
170 AliDebug(AliLog::kDebug + 5, "<-");
171 AliDebug(AliLog::kDebug + 5, Form("AddEntry(%lld,%p)", entry, (void *)ev));
172 if (entry < 0) {
173 AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
174 return kFALSE;
175 }
176 Int_t idEntryList = -1;
177 TEntryList *el = FindEntryList(ev, idEntryList);
178 if (el) {
179 el->Enter(entry);
180 AliDebug(AliLog::kDebug, Form("Entry %lld was added with idEntryList %d !!!", entry, idEntryList));
181 return kTRUE;
182 }
183 AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
184 AliDebug(AliLog::kDebug + 5, "->");
185 return kFALSE;
c5e33610 186}
187
188//_________________________________________________________________________________________________
b425275c 189TEntryList *AliMixEventPool::FindEntryList(AliVEvent *ev, Int_t &idEntryList)
190{
191 //
192 // Find entrlist in list of entrlist
193 //
194 AliDebug(AliLog::kDebug + 5, "<-");
195 Int_t num = fListOfEventCuts.GetEntriesFast();
196 if (num < 1) return 0;
197 Int_t *indexes = new Int_t[num] ;
198 Int_t *lenght = new Int_t[num];
199 Int_t i = 0;
200 TObjArrayIter next(&fListOfEventCuts);
201 AliMixEventCutObj *cut;
202 while ((cut = (AliMixEventCutObj *) next())) {
203 indexes[i] = cut->GetIndex(ev);
204 if (indexes[i] < 0) {
205 AliDebug(AliLog::kDebug, Form("idEntryList %d", -1));
206 delete [] indexes;
207 delete [] lenght;
208 return 0;
209 }
210 lenght[i] = cut->GetNumberOfBins();
211 AliDebug(AliLog::kDebug + 1, Form("indexes[%d] %d", i, indexes[i]));
212 i++;
213 }
214 idEntryList = 0;
215 SearchIndexRecursive(fListOfEventCuts.GetEntries() - 1, &indexes[0], &lenght[0], idEntryList);
216 AliDebug(AliLog::kDebug, Form("idEntryList %d", idEntryList - 1));
217 // index which start with 0 (idEntryList-1)
218 delete [] indexes;
219 delete [] lenght;
220 AliDebug(AliLog::kDebug + 5, "->");
221 return (TEntryList *) fListOfEntryList.At(idEntryList - 1);
c5e33610 222}
223
224//_________________________________________________________________________________________________
b425275c 225void AliMixEventPool::SearchIndexRecursive(Int_t num, Int_t *i, Int_t *d, Int_t &index)
226{
227 //
228 // Search for index of entrylist
229 //
230 AliDebug(AliLog::kDebug + 5, "<-");
231 if (num > 0) {
f2db2f8e 232 index += (i[num] - 1) * d[num - 1];
b425275c 233 SearchIndexRecursive(num - 1, i, d, index);
234 } else {
235 index += i[num];
236 }
237 AliDebug(AliLog::kDebug + 5, "->");
c5e33610 238}
239
240//_________________________________________________________________________________________________
a9439e6d 241Bool_t AliMixEventPool::SetCutValuesFromBinIndex(Int_t index)
b425275c 242{
243 //
244 // Sets cut value from bin index
245 //
a9439e6d 246
b425275c 247 Int_t numCuts = fListOfEventCuts.GetEntriesFast();
248 Int_t *lenght = new Int_t[numCuts];
249 Int_t *indexes = new Int_t[numCuts];
250 Long64_t timesNum = 1;
251 AliMixEventCutObj *cut;
252 Int_t i = 0, j = 0;
253 for (i = 0; i < numCuts; i++) {
254 cut = (AliMixEventCutObj *) fListOfEventCuts.At(i);
255 cut->Reset();
256 lenght[i] = cut->GetNumberOfBins();
257 indexes[i] = 1;
258 timesNum *= lenght[i];
259 }
260
261 if (index < 0 || index >= timesNum) {
a9439e6d 262// AliError(Form("index=%d is out of range !!!", index));
781b6757 263 delete [] lenght;
264 delete [] indexes;
a9439e6d 265 return kFALSE;
b425275c 266 }
267
268 Long64_t indexNum = index;
269 for (i = 0; i < numCuts; i++) {
270 timesNum = 1;
271 for (j = 0; j < numCuts - i - 1; j++) timesNum *= lenght[j];
272 indexNum /= timesNum;
f2db2f8e 273 indexes[numCuts - i - 1] = indexNum + 1;
b425275c 274 index -= indexNum * timesNum;
275 indexNum = index;
276 }
277
278 for (i = 0; i < numCuts; i++) {
279 cut = (AliMixEventCutObj *) fListOfEventCuts.At(i);
280 for (j = 0; j < indexes[i]; j++) cut->AddStep();
281 cut->PrintCurrentInterval();
282
283 }
284
285 for (i = 0; i < numCuts; i++) AliDebug(AliLog::kDebug, Form("indexes[%d]=%d", i, indexes[i]));
286
287 delete [] lenght;
288 delete [] indexes;
a9439e6d 289
290 return kTRUE;
c5e33610 291}