]>
Commit | Line | Data |
---|---|---|
b425275c | 1 | // |
2 | // Class AliAnalysisTaskMixInfo | |
3 | // | |
4 | // AliAnalysisTaskMixInfo is task | |
5 | // for mixing info | |
6 | // | |
24dc85b1 | 7 | // Mixing info can be enabled by setting one of following lines in UserCreateOutput() in your task |
8 | // // prints mixing info | |
9 | // AliLog::SetClassDebugLevel("AliAnalysisTaskMixInfo", AliLog::kDebug); | |
10 | // // prints mixing info + event info for both (main and mixed) events | |
11 | // AliLog::SetClassDebugLevel("AliAnalysisTaskMixInfo", AliLog::kDebug+1); | |
12 | // | |
b425275c | 13 | // authors: |
14 | // Martin Vala (martin.vala@cern.ch) | |
15 | // | |
16 | ||
17 | #include <TList.h> | |
f2db2f8e | 18 | #include <TObjString.h> |
b425275c | 19 | |
20 | #include "AliAnalysisManager.h" | |
21 | ||
22 | #include "AliMixInputEventHandler.h" | |
23 | #include "AliAnalysisTaskMixInfo.h" | |
24 | #include "AliMixInfo.h" | |
25 | #include "AliMixEventPool.h" | |
24dc85b1 | 26 | #include "AliMixEventCutObj.h" |
b425275c | 27 | |
f2db2f8e | 28 | |
b425275c | 29 | ClassImp(AliAnalysisTaskMixInfo) |
30 | ||
31 | //________________________________________________________________________ | |
32 | AliAnalysisTaskMixInfo::AliAnalysisTaskMixInfo(const char *name) | |
33 | : AliAnalysisTaskSE(name), | |
24dc85b1 | 34 | fInputEHMain(0), |
35 | fInputEHMix(0), | |
b425275c | 36 | fOutputList(0), |
37 | fMixInfo(0), | |
38 | fCurrentEntryTmp(-1), | |
39 | fLogType(AliLog::kInfo), | |
40 | fLogClassesString() | |
41 | { | |
42 | // | |
43 | // Constructor | |
44 | // | |
45 | DefineOutput(1, TList::Class()); | |
46 | } | |
47 | ||
48 | //________________________________________________________________________ | |
49 | AliAnalysisTaskMixInfo::~AliAnalysisTaskMixInfo() | |
50 | { | |
51 | // | |
52 | // Destructor | |
53 | // | |
54 | if (fOutputList && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fOutputList; | |
55 | } | |
56 | ||
57 | //________________________________________________________________________ | |
58 | void AliAnalysisTaskMixInfo::UserCreateOutputObjects() | |
59 | { | |
60 | // Create histograms | |
61 | // Called once | |
62 | ||
63 | SetDebugForAllClasses(); | |
64 | fOutputList = new TList(); | |
65 | fOutputList->SetOwner(kTRUE); | |
b425275c | 66 | |
24dc85b1 | 67 | // sets all Inuput Handler pointers |
68 | InitInputHandlers(); | |
69 | ||
70 | // inits mix info | |
71 | InitMixInfo(); | |
72 | ||
73 | if (fInputEHMix) { | |
74 | AliMixEventPool *evPool = fInputEHMix->GetEventPool(); | |
75 | if (evPool) { | |
76 | evPool->SetBufferSize(fInputEHMix->BufferSize()); | |
77 | evPool->SetMixNumber(fInputEHMix->MixNumber()); | |
78 | fMixInfo->SetEventPool(evPool); | |
b425275c | 79 | } |
80 | } | |
b425275c | 81 | if (fMixInfo) fOutputList->Add(fMixInfo); |
82 | ||
83 | // Post output data. | |
84 | PostData(1, fOutputList); | |
85 | } | |
86 | ||
87 | //________________________________________________________________________ | |
88 | void AliAnalysisTaskMixInfo::UserExec(Option_t *) | |
89 | { | |
90 | // Main loop | |
91 | // Called for each event | |
24dc85b1 | 92 | if (fMixInfo && fInputEHMix) { |
93 | if (fInputEHMix->BufferSize() > 1) { | |
94 | if (fInputEHMix->NumberMixedTimes() >= fInputEHMix->BufferSize()) | |
95 | fMixInfo->FillHistogram(AliMixInfo::kMainEvents, fInputEHMix->CurrentBinIndex()); | |
96 | } else { | |
917b33da | 97 | if ((!fInputEHMix->IsMixingIfNotEnoughEvents())) { |
98 | if (fInputEHMix->NumberMixed() == fInputEHMix->MixNumber()) | |
99 | // add main entry only when there was enough mixed events mixed | |
100 | fMixInfo->FillHistogram(AliMixInfo::kMainEvents, fInputEHMix->CurrentBinIndex()); | |
101 | } else { | |
102 | fMixInfo->FillHistogram(AliMixInfo::kMainEvents, fInputEHMix->CurrentBinIndex()); | |
103 | } | |
781b6757 | 104 | } |
24dc85b1 | 105 | AliDebug(AliLog::kDebug, Form("Main %lld %d [%lld,%lld] %d", fInputEHMix->CurrentEntry(), fInputEHMix->CurrentBinIndex(), fInputEHMix->CurrentEntryMain(), fInputEHMix->CurrentEntryMix(), fInputEHMix->NumberMixed())); |
b425275c | 106 | } |
107 | // Post output data. | |
108 | PostData(1, fOutputList); | |
109 | } | |
110 | ||
111 | //________________________________________________________________________ | |
112 | void AliAnalysisTaskMixInfo::UserExecMix(Option_t *) | |
113 | { | |
114 | // UserExecMix | |
24dc85b1 | 115 | |
116 | if (!fInputEHMix) return; | |
117 | ||
118 | // fills bin index (even when it is -1, so we know out of range combinations) | |
119 | if (fMixInfo) fMixInfo->FillHistogram(AliMixInfo::kMixedEvents, fInputEHMix->CurrentBinIndex()); | |
120 | ||
121 | // just test | |
122 | if (fInputEHMix->CurrentEntryMix() < 0) { | |
123 | AliError("Mix entry is -1 and it should not happen !!!!!"); | |
124 | return ; | |
b425275c | 125 | } |
24dc85b1 | 126 | AliDebug(AliLog::kDebug, Form("Mixing %lld %d [%lld,%lld] %d", fInputEHMix->CurrentEntry(), fInputEHMix->CurrentBinIndex(), fInputEHMix->CurrentEntryMain(), fInputEHMix->CurrentEntryMix(), fInputEHMix->NumberMixed())); |
127 | if (AliLog::GetDebugLevel("", IsA()->GetName()) > AliLog::kDebug) PrintEventInfo(); | |
b425275c | 128 | // Post output data. |
129 | PostData(1, fOutputList); | |
130 | } | |
131 | ||
132 | //________________________________________________________________________ | |
133 | void AliAnalysisTaskMixInfo::FinishTaskOutput() | |
134 | { | |
135 | // FinishTaskOutput | |
136 | if (fMixInfo) fMixInfo->Print(); | |
137 | } | |
138 | ||
139 | ||
140 | //________________________________________________________________________ | |
141 | void AliAnalysisTaskMixInfo::Terminate(Option_t *) | |
142 | { | |
143 | // Draw result to the screen | |
144 | // Called once at the end of the query | |
145 | fOutputList = dynamic_cast<TList *>(GetOutputData(1)); | |
146 | if (!fOutputList) { | |
147 | AliError("fOutputList not available"); | |
148 | return; | |
149 | } | |
150 | fOutputList->Print(); | |
151 | fMixInfo = (AliMixInfo *) fOutputList->FindObject("mixInfo"); | |
152 | if (fMixInfo) { | |
153 | fMixInfo->Draw("HIST"); | |
154 | AliMixEventPool *evPool = (AliMixEventPool *) fMixInfo->GetEventPool("mixEventPool"); | |
155 | if (evPool) evPool->Print(); | |
156 | } | |
157 | } | |
158 | ||
159 | //_____________________________________________________________________________ | |
160 | void AliAnalysisTaskMixInfo::SetLogType(AliLog::EType_t type, TString allClasses) | |
161 | { | |
162 | // | |
163 | // Set Log level for this and other classes (list of their names) | |
164 | // | |
165 | AliDebug(AliLog::kDebug + 10, "<-"); | |
166 | fLogType = type; | |
167 | fLogClassesString = allClasses; | |
168 | SetDebugForAllClasses(); | |
169 | AliDebug(AliLog::kDebug + 10, "->"); | |
170 | } | |
171 | ||
172 | //_____________________________________________________________________________ | |
173 | void AliAnalysisTaskMixInfo::SetDebugForAllClasses() | |
174 | { | |
175 | // | |
176 | // Set debug level for all classes for which it is required | |
177 | // | |
178 | AliDebug(AliLog::kDebug + 10, "<-"); | |
179 | TObjArray *array = fLogClassesString.Tokenize(":"); | |
180 | TObjString *str; | |
181 | TString strr; | |
182 | for (Int_t i = 0; i < array->GetEntriesFast(); i++) { | |
183 | str = (TObjString *) array->At(i); | |
184 | strr = str->GetString(); | |
185 | AliLog::SetClassDebugLevel(strr.Data(), fLogType); | |
186 | AliDebug(AliLog::kDebug + 5, Form("Setting Debug level %d to %s ...", (Int_t)fLogType - AliLog::kDebug, strr.Data())); | |
187 | } | |
188 | AliDebug(AliLog::kDebug + 10, "->"); | |
189 | } | |
190 | ||
24dc85b1 | 191 | //_____________________________________________________________________________ |
b425275c | 192 | void AliAnalysisTaskMixInfo::InitMixInfo() |
193 | { | |
194 | // | |
195 | // Init mixing info | |
196 | // | |
24dc85b1 | 197 | if (fInputEHMix) { |
198 | fMixInfo = new AliMixInfo("mixInfo", "Mix title"); | |
199 | AliMixEventPool *evPool = fInputEHMix->GetEventPool(); | |
200 | if (!evPool) { | |
201 | // TList *list = new TList; | |
202 | if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, 1, 1, 2); | |
203 | if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, 1, 1, 2); | |
b425275c | 204 | } else { |
24dc85b1 | 205 | if (evPool->NeedInit()) evPool->Init(); |
206 | Int_t num = evPool->GetListOfEntryLists()->GetEntriesFast(); | |
207 | if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, num, 1, num + 1); | |
208 | if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, num, 1, num + 1); | |
b425275c | 209 | } |
24dc85b1 | 210 | } |
211 | } | |
212 | ||
213 | //_____________________________________________________________________________ | |
214 | void AliAnalysisTaskMixInfo::PrintEventInfo() | |
215 | { | |
216 | // | |
217 | // Prints event info for all event mxing cuts | |
218 | // | |
219 | if (fInputEHMix) { | |
220 | TObjArrayIter next(fInputEHMix->GetEventPool()->GetListOfEventCuts()); | |
221 | AliMixEventCutObj *cut; | |
222 | AliInputEventHandler *ihMain = fInputEHMain->GetFirstInputEventHandler(); | |
223 | AliMultiInputEventHandler *ihMultiMix = fInputEHMix->GetFirstMultiInputHandler(); | |
224 | AliInputEventHandler *ihMix = 0; | |
225 | if (ihMultiMix) ihMix = ihMultiMix->GetFirstInputEventHandler(); | |
226 | if (!ihMix) return; | |
227 | while ((cut = (AliMixEventCutObj *) next())) { | |
228 | cut->PrintValues(ihMain->GetEvent(), ihMix->GetEvent()); | |
229 | } | |
230 | } | |
231 | } | |
232 | ||
233 | //_____________________________________________________________________________ | |
234 | void AliAnalysisTaskMixInfo::InitInputHandlers() | |
235 | { | |
236 | // | |
237 | // Sets needed input handlers | |
238 | // | |
239 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
240 | fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler()); | |
241 | if (fInputEHMain) { | |
242 | fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler()); | |
b425275c | 243 | } |
244 | } |