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)
11 #include <Riostream.h>
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(""),
42 // Default constructor.
43 // Define the output slot for histograms.
46 DefineOutput(1, TList::Class());
47 DefineOutput(2, TList::Class());
48 for(Int_t i=0;i<2;i++) {
56 //_____________________________________________________________________________
57 AliRsnVAnalysisTask::AliRsnVAnalysisTask(const AliRsnVAnalysisTask& copy) :
58 AliAnalysisTaskSE(copy),
59 fLogType(copy.fLogType),
60 fLogClassesString(copy.fLogClassesString),
61 fIsMixing(copy.fIsMixing),
62 fMCOnly(copy.fMCOnly),
64 fTaskInfo(copy.fTaskInfo),
65 fMixedEH(copy.fMixedEH)
69 // Defined for coding conventions compliance but never used.
71 AliDebug(AliLog::kDebug+2, "<-");
72 for(Int_t i=0;i<2;i++) {
73 fESDEvent[i] = copy.fESDEvent[i];
74 fMCEvent[i]=copy.fMCEvent[i];
75 fAODEventIn[i]=copy.fAODEventIn[i];
76 fAODEventOut[i]=copy.fAODEventOut[i];
77 fRsnEvent[i]=copy.fRsnEvent[i];
79 AliDebug(AliLog::kDebug+2, "->");
83 //_____________________________________________________________________________
84 void AliRsnVAnalysisTask::LocalInit()
87 // Local initialization.
88 // Defines the debug message level and calls the mother class LocalInit().
91 AliAnalysisTaskSE::LocalInit();
92 SetDebugForAllClasses();
95 //_____________________________________________________________________________
96 Bool_t AliRsnVAnalysisTask::UserNotify()
99 // Calls the mother class Notify()
102 return AliAnalysisTaskSE::UserNotify();
105 //_____________________________________________________________________________
106 void AliRsnVAnalysisTask::ConnectInputData(Option_t *opt)
109 // Connect input data, which consist in initializing properly
110 // the pointer to the input event, which is dynamically casted
111 // to all available types, and this allows to know its type.
112 // Calls also the mother class omonyme method.
115 AliAnalysisTaskSE::ConnectInputData(opt);
117 // get AliESDEvent and, if successful
118 // retrieve the corresponding MC if exists
119 fESDEvent[0] = dynamic_cast<AliESDEvent *>(fInputEvent);
122 fMCEvent[0] = (AliMCEvent*) MCEvent();
123 AliInfo(Form("Input event is of type ESD (%p)", fESDEvent[0]));
124 if (fMCEvent[0]) AliInfo(Form("Input has an associated MC (%p)", fMCEvent[0]));
127 // get AliAODEvent from input and, if successful
128 // it will contain both the reconstructed and MC informations
129 fAODEventIn[0] = dynamic_cast<AliAODEvent *>(fInputEvent);
132 AliInfo(Form("Input event if of type native AOD (%p)", fAODEventIn[0]));
135 // get AliAODEvent from output of previous task
136 fAODEventOut[0] = dynamic_cast<AliAODEvent *>(AODEvent());
139 AliInfo(Form("Input event if of type produced AOD from previous step (%p)",fAODEventOut[0]));
143 //_____________________________________________________________________________
144 void AliRsnVAnalysisTask::UserCreateOutputObjects()
147 // Creates and links to task all output objects.
148 // Does explicitly the initialization for the event info class,
149 // and then calls the customized function which must be overloaded
150 // in the applications of this base class.
153 SetDebugForAllClasses();
155 // set event info outputs
156 fInfoList = new TList();
157 fInfoList->SetOwner();
158 fTaskInfo.GenerateInfoList(fInfoList);
160 // create customized outputs
161 RsnUserCreateOutputObjects();
163 PostData(1, fInfoList);
166 //_____________________________________________________________________________
167 void AliRsnVAnalysisTask::UserExec(Option_t* opt)
170 // Prepares for execution, setting the correct pointers of the
171 // RSN package event interface, which will point to the not NULL
172 // objects obtained from dynamic-casts called in ConnectInputData().
175 if (fMCOnly && fMCEvent)
177 fRsnEvent[0].SetRef (fMCEvent[0]);
178 fRsnEvent[0].SetRefMC(fMCEvent[0]);
180 else if (fESDEvent[0])
182 fRsnEvent[0].SetRef (fESDEvent[0]);
183 fRsnEvent[0].SetRefMC(fMCEvent[0]);
185 else if (fAODEventOut)
187 fRsnEvent[0].SetRef (fAODEventOut[0]);
188 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
190 else if (fAODEventIn)
192 fRsnEvent[0].SetRef (fAODEventIn[0]);
193 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
197 AliError("Unknown input event format. Skipping");
201 // since this class is for single-event analysis
202 // both static pointers of AliRsnEvent class
203 // will point to the same unique datamember
204 AliRsnEvent::SetCurrentEvent1(&fRsnEvent[0], fEntry);
205 AliRsnEvent::SetCurrentEvent2(&fRsnEvent[0], fEntry);
206 AliRsnTarget::SwitchToFirst();
208 // call event preprocessing...
209 Bool_t preCheck = EventProcess();
210 // ...then fill the information object and print informations...
211 fTaskInfo.FillInfo();
212 fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
213 // ...and return if event did not pass selections
216 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
221 // call customized implementation for execution
224 // post outputs for the info object
225 // (eventually others are done in the derived classes)
226 PostData(1, fInfoList);
229 void AliRsnVAnalysisTask::UserExecMix(Option_t* option)
231 AliDebug(AliLog::kDebug+2,"<-");
234 if (!IsMixing()) return;
238 if (!fMixedEH) return;
240 if (fMCOnly && fMCEvent[0])
242 fRsnEvent[0].SetRef (fMCEvent[0]);
243 fRsnEvent[0].SetRefMC(fMCEvent[0]);
244 fRsnEvent[1].SetRef (fMCEvent[1]);
245 fRsnEvent[1].SetRefMC(fMCEvent[1]);
247 else if (fESDEvent[0])
249 fRsnEvent[0].SetRef (fESDEvent[0]);
250 fRsnEvent[0].SetRefMC(fMCEvent[0]);
251 fRsnEvent[1].SetRef (fESDEvent[1]);
252 fRsnEvent[1].SetRefMC(fMCEvent[1]);
254 else if (fAODEventOut)
256 fRsnEvent[0].SetRef (fAODEventOut[0]);
257 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
258 fRsnEvent[1].SetRef (fAODEventOut[1]);
259 fRsnEvent[1].SetRefMC(fAODEventOut[1]);
261 else if (fAODEventIn)
263 fRsnEvent[0].SetRef (fAODEventIn[0]);
264 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
265 fRsnEvent[1].SetRef (fAODEventIn[1]);
266 fRsnEvent[1].SetRefMC(fAODEventIn[1]);
269 AliError("NO ESD or AOD object!!! Skipping ...");
272 // since this class is for single-event analysis
273 // both static pointers of AliRsnEvent class
274 // will point to the same unique datamember
277 AliRsnEvent::SetCurrentEvent1(&fRsnEvent[0], fMixedEH->CurrentEntryMain());
278 AliRsnEvent::SetCurrentEvent2(&fRsnEvent[1], fMixedEH->CurrentEntryMix());
279 AliRsnTarget::SwitchToFirst();
281 // call event preprocessing...
282 Bool_t preCheck = EventProcess();
283 // ...then fill the information object and print informations...
284 fTaskInfo.FillInfo();
285 fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
286 // ...and return if event did not pass selections
289 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
293 RsnUserExecMix(option);
294 AliDebug(AliLog::kDebug+2,"->");
298 //_____________________________________________________________________________
299 void AliRsnVAnalysisTask::Terminate(Option_t* opt)
302 // Termination routines.
303 // Stores all histograms (after checking they exist)
304 // and includes to the TList all task informations.
307 AliAnalysisTask::Terminate();
309 TList* list = dynamic_cast<TList*>(GetOutputData(1));
312 AliError(Form("At end of analysis, fOutList is %p", list));
318 TH1I *hEventInfo = (TH1I*) list->FindObject(fTaskInfo.GetEventHistogramName());
321 AliError(Form("hEventInfo is %p", hEventInfo));
324 AliInfo(Form("=== %s ==================",GetName()));
325 AliInfo(Form("Number Of Events Processed : %10lld",(Long64_t)hEventInfo->Integral()));
326 AliInfo(Form("Number Of Events Accepted : %10lld",(Long64_t)hEventInfo->GetBinContent(2)));
327 AliInfo(Form("Number Of Events Skipped : %10lld",(Long64_t)hEventInfo->GetBinContent(1)));
328 AliInfo(Form("=== end %s ==============",GetName()));
330 AliDebug(AliLog::kDebug+2, "->");
333 //_____________________________________________________________________________
334 void AliRsnVAnalysisTask::RsnUserCreateOutputObjects()
337 // Define here all instructions to create output objects.
338 // This method will be called inside the "UserCreateOutputObjects"
342 AliWarning("Implement this in derived classes");
345 //_____________________________________________________________________________
346 void AliRsnVAnalysisTask::RsnUserExec(Option_t*)
352 AliWarning("Implement this in derived classes");
355 void AliRsnVAnalysisTask::RsnUserExecMix(Option_t* )
361 AliWarning("Implement this in derived classes");
364 //_____________________________________________________________________________
365 void AliRsnVAnalysisTask::RsnTerminate(Option_t*)
368 // Overload this to add additional termination operations
371 AliWarning("Implement this in derived classes");
374 //_____________________________________________________________________________
375 Bool_t AliRsnVAnalysisTask::EventProcess()
378 // Performs some pre-processing of current event,
379 // which is useful for all the operations which
380 // need to be done only once for each event.
383 // in this case, return always a success
387 void AliRsnVAnalysisTask::SetupMixingEvents()
391 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
392 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
394 fMixedEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
396 AliMultiInputEventHandler *inEvHMainTmpMix = dynamic_cast<AliMultiInputEventHandler *>(fMixedEH->InputEventHandler(0));
397 if(!inEvHMainTmpMix) return;
398 AliInputEventHandler *inEvHMixTmp = dynamic_cast<AliInputEventHandler *>(inEvHMainTmpMix->GetFirstInputEventHandler());
399 AliMCEventHandler *inEvHMCMixTmp = dynamic_cast<AliMCEventHandler *>(inEvHMainTmpMix->GetFirstMCEventHandler());
400 if(!inEvHMixTmp) return;
401 fESDEvent[1] = dynamic_cast<AliESDEvent *>(inEvHMixTmp->GetEvent());
402 if (fESDEvent[1]) AliDebug(AliLog::kDebug,Form("Input is ESD (%p) MIXED", fESDEvent[1]));
403 // getting AliAODEvent from input
404 fAODEventIn[1] = dynamic_cast<AliAODEvent *>(inEvHMixTmp->GetEvent());
405 if (fAODEventIn[1]) AliDebug(AliLog::kDebug,Form("Input is AOD (%p) MIXED", fAODEventIn[1]));
406 // getting AliAODEvent if it is output from previous task (not supported)
410 fMCEvent[1] = inEvHMCMixTmp->MCEvent();
411 if (fMCEvent[1]) AliDebug(AliLog::kDebug,Form("Input is ESDMC (%p) MIXED", fMCEvent[1]));
419 //_____________________________________________________________________________
420 void AliRsnVAnalysisTask::SetDebugForAllClasses()
423 // Set debug level for all classes for which it is required
426 TObjArray *array = fLogClassesString.Tokenize(":");
429 Int_t i, n = array->GetEntriesFast();
431 for (i = 0; i < n; i++)
433 objStr = (TObjString*)array->At(i);
434 str = objStr->GetString();
435 AliLog::SetClassDebugLevel(str.Data(), fLogType);
436 AliInfo(Form("Setting Debug to %s", str.Data()));