2 // Class AliRsnVAnalysisTask
4 // Virtual Class derivated from AliAnalysisTaskSE which will be base class
5 // for all RSN SE tasks
7 // authors: Martin Vala (martin.vala@cern.ch)
8 // Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
13 #include "AliESDEvent.h"
14 #include "AliMCEvent.h"
15 #include "AliAODEvent.h"
16 #include "AliAnalysisManager.h"
17 #include "AliMCEventHandler.h"
18 #include "AliMultiInputEventHandler.h"
19 #include "AliMixInputEventHandler.h"
22 #include "AliRsnEvent.h"
23 #include "AliRsnTarget.h"
25 #include "AliRsnVAnalysisTask.h"
27 ClassImp(AliRsnVAnalysisTask)
29 //_____________________________________________________________________________
30 AliRsnVAnalysisTask::AliRsnVAnalysisTask
31 (const char *name, Bool_t mcOnly) :
32 AliAnalysisTaskSE(name),
33 fLogType(AliLog::kInfo),
34 fLogClassesString(""),
40 fUseMixingRange(kTRUE)
43 // Default constructor.
44 // Define the output slot for histograms.
47 DefineOutput(1, TList::Class());
48 DefineOutput(2, TList::Class());
50 for (Int_t i = 0; i < 2; i++) {
58 //_____________________________________________________________________________
59 AliRsnVAnalysisTask::AliRsnVAnalysisTask(const AliRsnVAnalysisTask& copy) :
60 AliAnalysisTaskSE(copy),
61 fLogType(copy.fLogType),
62 fLogClassesString(copy.fLogClassesString),
63 fIsMixing(copy.fIsMixing),
64 fMCOnly(copy.fMCOnly),
66 fTaskInfo(copy.fTaskInfo),
67 fMixedEH(copy.fMixedEH),
68 fUseMixingRange(copy.fUseMixingRange)
72 // Defined for coding conventions compliance but never used.
74 AliDebug(AliLog::kDebug + 2, "<-");
76 for (Int_t i = 0; i < 2; i++) {
77 fESDEvent[i] = copy.fESDEvent[i];
78 fMCEvent[i] = copy.fMCEvent[i];
79 fAODEventIn[i] = copy.fAODEventIn[i];
80 fAODEventOut[i] = copy.fAODEventOut[i];
81 fRsnEvent[i] = copy.fRsnEvent[i];
84 AliDebug(AliLog::kDebug + 2, "->");
87 //_____________________________________________________________________________
88 void AliRsnVAnalysisTask::LocalInit()
91 // Local initialization.
92 // Defines the debug message level and calls the mother class LocalInit().
95 AliAnalysisTaskSE::LocalInit();
96 SetDebugForAllClasses();
99 //_____________________________________________________________________________
100 Bool_t AliRsnVAnalysisTask::UserNotify()
103 // Calls the mother class Notify()
106 return AliAnalysisTaskSE::UserNotify();
109 //_____________________________________________________________________________
110 void AliRsnVAnalysisTask::ConnectInputData(Option_t *opt)
113 // Connect input data, which consist in initializing properly
114 // the pointer to the input event, which is dynamically casted
115 // to all available types, and this allows to know its type.
116 // Calls also the mother class omonyme method.
119 AliAnalysisTaskSE::ConnectInputData(opt);
121 // get AliESDEvent and, if successful
122 // retrieve the corresponding MC if exists
123 fESDEvent[0] = dynamic_cast<AliESDEvent *>(fInputEvent);
125 fMCEvent[0] = (AliMCEvent*) MCEvent();
126 AliInfo(Form("Input event is of type ESD (%p)", fESDEvent[0]));
127 if (fMCEvent[0]) AliInfo(Form("Input has an associated MC (%p)", fMCEvent[0]));
130 // get AliAODEvent from input and, if successful
131 // it will contain both the reconstructed and MC informations
132 fAODEventIn[0] = dynamic_cast<AliAODEvent *>(fInputEvent);
133 if (fAODEventIn[0]) {
134 AliInfo(Form("Input event if of type native AOD (%p)", fAODEventIn[0]));
137 // get AliAODEvent from output of previous task
138 fAODEventOut[0] = dynamic_cast<AliAODEvent *>(AODEvent());
139 if (fAODEventOut[0]) {
140 AliInfo(Form("Input event if of type produced AOD from previous step (%p)", fAODEventOut[0]));
144 //_____________________________________________________________________________
145 void AliRsnVAnalysisTask::UserCreateOutputObjects()
148 // Creates and links to task all output objects.
149 // Does explicitly the initialization for the event info class,
150 // and then calls the customized function which must be overloaded
151 // in the applications of this base class.
154 SetDebugForAllClasses();
156 // set event info outputs
157 fInfoList = new TList();
158 fInfoList->SetOwner();
159 fTaskInfo.GenerateInfoList(fInfoList);
161 // create customized outputs
162 RsnUserCreateOutputObjects();
164 PostData(1, fInfoList);
167 //_____________________________________________________________________________
168 void AliRsnVAnalysisTask::UserExec(Option_t* opt)
171 // Prepares for execution, setting the correct pointers of the
172 // RSN package event interface, which will point to the not NULL
173 // objects obtained from dynamic-casts called in ConnectInputData().
178 if (fMCOnly && fMCEvent[0]) {
179 fRsnEvent[0].SetRef(fMCEvent[0]);
180 fRsnEvent[0].SetRefMC(fMCEvent[0]);
181 } else if (fESDEvent[0]) {
182 fRsnEvent[0].SetRef(fESDEvent[0]);
183 fRsnEvent[0].SetRefMC(fMCEvent[0]);
184 } else if (fAODEventOut[0]) {
185 fRsnEvent[0].SetRef(fAODEventOut[0]);
186 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
187 } else if (fAODEventIn[0]) {
188 fRsnEvent[0].SetRef(fAODEventIn[0]);
189 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
191 AliError("Unknown input event format. Skipping");
195 // call event preprocessing...
196 Bool_t preCheck = RsnEventProcess();
197 // ...then fill the information object and print informations...
198 fTaskInfo.FillInfo(&fRsnEvent[0]);
199 fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
200 // ...and return if event did not pass selections
202 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
206 // call customized implementation for execution
210 // post outputs for the info object
211 // (eventually others are done in the derived classes)
212 PostData(1, fInfoList);
215 void AliRsnVAnalysisTask::UserExecMix(Option_t* option)
217 AliDebug(AliLog::kDebug + 2, "<-");
220 if (!IsMixing()) return;
224 if (!fMixedEH) return;
226 if (fMCOnly && fMCEvent[0]) {
227 fRsnEvent[0].SetRef(fMCEvent[0]);
228 fRsnEvent[0].SetRefMC(fMCEvent[0]);
229 fRsnEvent[1].SetRef(fMCEvent[1]);
230 fRsnEvent[1].SetRefMC(fMCEvent[1]);
231 } else if (fESDEvent[0]) {
232 fRsnEvent[0].SetRef(fESDEvent[0]);
233 fRsnEvent[0].SetRefMC(fMCEvent[0]);
234 fRsnEvent[1].SetRef(fESDEvent[1]);
235 fRsnEvent[1].SetRefMC(fMCEvent[1]);
236 } else if (fAODEventOut) {
237 fRsnEvent[0].SetRef(fAODEventOut[0]);
238 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
239 fRsnEvent[1].SetRef(fAODEventOut[1]);
240 fRsnEvent[1].SetRefMC(fAODEventOut[1]);
241 } else if (fAODEventIn) {
242 fRsnEvent[0].SetRef(fAODEventIn[0]);
243 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
244 fRsnEvent[1].SetRef(fAODEventIn[1]);
245 fRsnEvent[1].SetRefMC(fAODEventIn[1]);
247 AliError("NO ESD or AOD object!!! Skipping ...");
251 // call event preprocessing...
252 Bool_t preCheck = RsnEventProcess();
253 // ...then fill the information object and print informations...
254 fTaskInfo.FillInfo(&fRsnEvent[0]);
255 fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
256 // ...and return if event did not pass selections
258 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
262 RsnUserExecMix(option);
263 AliDebug(AliLog::kDebug + 2, "->");
267 //_____________________________________________________________________________
268 void AliRsnVAnalysisTask::Terminate(Option_t* opt)
271 // Termination routines.
272 // Stores all histograms (after checking they exist)
273 // and includes to the TList all task informations.
276 AliAnalysisTask::Terminate();
278 TList* list = dynamic_cast<TList*>(GetOutputData(1));
280 AliError(Form("At end of analysis, fOutList is %p", list));
286 TH1I *hEventInfo = (TH1I*) list->FindObject(fTaskInfo.GetEventHistogramName());
288 AliError(Form("hEventInfo is %p", hEventInfo));
291 AliInfo(Form("=== %s ==================", GetName()));
292 AliInfo(Form("Number Of Events Processed : %10lld", (Long64_t)hEventInfo->Integral()));
293 AliInfo(Form("Number Of Events Accepted : %10lld", (Long64_t)hEventInfo->GetBinContent(2)));
294 AliInfo(Form("Number Of Events Skipped : %10lld", (Long64_t)hEventInfo->GetBinContent(1)));
295 AliInfo(Form("=== end %s ==============", GetName()));
297 AliDebug(AliLog::kDebug + 2, "->");
300 //_____________________________________________________________________________
301 void AliRsnVAnalysisTask::RsnUserCreateOutputObjects()
304 // Define here all instructions to create output objects.
305 // This method will be called inside the "UserCreateOutputObjects"
309 AliWarning("Implement this in derived classes");
312 //_____________________________________________________________________________
313 void AliRsnVAnalysisTask::RsnUserExec(Option_t*)
319 AliWarning("Implement this in derived classes");
322 void AliRsnVAnalysisTask::RsnUserExecMix(Option_t*)
328 AliWarning("Implement this in derived classes");
331 //_____________________________________________________________________________
332 void AliRsnVAnalysisTask::RsnTerminate(Option_t*)
335 // Overload this to add additional termination operations
338 AliWarning("Implement this in derived classes");
341 //_____________________________________________________________________________
342 Bool_t AliRsnVAnalysisTask::RsnEventProcess()
345 // Performs some pre-processing of current event,
346 // which is useful for all the operations which
347 // need to be done only once for each event.
350 // if not using mixing cuts return kTRUE
351 if (!IsMixing() || !IsUsingMixingRange()) return kTRUE;
353 // cut if event was in range of mixing cuts
354 AliVEventHandler *inh = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
355 if (inh->InheritsFrom(AliMultiInputEventHandler::Class())) {
356 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(inh);
358 fMixedEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
360 if (fMixedEH->CurrentBinIndex() < 0) return kFALSE;
365 // in this case, return always a success
369 //_____________________________________________________________________________
370 void AliRsnVAnalysisTask::SetupMixingEvents()
373 // Setup the pointers to the mixed event.
374 // This requires to retrieve them from the mixed event handler
377 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
378 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
380 fMixedEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
382 AliMultiInputEventHandler *inEvHMainTmpMix = dynamic_cast<AliMultiInputEventHandler *>(fMixedEH->InputEventHandler(0));
383 if (!inEvHMainTmpMix) return;
384 AliInputEventHandler *inEvHMixTmp = dynamic_cast<AliInputEventHandler *>(inEvHMainTmpMix->GetFirstInputEventHandler());
385 AliMCEventHandler *inEvHMCMixTmp = dynamic_cast<AliMCEventHandler *>(inEvHMainTmpMix->GetFirstMCEventHandler());
386 if (!inEvHMixTmp) return;
387 fESDEvent[1] = dynamic_cast<AliESDEvent *>(inEvHMixTmp->GetEvent());
388 if (fESDEvent[1]) AliDebug(AliLog::kDebug, Form("Input is ESD (%p) MIXED", fESDEvent[1]));
389 // getting AliAODEvent from input
390 fAODEventIn[1] = dynamic_cast<AliAODEvent *>(inEvHMixTmp->GetEvent());
391 if (fAODEventIn[1]) AliDebug(AliLog::kDebug, Form("Input is AOD (%p) MIXED", fAODEventIn[1]));
392 // getting AliAODEvent if it is output from previous task (not supported)
396 fMCEvent[1] = inEvHMCMixTmp->MCEvent();
397 if (fMCEvent[1]) AliDebug(AliLog::kDebug, Form("Input is ESDMC (%p) MIXED", fMCEvent[1]));
405 //_____________________________________________________________________________
406 void AliRsnVAnalysisTask::SetDebugForAllClasses()
409 // Set debug level for all classes for which it is required
412 TObjArray *array = fLogClassesString.Tokenize(":");
415 Int_t i, n = array->GetEntriesFast();
417 for (i = 0; i < n; i++) {
418 objStr = (TObjString*)array->At(i);
419 str = objStr->GetString();
420 AliLog::SetClassDebugLevel(str.Data(), fLogType);
421 AliInfo(Form("Setting Debug to %s", str.Data()));