2 // Class AliMixEventPool
4 // AliMixEventPool is used to find
8 // Martin Vala (martin.vala@cern.ch)
11 #include <TEntryList.h>
14 #include "AliMixEventCutObj.h"
16 #include "AliMixEventPool.h"
18 ClassImp(AliMixEventPool)
20 //_________________________________________________________________________________________________
21 AliMixEventPool::AliMixEventPool(const char *name, const char *title) : TNamed(name, title),
29 // Default constructor.
31 AliDebug(AliLog::kDebug + 5, "<-");
32 AliDebug(AliLog::kDebug + 5, "->");
34 //_________________________________________________________________________________________________
35 AliMixEventPool::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)
45 AliDebug(AliLog::kDebug + 5, "<-");
46 AliDebug(AliLog::kDebug + 5, "->");
49 //_________________________________________________________________________________________________
50 AliMixEventPool& AliMixEventPool::operator=(const AliMixEventPool& obj)
56 TNamed::operator=(obj);
57 fListOfEntryList = obj.fListOfEntryList;
58 fListOfEventCuts = obj.fListOfEventCuts;
59 fBinNumber = obj.fBinNumber;
60 fBufferSize = obj.fBufferSize;
61 fMixNumber = obj.fMixNumber;
67 //_________________________________________________________________________________________________
68 AliMixEventPool::~AliMixEventPool()
73 AliDebug(AliLog::kDebug + 5, "<-");
74 AliDebug(AliLog::kDebug + 5, "->");
76 //_________________________________________________________________________________________________
77 void AliMixEventPool::AddCut(AliMixEventCutObj *cut)
82 if (cut) fListOfEventCuts.Add(new AliMixEventCutObj(*cut));
84 //_________________________________________________________________________________________________
85 void AliMixEventPool::Print(const Option_t *option) const
88 // Prints usefull information
90 TObjArrayIter next(&fListOfEventCuts);
92 AliMixEventCutObj *cut;
93 while ((cut = (AliMixEventCutObj *) next())) {
96 AliDebug(AliLog::kDebug, Form("NumOfEntryList %d", fListOfEntryList.GetEntries()));
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()));
103 //_________________________________________________________________________________________________
104 Int_t AliMixEventPool::Init()
109 AliDebug(AliLog::kDebug + 5, "<-");
110 CreateEntryListsRecursivly(fListOfEventCuts.GetEntries() - 1);
112 AliDebug(AliLog::kDebug, Form("fBinnumber = %d", fBinNumber));
114 AliDebug(AliLog::kDebug + 5, "->");
118 //_________________________________________________________________________________________________
119 void AliMixEventPool::CreateEntryListsRecursivly(Int_t index)
122 // Helper function which create entrylist recursivly
124 AliDebug(AliLog::kDebug + 5, "<-");
125 AliMixEventCutObj *cut;
127 AliDebug(AliLog::kDebug + 1, Form("index = %d", index));
128 cut = dynamic_cast<AliMixEventCutObj *>(fListOfEventCuts.At(index));
131 while (cut->HasMore()) {
133 CreateEntryListsRecursivly(index - 1);
134 if (cut->HasMore()) {
136 AliDebug(AliLog::kDebug + 1, Form("fBinnumber = %d", fBinNumber));
138 // PrintCurrentCutIntervals();
142 AliDebug(AliLog::kDebug + 5, "->");
145 //_________________________________________________________________________________________________
146 TEntryList *AliMixEventPool::AddEntryList()
151 AliDebug(AliLog::kDebug + 5, "<-");
152 TObjArrayIter next(&fListOfEventCuts);
153 AliMixEventCutObj *cut;
154 while ((cut = (AliMixEventCutObj *) next())) {
155 if (cut) cut->PrintCurrentInterval();
157 TEntryList *el = new TEntryList;
158 fListOfEntryList.Add(el);
159 AliDebug(AliLog::kDebug + 1, Form("Number in Entry list -> %lld", el->GetN()));
160 AliDebug(AliLog::kDebug + 5, "->");
164 //_________________________________________________________________________________________________
165 Bool_t AliMixEventPool::AddEntry(Long64_t entry, AliVEvent *ev)
168 // Adds entry to correct entry list
170 AliDebug(AliLog::kDebug + 5, "<-");
171 AliDebug(AliLog::kDebug + 5, Form("AddEntry(%lld,%p)", entry, (void *)ev));
173 AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
176 Int_t idEntryList = -1;
177 TEntryList *el = FindEntryList(ev, idEntryList);
180 AliDebug(AliLog::kDebug, Form("Entry %lld was added with idEntryList %d !!!", entry, idEntryList));
183 AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
184 AliDebug(AliLog::kDebug + 5, "->");
188 //_________________________________________________________________________________________________
189 TEntryList *AliMixEventPool::FindEntryList(AliVEvent *ev, Int_t &idEntryList)
192 // Find entrlist in list of entrlist
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];
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));
210 lenght[i] = cut->GetNumberOfBins();
211 AliDebug(AliLog::kDebug + 1, Form("indexes[%d] %d", i, indexes[i]));
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)
220 AliDebug(AliLog::kDebug + 5, "->");
221 return (TEntryList *) fListOfEntryList.At(idEntryList - 1);
224 //_________________________________________________________________________________________________
225 void AliMixEventPool::SearchIndexRecursive(Int_t num, Int_t *i, Int_t *d, Int_t &index)
228 // Search for index of entrylist
230 AliDebug(AliLog::kDebug + 5, "<-");
232 index += (i[num] - 1) * d[num - 1];
233 SearchIndexRecursive(num - 1, i, d, index);
237 AliDebug(AliLog::kDebug + 5, "->");
240 //_________________________________________________________________________________________________
241 Bool_t AliMixEventPool::SetCutValuesFromBinIndex(Int_t index)
244 // Sets cut value from bin index
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;
253 for (i = 0; i < numCuts; i++) {
254 cut = (AliMixEventCutObj *) fListOfEventCuts.At(i);
256 lenght[i] = cut->GetNumberOfBins();
258 timesNum *= lenght[i];
261 if (index < 0 || index >= timesNum) {
262 // AliError(Form("index=%d is out of range !!!", index));
268 Long64_t indexNum = index;
269 for (i = 0; i < numCuts; i++) {
271 for (j = 0; j < numCuts - i - 1; j++) timesNum *= lenght[j];
272 indexNum /= timesNum;
273 indexes[numCuts - i - 1] = indexNum + 1;
274 index -= indexNum * timesNum;
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();
285 for (i = 0; i < numCuts; i++) AliDebug(AliLog::kDebug, Form("indexes[%d]=%d", i, indexes[i]));