]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnVAnalysisTask.cxx
New analysis task objects with the capability to do mixing
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnVAnalysisTask.cxx
CommitLineData
1c7bc43c 1//
2// Class AliRsnVAnalysisTask
3//
4// Virtual Class derivated from AliAnalysisTaskSE which will be base class
5// for all RSN SE tasks
6//
7// authors: Martin Vala (martin.vala@cern.ch)
8// Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
9//
10
11#include <Riostream.h>
12
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"
20
21
22#include "AliRsnEvent.h"
23#include "AliRsnTarget.h"
24
25#include "AliRsnVAnalysisTask.h"
26
27ClassImp(AliRsnVAnalysisTask)
28
29//_____________________________________________________________________________
30AliRsnVAnalysisTask::AliRsnVAnalysisTask
31(const char *name, Bool_t mcOnly) :
32 AliAnalysisTaskSE(name),
33 fLogType(AliLog::kInfo),
34 fLogClassesString(""),
35 fIsMixing(kFALSE),
36 fMCOnly(mcOnly),
37 fInfoList(0x0),
38 fTaskInfo(name),
39 fMixedEH(0)
40{
41//
42// Default constructor.
43// Define the output slot for histograms.
44//
45
46 DefineOutput(1, TList::Class());
47 DefineOutput(2, TList::Class());
48 for(Int_t i=0;i<2;i++) {
49 fESDEvent[i] = 0;
50 fMCEvent[i]=0;
51 fAODEventIn[i]=0;
52 fAODEventOut[i]=0;
53 }
54}
55
56//_____________________________________________________________________________
57AliRsnVAnalysisTask::AliRsnVAnalysisTask(const AliRsnVAnalysisTask& copy) :
58 AliAnalysisTaskSE(copy),
59 fLogType(copy.fLogType),
60 fLogClassesString(copy.fLogClassesString),
61 fIsMixing(copy.fIsMixing),
62 fMCOnly(copy.fMCOnly),
63 fInfoList(0x0),
64 fTaskInfo(copy.fTaskInfo),
65 fMixedEH(copy.fMixedEH)
66{
67//
68// Copy constructor.
69// Defined for coding conventions compliance but never used.
70//
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];
78 }
79 AliDebug(AliLog::kDebug+2, "->");
80
81}
82
83//_____________________________________________________________________________
84void AliRsnVAnalysisTask::LocalInit()
85{
86//
87// Local initialization.
88// Defines the debug message level and calls the mother class LocalInit().
89//
90
91 AliAnalysisTaskSE::LocalInit();
92 SetDebugForAllClasses();
93}
94
95//_____________________________________________________________________________
96Bool_t AliRsnVAnalysisTask::UserNotify()
97{
98//
99// Calls the mother class Notify()
100//
101
102 return AliAnalysisTaskSE::UserNotify();
103}
104
105//_____________________________________________________________________________
106void AliRsnVAnalysisTask::ConnectInputData(Option_t *opt)
107{
108//
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.
113//
114
115 AliAnalysisTaskSE::ConnectInputData(opt);
116
117 // get AliESDEvent and, if successful
118 // retrieve the corresponding MC if exists
119 fESDEvent[0] = dynamic_cast<AliESDEvent *>(fInputEvent);
120 if (fESDEvent[0])
121 {
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]));
125 }
126
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);
130 if (fAODEventIn[0])
131 {
132 AliInfo(Form("Input event if of type native AOD (%p)", fAODEventIn[0]));
133 }
134
135 // get AliAODEvent from output of previous task
136 fAODEventOut[0] = dynamic_cast<AliAODEvent *>(AODEvent());
137 if (fAODEventOut[0])
138 {
139 AliInfo(Form("Input event if of type produced AOD from previous step (%p)",fAODEventOut[0]));
140 }
141}
142
143//_____________________________________________________________________________
144void AliRsnVAnalysisTask::UserCreateOutputObjects()
145{
146//
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.
151//
152
153 SetDebugForAllClasses();
154
155 // set event info outputs
156 fInfoList = new TList();
157 fInfoList->SetOwner();
158 fTaskInfo.GenerateInfoList(fInfoList);
159
160 // create customized outputs
161 RsnUserCreateOutputObjects();
162
163 PostData(1, fInfoList);
164}
165
166//_____________________________________________________________________________
167void AliRsnVAnalysisTask::UserExec(Option_t* opt)
168{
169//
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().
173//
174 if (!IsMixing()) {
175 if (fMCOnly && fMCEvent)
176 {
177 fRsnEvent[0].SetRef (fMCEvent[0]);
178 fRsnEvent[0].SetRefMC(fMCEvent[0]);
179 }
180 else if (fESDEvent[0])
181 {
182 fRsnEvent[0].SetRef (fESDEvent[0]);
183 fRsnEvent[0].SetRefMC(fMCEvent[0]);
184 }
185 else if (fAODEventOut)
186 {
187 fRsnEvent[0].SetRef (fAODEventOut[0]);
188 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
189 }
190 else if (fAODEventIn)
191 {
192 fRsnEvent[0].SetRef (fAODEventIn[0]);
193 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
194 }
195 else
196 {
197 AliError("Unknown input event format. Skipping");
198 return;
199 }
200
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();
207
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
214 if (!preCheck)
215 {
216 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
217 return;
218 }
219
220
221 // call customized implementation for execution
222 RsnUserExec(opt);
223 }
224 // post outputs for the info object
225 // (eventually others are done in the derived classes)
226 PostData(1, fInfoList);
227}
228
229void AliRsnVAnalysisTask::UserExecMix(Option_t* option)
230{
231 AliDebug(AliLog::kDebug+2,"<-");
232
233
234 if (!IsMixing()) return;
235
236 SetupMixingEvents();
237
238 if (!fMixedEH) return;
239
240 if (fMCOnly && fMCEvent[0])
241 {
242 fRsnEvent[0].SetRef (fMCEvent[0]);
243 fRsnEvent[0].SetRefMC(fMCEvent[0]);
244 fRsnEvent[1].SetRef (fMCEvent[1]);
245 fRsnEvent[1].SetRefMC(fMCEvent[1]);
246 }
247 else if (fESDEvent[0])
248 {
249 fRsnEvent[0].SetRef (fESDEvent[0]);
250 fRsnEvent[0].SetRefMC(fMCEvent[0]);
251 fRsnEvent[1].SetRef (fESDEvent[1]);
252 fRsnEvent[1].SetRefMC(fMCEvent[1]);
253 }
254 else if (fAODEventOut)
255 {
256 fRsnEvent[0].SetRef (fAODEventOut[0]);
257 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
258 fRsnEvent[1].SetRef (fAODEventOut[1]);
259 fRsnEvent[1].SetRefMC(fAODEventOut[1]);
260 }
261 else if (fAODEventIn)
262 {
263 fRsnEvent[0].SetRef (fAODEventIn[0]);
264 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
265 fRsnEvent[1].SetRef (fAODEventIn[1]);
266 fRsnEvent[1].SetRefMC(fAODEventIn[1]);
267 }
268 else {
269 AliError("NO ESD or AOD object!!! Skipping ...");
270 return;
271 }
272 // since this class is for single-event analysis
273 // both static pointers of AliRsnEvent class
274 // will point to the same unique datamember
275
276
277 AliRsnEvent::SetCurrentEvent1(&fRsnEvent[0], fMixedEH->CurrentEntryMain());
278 AliRsnEvent::SetCurrentEvent2(&fRsnEvent[1], fMixedEH->CurrentEntryMix());
279 AliRsnTarget::SwitchToFirst();
280
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
287 if (!preCheck)
288 {
289 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
290 return;
291 }
292
293 RsnUserExecMix(option);
294 AliDebug(AliLog::kDebug+2,"->");
295}
296
297
298//_____________________________________________________________________________
299void AliRsnVAnalysisTask::Terminate(Option_t* opt)
300{
301//
302// Termination routines.
303// Stores all histograms (after checking they exist)
304// and includes to the TList all task informations.
305//
306
307 AliAnalysisTask::Terminate();
308
309 TList* list = dynamic_cast<TList*>(GetOutputData(1));
310 if (!list)
311 {
312 AliError(Form("At end of analysis, fOutList is %p", list));
313 return;
314 }
315
316 RsnTerminate(opt);
317
318 TH1I *hEventInfo = (TH1I*) list->FindObject(fTaskInfo.GetEventHistogramName());
319 if (!hEventInfo)
320 {
321 AliError(Form("hEventInfo is %p", hEventInfo));
322 return;
323 }
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()));
329
330 AliDebug(AliLog::kDebug+2, "->");
331}
332
333//_____________________________________________________________________________
334void AliRsnVAnalysisTask::RsnUserCreateOutputObjects()
335{
336//
337// Define here all instructions to create output objects.
338// This method will be called inside the "UserCreateOutputObjects"
339// in the used task.
340//
341
342 AliWarning("Implement this in derived classes");
343}
344
345//_____________________________________________________________________________
346void AliRsnVAnalysisTask::RsnUserExec(Option_t*)
347{
348//
349//
350//
351
352 AliWarning("Implement this in derived classes");
353}
354
355void AliRsnVAnalysisTask::RsnUserExecMix(Option_t* )
356{
357 //
358 //
359 //
360
361 AliWarning("Implement this in derived classes");
362}
363
364//_____________________________________________________________________________
365void AliRsnVAnalysisTask::RsnTerminate(Option_t*)
366{
367//
368// Overload this to add additional termination operations
369//
370
371 AliWarning("Implement this in derived classes");
372}
373
374//_____________________________________________________________________________
375Bool_t AliRsnVAnalysisTask::EventProcess()
376{
377//
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.
381//
382
383 // in this case, return always a success
384 return kTRUE;
385}
386
387void AliRsnVAnalysisTask::SetupMixingEvents()
388{
389 // mixing setup
390
391 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
392 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
393 if(inEvHMain) {
394 fMixedEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
395 if(fMixedEH) {
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)
407 fAODEventOut[1] = 0;
408
409 if(inEvHMCMixTmp) {
410 fMCEvent[1] = inEvHMCMixTmp->MCEvent();
411 if (fMCEvent[1]) AliDebug(AliLog::kDebug,Form("Input is ESDMC (%p) MIXED", fMCEvent[1]));
412 }
413
414 }
415
416 }
417}
418
419//_____________________________________________________________________________
420void AliRsnVAnalysisTask::SetDebugForAllClasses()
421{
422//
423// Set debug level for all classes for which it is required
424//
425
426 TObjArray *array = fLogClassesString.Tokenize(":");
427 TObjString *objStr;
428 TString str;
429 Int_t i, n = array->GetEntriesFast();
430
431 for (i = 0; i < n; i++)
432 {
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()));
437 }
438}
439