]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnVAnalysisTaskSE.cxx
Macro to add the energy distribution task to the train
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnVAnalysisTaskSE.cxx
1 //
2 // Class AliRsnVAnalysisTaskSE
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 "AliRsnEvent.h"
17 #include "AliRsnTarget.h"
18
19 #include "AliRsnVAnalysisTaskSE.h"
20
21 ClassImp(AliRsnVAnalysisTaskSE)
22
23 //_____________________________________________________________________________
24 AliRsnVAnalysisTaskSE::AliRsnVAnalysisTaskSE
25 (const char *name, Bool_t mcOnly) :
26   AliAnalysisTaskSE(name),
27   fLogType(AliLog::kInfo),
28   fLogClassesString(""),
29   fESDEvent(0x0),
30   fMCEvent(0x0),
31   fAODEventIn(0x0),
32   fAODEventOut(0x0),
33   fMCOnly(mcOnly),
34   fRsnEvent(),
35   fInfoList(0x0),
36   fTaskInfo(name)
37 {
38 //
39 // Default constructor.
40 // Define the output slot for histograms.
41 //
42
43   DefineOutput(1, TList::Class());
44   DefineOutput(2, TList::Class());
45 }
46
47 //_____________________________________________________________________________
48 AliRsnVAnalysisTaskSE::AliRsnVAnalysisTaskSE(const AliRsnVAnalysisTaskSE& copy) :
49   AliAnalysisTaskSE(copy),
50   fLogType(copy.fLogType),
51   fLogClassesString(copy.fLogClassesString),
52   fESDEvent(copy.fESDEvent),
53   fMCEvent(copy.fMCEvent),
54   fAODEventIn(copy.fAODEventIn),
55   fAODEventOut(copy.fAODEventOut),
56   fMCOnly(copy.fMCOnly),
57   fRsnEvent(),
58   fInfoList(0x0),
59   fTaskInfo(copy.fTaskInfo)
60 {
61 //
62 // Copy constructor.
63 // Defined for coding conventions compliance but never used.
64 //
65 }
66
67 //_____________________________________________________________________________
68 void AliRsnVAnalysisTaskSE::LocalInit()
69 {
70 //
71 // Local initialization.
72 // Defines the debug message level and calls the mother class LocalInit().
73 //
74
75   AliAnalysisTaskSE::LocalInit();
76   SetDebugForAllClasses();
77 }
78
79 //_____________________________________________________________________________
80 Bool_t AliRsnVAnalysisTaskSE::UserNotify()
81 {
82 //
83 // Calls the mother class Notify()
84 //
85
86   return AliAnalysisTaskSE::UserNotify();
87 }
88
89 //_____________________________________________________________________________
90 void AliRsnVAnalysisTaskSE::ConnectInputData(Option_t *opt)
91 {
92 //
93 // Connect input data, which consist in initializing properly
94 // the pointer to the input event, which is dynamically casted
95 // to all available types, and this allows to know its type.
96 // Calls also the mother class omonyme method.
97 // 
98
99   AliAnalysisTaskSE::ConnectInputData(opt);
100
101   // get AliESDEvent and, if successful
102   // retrieve the corresponding MC if exists
103   fESDEvent = dynamic_cast<AliESDEvent *>(fInputEvent);
104   if (fESDEvent)
105   {
106     fMCEvent = (AliMCEvent*) MCEvent();
107     AliInfo(Form("Input event is of type ESD   (%p)", fESDEvent));
108     if (fMCEvent) AliInfo(Form("Input has an associated MC (%p)", fMCEvent));
109   }
110
111   // get AliAODEvent from input and, if successful
112   // it will contain both the reconstructed and MC informations
113   fAODEventIn = dynamic_cast<AliAODEvent *>(fInputEvent);
114   if (fAODEventIn)
115   {
116     AliInfo(Form("Input event if of type native AOD (%p)", fAODEventIn));
117   }
118
119   // get AliAODEvent from output of previous task
120   fAODEventOut = dynamic_cast<AliAODEvent *>(AODEvent());
121   if (fAODEventOut)
122   {
123     AliInfo(Form("Input event if of type produced AOD from previous step (%p)",fAODEventOut));
124   }
125 }
126
127 //_____________________________________________________________________________
128 void AliRsnVAnalysisTaskSE::UserCreateOutputObjects()
129 {
130 //
131 // Creates and links to task all output objects.
132 // Does explicitly the initialization for the event info class,
133 // and then calls the customized function which must be overloaded
134 // in the applications of this base class.
135 //
136
137   SetDebugForAllClasses();
138
139   // set event info outputs
140   fInfoList = new TList();
141   fInfoList->SetOwner();
142   fTaskInfo.GenerateInfoList(fInfoList);
143   
144   // create customized outputs
145   RsnUserCreateOutputObjects();
146
147   PostData(1, fInfoList);
148 }
149
150 //_____________________________________________________________________________
151 void AliRsnVAnalysisTaskSE::UserExec(Option_t* opt)
152 {
153 //
154 // Prepares for execution, setting the correct pointers of the
155 // RSN package event interface, which will point to the not NULL
156 // objects obtained from dynamic-casts called in ConnectInputData().
157 //
158
159   if (fMCOnly && fMCEvent)
160   {
161     fRsnEvent.SetRef  (fMCEvent);
162     fRsnEvent.SetRefMC(fMCEvent);
163   }
164   else if (fESDEvent)
165   {
166     fRsnEvent.SetRef  (fESDEvent);
167     fRsnEvent.SetRefMC(fMCEvent);
168   }
169   else if (fAODEventOut)
170   {
171     fRsnEvent.SetRef  (fAODEventOut);
172     fRsnEvent.SetRefMC(fAODEventOut);
173   }
174   else if (fAODEventIn)
175   {
176     fRsnEvent.SetRef  (fAODEventIn);
177     fRsnEvent.SetRefMC(fAODEventIn);
178   }
179   else 
180   {
181     AliError("Unknown input event format. Skipping");
182     return;
183   }
184
185   // since this class is for single-event analysis
186   // both static pointers of AliRsnEvent class 
187   // will point to the same unique datamember
188   AliRsnEvent::SetCurrentEvent1(&fRsnEvent, fEntry);
189   AliRsnEvent::SetCurrentEvent2(&fRsnEvent, fEntry);
190   AliRsnTarget::SwitchToFirst();
191   
192   // call event preprocessing...
193   Bool_t preCheck = EventProcess();
194   // ...then fill the information object and print informations...
195   fTaskInfo.FillInfo();
196   fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
197   // ...and return if event did not pass selections
198   if (!preCheck)
199   {
200     AliDebug(AliLog::kDebug, "Event preprocessing has failed. Skipping event");
201     return;
202   }
203   
204   
205   // call customized implementation for execution
206   RsnUserExec(opt);
207   
208   // post outputs for the info object
209   // (eventually others are done in the derived classes)
210   PostData(1, fInfoList);
211 }
212
213 //_____________________________________________________________________________
214 void AliRsnVAnalysisTaskSE::Terminate(Option_t* opt)
215 {
216 //
217 // Termination routines.
218 // Stores all histograms (after checking they exist)
219 // and includes to the TList all task informations.
220 //
221
222   AliAnalysisTask::Terminate();
223
224   TList* list  = dynamic_cast<TList*>(GetOutputData(1));
225   if (!list) 
226   {
227     AliError(Form("At end of analysis, fOutList is %p", list));
228     return;
229   }
230
231   RsnTerminate(opt);
232
233   TH1I *hEventInfo = (TH1I*) list->FindObject(fTaskInfo.GetEventHistogramName());
234   if (!hEventInfo) 
235   {
236     AliError(Form("hEventInfo is %p", hEventInfo));
237     return;
238   }
239   AliInfo(Form("=== %s ==================",GetName()));
240   AliInfo(Form("Number Of Events Processed : %10lld",(Long64_t)hEventInfo->Integral()));
241   AliInfo(Form("Number Of Events Accepted  : %10lld",(Long64_t)hEventInfo->GetBinContent(2)));
242   AliInfo(Form("Number Of Events Skipped   : %10lld",(Long64_t)hEventInfo->GetBinContent(1)));
243   AliInfo(Form("=== end %s ==============",GetName()));
244
245   AliDebug(AliLog::kDebug+2, "->");
246 }
247
248 //_____________________________________________________________________________
249 void AliRsnVAnalysisTaskSE::RsnUserCreateOutputObjects()
250 {
251 //
252 // Define here all instructions to create output objects.
253 // This method will be called inside the "UserCreateOutputObjects"
254 // in the used task.
255 //
256
257   AliWarning("Implement this in derived classes");
258 }
259
260 //_____________________________________________________________________________
261 void AliRsnVAnalysisTaskSE::RsnUserExec(Option_t*)
262 {
263 //
264 //
265 //
266
267   AliWarning("Implement this in derived classes");
268 }
269
270 //_____________________________________________________________________________
271 void AliRsnVAnalysisTaskSE::RsnTerminate(Option_t*)
272 {
273 //
274 // Overload this to add additional termination operations
275 //
276
277   AliWarning("Implement this in derived classes");
278 }
279
280 //_____________________________________________________________________________
281 Bool_t AliRsnVAnalysisTaskSE::EventProcess()
282 {
283 //
284 // Performs some pre-processing of current event,
285 // which is useful for all the operations which 
286 // need to be done only once for each event.
287 //
288   
289   // in this case, return always a success
290   return kTRUE;
291 }
292
293 //_____________________________________________________________________________
294 void AliRsnVAnalysisTaskSE::SetDebugForAllClasses()
295 {
296 //
297 // Set debug level for all classes for which it is required
298 //
299
300   TObjArray  *array = fLogClassesString.Tokenize(":");
301   TObjString *objStr;
302   TString     str;
303   Int_t       i, n = array->GetEntriesFast();
304   
305   for (i = 0; i < n; i++)
306   {
307     objStr = (TObjString*)array->At(i);
308     str    = objStr->GetString();
309     AliLog::SetClassDebugLevel(str.Data(), fLogType);
310     AliInfo(Form("Setting Debug to %s", str.Data()));
311   }
312 }
313