]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnVAnalysisTask.cxx
add possibility to smear cluster energy, only for MC, some stetic changes in header...
[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),
0294bbe8 39 fMixedEH(0),
40 fUseMixingRange(kTRUE)
1c7bc43c 41{
42//
43// Default constructor.
44// Define the output slot for histograms.
45//
46
47 DefineOutput(1, TList::Class());
48 DefineOutput(2, TList::Class());
49 for(Int_t i=0;i<2;i++) {
50 fESDEvent[i] = 0;
51 fMCEvent[i]=0;
52 fAODEventIn[i]=0;
53 fAODEventOut[i]=0;
54 }
55}
56
57//_____________________________________________________________________________
58AliRsnVAnalysisTask::AliRsnVAnalysisTask(const AliRsnVAnalysisTask& copy) :
59 AliAnalysisTaskSE(copy),
60 fLogType(copy.fLogType),
61 fLogClassesString(copy.fLogClassesString),
62 fIsMixing(copy.fIsMixing),
63 fMCOnly(copy.fMCOnly),
64 fInfoList(0x0),
65 fTaskInfo(copy.fTaskInfo),
0294bbe8 66 fMixedEH(copy.fMixedEH),
67 fUseMixingRange(copy.fUseMixingRange)
1c7bc43c 68{
69//
70// Copy constructor.
71// Defined for coding conventions compliance but never used.
72//
73 AliDebug(AliLog::kDebug+2, "<-");
74 for(Int_t i=0;i<2;i++) {
75 fESDEvent[i] = copy.fESDEvent[i];
76 fMCEvent[i]=copy.fMCEvent[i];
77 fAODEventIn[i]=copy.fAODEventIn[i];
78 fAODEventOut[i]=copy.fAODEventOut[i];
79 fRsnEvent[i]=copy.fRsnEvent[i];
80 }
81 AliDebug(AliLog::kDebug+2, "->");
82
83}
84
85//_____________________________________________________________________________
86void AliRsnVAnalysisTask::LocalInit()
87{
88//
89// Local initialization.
90// Defines the debug message level and calls the mother class LocalInit().
91//
92
93 AliAnalysisTaskSE::LocalInit();
94 SetDebugForAllClasses();
95}
96
97//_____________________________________________________________________________
98Bool_t AliRsnVAnalysisTask::UserNotify()
99{
100//
101// Calls the mother class Notify()
102//
103
104 return AliAnalysisTaskSE::UserNotify();
105}
106
107//_____________________________________________________________________________
108void AliRsnVAnalysisTask::ConnectInputData(Option_t *opt)
109{
110//
111// Connect input data, which consist in initializing properly
112// the pointer to the input event, which is dynamically casted
113// to all available types, and this allows to know its type.
114// Calls also the mother class omonyme method.
115//
116
117 AliAnalysisTaskSE::ConnectInputData(opt);
118
119 // get AliESDEvent and, if successful
120 // retrieve the corresponding MC if exists
121 fESDEvent[0] = dynamic_cast<AliESDEvent *>(fInputEvent);
122 if (fESDEvent[0])
123 {
124 fMCEvent[0] = (AliMCEvent*) MCEvent();
125 AliInfo(Form("Input event is of type ESD (%p)", fESDEvent[0]));
126 if (fMCEvent[0]) AliInfo(Form("Input has an associated MC (%p)", fMCEvent[0]));
127 }
128
129 // get AliAODEvent from input and, if successful
130 // it will contain both the reconstructed and MC informations
131 fAODEventIn[0] = dynamic_cast<AliAODEvent *>(fInputEvent);
132 if (fAODEventIn[0])
133 {
134 AliInfo(Form("Input event if of type native AOD (%p)", fAODEventIn[0]));
135 }
136
137 // get AliAODEvent from output of previous task
138 fAODEventOut[0] = dynamic_cast<AliAODEvent *>(AODEvent());
139 if (fAODEventOut[0])
140 {
141 AliInfo(Form("Input event if of type produced AOD from previous step (%p)",fAODEventOut[0]));
142 }
143}
144
145//_____________________________________________________________________________
146void AliRsnVAnalysisTask::UserCreateOutputObjects()
147{
148//
149// Creates and links to task all output objects.
150// Does explicitly the initialization for the event info class,
151// and then calls the customized function which must be overloaded
152// in the applications of this base class.
153//
154
155 SetDebugForAllClasses();
156
157 // set event info outputs
158 fInfoList = new TList();
159 fInfoList->SetOwner();
160 fTaskInfo.GenerateInfoList(fInfoList);
161
162 // create customized outputs
163 RsnUserCreateOutputObjects();
164
165 PostData(1, fInfoList);
166}
167
168//_____________________________________________________________________________
169void AliRsnVAnalysisTask::UserExec(Option_t* opt)
170{
171//
172// Prepares for execution, setting the correct pointers of the
173// RSN package event interface, which will point to the not NULL
174// objects obtained from dynamic-casts called in ConnectInputData().
175//
176 if (!IsMixing()) {
0294bbe8 177
178
1c7bc43c 179 if (fMCOnly && fMCEvent)
180 {
181 fRsnEvent[0].SetRef (fMCEvent[0]);
182 fRsnEvent[0].SetRefMC(fMCEvent[0]);
183 }
184 else if (fESDEvent[0])
185 {
186 fRsnEvent[0].SetRef (fESDEvent[0]);
187 fRsnEvent[0].SetRefMC(fMCEvent[0]);
188 }
189 else if (fAODEventOut)
190 {
191 fRsnEvent[0].SetRef (fAODEventOut[0]);
192 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
193 }
194 else if (fAODEventIn)
195 {
196 fRsnEvent[0].SetRef (fAODEventIn[0]);
197 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
198 }
199 else
200 {
201 AliError("Unknown input event format. Skipping");
202 return;
203 }
204
205 // since this class is for single-event analysis
206 // both static pointers of AliRsnEvent class
207 // will point to the same unique datamember
208 AliRsnEvent::SetCurrentEvent1(&fRsnEvent[0], fEntry);
209 AliRsnEvent::SetCurrentEvent2(&fRsnEvent[0], fEntry);
210 AliRsnTarget::SwitchToFirst();
211
212 // call event preprocessing...
213 Bool_t preCheck = EventProcess();
214 // ...then fill the information object and print informations...
215 fTaskInfo.FillInfo();
216 fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
217 // ...and return if event did not pass selections
218 if (!preCheck)
219 {
220 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
221 return;
222 }
223
224
225 // call customized implementation for execution
226 RsnUserExec(opt);
227 }
228 // post outputs for the info object
229 // (eventually others are done in the derived classes)
230 PostData(1, fInfoList);
231}
232
233void AliRsnVAnalysisTask::UserExecMix(Option_t* option)
234{
235 AliDebug(AliLog::kDebug+2,"<-");
236
237
238 if (!IsMixing()) return;
239
240 SetupMixingEvents();
241
242 if (!fMixedEH) return;
243
244 if (fMCOnly && fMCEvent[0])
245 {
246 fRsnEvent[0].SetRef (fMCEvent[0]);
247 fRsnEvent[0].SetRefMC(fMCEvent[0]);
248 fRsnEvent[1].SetRef (fMCEvent[1]);
249 fRsnEvent[1].SetRefMC(fMCEvent[1]);
250 }
251 else if (fESDEvent[0])
252 {
253 fRsnEvent[0].SetRef (fESDEvent[0]);
254 fRsnEvent[0].SetRefMC(fMCEvent[0]);
255 fRsnEvent[1].SetRef (fESDEvent[1]);
256 fRsnEvent[1].SetRefMC(fMCEvent[1]);
257 }
258 else if (fAODEventOut)
259 {
260 fRsnEvent[0].SetRef (fAODEventOut[0]);
261 fRsnEvent[0].SetRefMC(fAODEventOut[0]);
262 fRsnEvent[1].SetRef (fAODEventOut[1]);
263 fRsnEvent[1].SetRefMC(fAODEventOut[1]);
264 }
265 else if (fAODEventIn)
266 {
267 fRsnEvent[0].SetRef (fAODEventIn[0]);
268 fRsnEvent[0].SetRefMC(fAODEventIn[0]);
269 fRsnEvent[1].SetRef (fAODEventIn[1]);
270 fRsnEvent[1].SetRefMC(fAODEventIn[1]);
271 }
272 else {
273 AliError("NO ESD or AOD object!!! Skipping ...");
274 return;
275 }
276 // since this class is for single-event analysis
277 // both static pointers of AliRsnEvent class
278 // will point to the same unique datamember
279
280
281 AliRsnEvent::SetCurrentEvent1(&fRsnEvent[0], fMixedEH->CurrentEntryMain());
282 AliRsnEvent::SetCurrentEvent2(&fRsnEvent[1], fMixedEH->CurrentEntryMix());
283 AliRsnTarget::SwitchToFirst();
284
285 // call event preprocessing...
286 Bool_t preCheck = EventProcess();
287 // ...then fill the information object and print informations...
288 fTaskInfo.FillInfo();
289 fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
290 // ...and return if event did not pass selections
291 if (!preCheck)
292 {
293 AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
294 return;
295 }
296
297 RsnUserExecMix(option);
298 AliDebug(AliLog::kDebug+2,"->");
299}
300
301
302//_____________________________________________________________________________
303void AliRsnVAnalysisTask::Terminate(Option_t* opt)
304{
305//
306// Termination routines.
307// Stores all histograms (after checking they exist)
308// and includes to the TList all task informations.
309//
310
311 AliAnalysisTask::Terminate();
312
313 TList* list = dynamic_cast<TList*>(GetOutputData(1));
314 if (!list)
315 {
316 AliError(Form("At end of analysis, fOutList is %p", list));
317 return;
318 }
319
320 RsnTerminate(opt);
321
322 TH1I *hEventInfo = (TH1I*) list->FindObject(fTaskInfo.GetEventHistogramName());
323 if (!hEventInfo)
324 {
325 AliError(Form("hEventInfo is %p", hEventInfo));
326 return;
327 }
328 AliInfo(Form("=== %s ==================",GetName()));
329 AliInfo(Form("Number Of Events Processed : %10lld",(Long64_t)hEventInfo->Integral()));
330 AliInfo(Form("Number Of Events Accepted : %10lld",(Long64_t)hEventInfo->GetBinContent(2)));
331 AliInfo(Form("Number Of Events Skipped : %10lld",(Long64_t)hEventInfo->GetBinContent(1)));
332 AliInfo(Form("=== end %s ==============",GetName()));
333
334 AliDebug(AliLog::kDebug+2, "->");
335}
336
337//_____________________________________________________________________________
338void AliRsnVAnalysisTask::RsnUserCreateOutputObjects()
339{
340//
341// Define here all instructions to create output objects.
342// This method will be called inside the "UserCreateOutputObjects"
343// in the used task.
344//
345
346 AliWarning("Implement this in derived classes");
347}
348
349//_____________________________________________________________________________
350void AliRsnVAnalysisTask::RsnUserExec(Option_t*)
351{
352//
353//
354//
355
356 AliWarning("Implement this in derived classes");
357}
358
359void AliRsnVAnalysisTask::RsnUserExecMix(Option_t* )
360{
361 //
362 //
363 //
364
365 AliWarning("Implement this in derived classes");
366}
367
368//_____________________________________________________________________________
369void AliRsnVAnalysisTask::RsnTerminate(Option_t*)
370{
371//
372// Overload this to add additional termination operations
373//
374
375 AliWarning("Implement this in derived classes");
376}
377
378//_____________________________________________________________________________
379Bool_t AliRsnVAnalysisTask::EventProcess()
380{
381//
382// Performs some pre-processing of current event,
383// which is useful for all the operations which
384// need to be done only once for each event.
385//
386
0294bbe8 387 // if not using mixing cuts return kTRUE
388 if (!IsUsingMixingRange()) return kTRUE;
389
390 // cut if event was in range of mixing cuts
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 if (fMixedEH->CurrentBinIndex()<0) return kFALSE;
397 }
398
399 }
400
1c7bc43c 401 // in this case, return always a success
402 return kTRUE;
403}
404
405void AliRsnVAnalysisTask::SetupMixingEvents()
406{
407 // mixing setup
408
409 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
410 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
411 if(inEvHMain) {
412 fMixedEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
413 if(fMixedEH) {
414 AliMultiInputEventHandler *inEvHMainTmpMix = dynamic_cast<AliMultiInputEventHandler *>(fMixedEH->InputEventHandler(0));
415 if(!inEvHMainTmpMix) return;
416 AliInputEventHandler *inEvHMixTmp = dynamic_cast<AliInputEventHandler *>(inEvHMainTmpMix->GetFirstInputEventHandler());
417 AliMCEventHandler *inEvHMCMixTmp = dynamic_cast<AliMCEventHandler *>(inEvHMainTmpMix->GetFirstMCEventHandler());
418 if(!inEvHMixTmp) return;
419 fESDEvent[1] = dynamic_cast<AliESDEvent *>(inEvHMixTmp->GetEvent());
420 if (fESDEvent[1]) AliDebug(AliLog::kDebug,Form("Input is ESD (%p) MIXED", fESDEvent[1]));
421 // getting AliAODEvent from input
422 fAODEventIn[1] = dynamic_cast<AliAODEvent *>(inEvHMixTmp->GetEvent());
423 if (fAODEventIn[1]) AliDebug(AliLog::kDebug,Form("Input is AOD (%p) MIXED", fAODEventIn[1]));
424 // getting AliAODEvent if it is output from previous task (not supported)
425 fAODEventOut[1] = 0;
426
427 if(inEvHMCMixTmp) {
428 fMCEvent[1] = inEvHMCMixTmp->MCEvent();
429 if (fMCEvent[1]) AliDebug(AliLog::kDebug,Form("Input is ESDMC (%p) MIXED", fMCEvent[1]));
430 }
431
432 }
433
434 }
435}
436
437//_____________________________________________________________________________
438void AliRsnVAnalysisTask::SetDebugForAllClasses()
439{
440//
441// Set debug level for all classes for which it is required
442//
443
444 TObjArray *array = fLogClassesString.Tokenize(":");
445 TObjString *objStr;
446 TString str;
447 Int_t i, n = array->GetEntriesFast();
448
449 for (i = 0; i < n; i++)
450 {
451 objStr = (TObjString*)array->At(i);
452 str = objStr->GetString();
453 AliLog::SetClassDebugLevel(str.Data(), fLogType);
454 AliInfo(Form("Setting Debug to %s", str.Data()));
455 }
456}
457