]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnVAnalysisTaskSE.cxx
bugfix
[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 "AliRsnVAnalysisTaskSE.h"
12
13 #include "AliESDEvent.h"
14 #include "AliMCEvent.h"
15 #include "AliAODEvent.h"
16
17 ClassImp(AliRsnVAnalysisTaskSE)
18
19 //_____________________________________________________________________________
20 AliRsnVAnalysisTaskSE::AliRsnVAnalysisTaskSE
21 (const char *name, Bool_t mcOnly) :
22   AliAnalysisTaskSE(name),
23   fLogType(AliLog::kInfo),
24   fLogClassesString(""),
25   fESDEvent(0x0),
26   fMCEvent(0x0),
27   fAODEventIn(0x0),
28   fAODEventOut(0x0),
29   fMCOnly(mcOnly),
30   fRsnEvent(),
31   fInfoList(0x0),
32   fTaskInfo(name)
33 {
34 //
35 // Default constructor.
36 // Define the output slot for histograms.
37 //
38
39   AliDebug(AliLog::kDebug+2,"<-");
40
41   DefineOutput(1, TList::Class());
42   DefineOutput(2, TList::Class());
43
44   AliDebug(AliLog::kDebug+2,"->");
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   AliDebug(AliLog::kDebug+2, "<-");
67   AliDebug(AliLog::kDebug+2, "->");
68 }
69
70 //_____________________________________________________________________________
71 void AliRsnVAnalysisTaskSE::LocalInit()
72 {
73 //
74 // Local initialization.
75 // Defines the debug message level and calls the mother class LocalInit().
76 //
77
78   SetDebugForAllClasses();
79
80   AliDebug(AliLog::kDebug+2, "<-");
81   AliAnalysisTaskSE::LocalInit();
82   AliDebug(AliLog::kDebug+2, "->");
83 }
84
85 //_____________________________________________________________________________
86 Bool_t AliRsnVAnalysisTaskSE::Notify()
87 {
88 //
89 // Calls the mother class Notify()
90 //
91
92   AliDebug(AliLog::kDebug+2,"<-");
93   AliDebug(AliLog::kDebug+2,"->");
94
95   return AliAnalysisTaskSE::Notify();
96 }
97
98 //_____________________________________________________________________________
99 void AliRsnVAnalysisTaskSE::ConnectInputData(Option_t *opt)
100 {
101 //
102 // Connect input data.
103 // Links the data member pointers to any possible AliVEvenb input
104 // to the appropriate object belonging to the mother class,
105 // for a fast retrieval of informations from it through the
106 // data interface classes provided in this package.
107 // Makes use of dynamic_cast, in order to know the kind of input
108 // just checking if the casted pointers are NULL or not.
109 //
110
111   AliDebug(AliLog::kDebug+2,"<-");
112   AliAnalysisTaskSE::ConnectInputData(opt);
113
114   // getting AliESDEvent
115   fESDEvent = dynamic_cast<AliESDEvent *>(fInputEvent);
116
117   if (fESDEvent) {
118     AliInfo(Form("Input is ESD (%p)", fESDEvent));
119
120     // getting AliMCEvent
121     fMCEvent = (AliMCEvent*) MCEvent();
122     if (fMCEvent) AliInfo(Form("Input is MC (%p)", fMCEvent));
123   }
124
125   // getting AliAODEvent from input
126   fAODEventIn = dynamic_cast<AliAODEvent *>(fInputEvent);
127   if (fAODEventIn) AliInfo(Form("Input is AOD INPUT (%p)",fAODEventIn));
128
129   // getting AliAODEvent if it is output from previous task
130   fAODEventOut = dynamic_cast<AliAODEvent *>(AODEvent());
131   if (fAODEventOut) AliInfo(Form("Input is AOD OUTPUT (%p)",fAODEventOut));
132
133   AliDebug(AliLog::kDebug+2,"->");
134 }
135
136 //_____________________________________________________________________________
137 void AliRsnVAnalysisTaskSE::RsnUserCreateOutputObjects()
138 {
139 //
140 // Define here all instructions to create output objects.
141 // This method will be called inside the "UserCreateOutputObjects"
142 // in the used task.
143 //
144
145   AliDebug(AliLog::kDebug+2,"<-");
146   AliDebug(AliLog::kDebug+2,"->");
147 }
148
149 //_____________________________________________________________________________
150 void AliRsnVAnalysisTaskSE::UserCreateOutputObjects()
151 {
152 //
153 // Creates and links to task all output objects.
154 // They are all stored inside a unique TList which will be saved
155 // in output slot #1.
156 //
157
158   SetDebugForAllClasses();
159
160   AliDebug(AliLog::kDebug+2, "<-");
161
162   fInfoList = new TList();
163   fInfoList->SetOwner();
164   fTaskInfo.GenerateInfoList(fInfoList);
165   RsnUserCreateOutputObjects();
166
167   PostData(1, fInfoList);
168
169   AliDebug(AliLog::kDebug+2,"<-");
170 }
171
172 //_____________________________________________________________________________
173 void AliRsnVAnalysisTaskSE::UserExec(Option_t* opt)
174 {
175 //
176 //
177 //
178
179   AliDebug(AliLog::kDebug+2,"<-");
180
181   // sets properly the RSN package event interface:
182   // if an ESD event is available, it has priority,
183   // otherwise the AOD event is used;
184   // if the MC information is available, it is linked
185   if (fMCOnly && fMCEvent)
186     fRsnEvent.SetRef(fMCEvent, fMCEvent);
187   else if (fESDEvent)
188     fRsnEvent.SetRef(fESDEvent, fMCEvent);
189   else if (fAODEventOut)
190     fRsnEvent.SetRef(fAODEventOut);
191   else if (fAODEventIn)
192     fRsnEvent.SetRef(fAODEventIn);
193   else {
194     AliError("NO ESD or AOD object!!! Skipping ...");
195     return;
196   }
197
198   RsnUserExec(opt);
199
200   FillInfo();
201
202   fTaskInfo.PrintInfo(fTaskInfo.GetNumerOfEventsProcessed());
203
204   PostData(1, fInfoList);
205
206   AliDebug(AliLog::kDebug+2,"->");
207 }
208
209 //_____________________________________________________________________________
210 void AliRsnVAnalysisTaskSE::RsnUserExec(Option_t*)
211 {
212 //
213 //
214 //
215
216   if (fESDEvent) {
217     AliDebug(AliLog::kDebug+1, Form("fESDEvent is %p", fESDEvent));
218     AliDebug(AliLog::kDebug,   Form("ESD tracks %d", fESDEvent->GetNumberOfTracks()));
219   }
220   if (fMCEvent) {
221     AliDebug(AliLog::kDebug+1, Form("fMCEvent is %p", fMCEvent));
222     AliDebug(AliLog::kDebug,   Form("MC tracks %d", fMCEvent->GetNumberOfTracks()));
223   }
224   if (fAODEventIn) {
225     AliDebug(AliLog::kDebug+1, Form("fAODEventIn is %p", fAODEventIn));
226     AliDebug(AliLog::kDebug,   Form("AOD (in) tracks %d", fAODEventIn->GetNumberOfTracks()));
227   }
228
229   if (fAODEventOut) {
230     AliDebug(AliLog::kDebug+1, Form("fAODEventOut if %p", fAODEventOut));
231     AliDebug(AliLog::kDebug,   Form("AOD (out) tracks %d", fAODEventOut->GetNumberOfTracks()));
232   }
233 }
234
235 //_____________________________________________________________________________
236 void AliRsnVAnalysisTaskSE::Terminate(Option_t* opt)
237 {
238 //
239 // Termination routines.
240 // Stores all histograms (after checking they exist)
241 // and includes to the TList all task informations.
242 //
243
244   AliDebug(AliLog::kDebug+2,"<-");
245   AliAnalysisTask::Terminate();
246
247   TList* list  = dynamic_cast<TList*>(GetOutputData(1));
248   if (!list) {
249     AliError(Form("At end of analysis, fOutList is %p", list));
250     return;
251   }
252
253   RsnTerminate(opt);
254
255   TH1I *hEventInfo = (TH1I*) list->FindObject(fTaskInfo.GetEventHistogramName());
256   if (!hEventInfo) {
257     AliError(Form("hEventInfo is %p",hEventInfo));
258     return;
259   }
260
261   AliInfo(Form("=== %s ==================",GetName()));
262   AliInfo(Form("Number Of Events Processed : %10d",(Long64_t)hEventInfo->Integral()));
263   AliInfo(Form("Number Of Events Accepted  : %10d",(Long64_t)hEventInfo->GetBinContent(2)));
264   AliInfo(Form("Number Of Events Skipped   : %10d",(Long64_t)hEventInfo->GetBinContent(1)));
265   AliInfo(Form("=== end %s ==============",GetName()));
266
267   AliDebug(AliLog::kDebug+2, "->");
268 }
269
270 //_____________________________________________________________________________
271 void AliRsnVAnalysisTaskSE::RsnTerminate(Option_t*)
272 {
273 //
274 // Overload this to add additional termination operations
275 //
276
277   AliDebug(AliLog::kDebug+2, "<-");
278   AliDebug(AliLog::kDebug+2, "->");
279 }
280
281 //_____________________________________________________________________________
282 void AliRsnVAnalysisTaskSE::FillInfo()
283 {
284 //
285 // Fill information object with statistics of analysis
286 //
287
288   AliDebug(AliLog::kDebug+2, "<-");
289
290   fTaskInfo.FillInfo();
291
292   AliDebug(AliLog::kDebug+2,"->");
293 }
294
295 //_____________________________________________________________________________
296 void AliRsnVAnalysisTaskSE::SetLogType(AliLog::EType_t type, TString allClasses)
297 {
298 //
299 // Set Log level for this and other classes (list of their names)
300 //
301
302   AliDebug(AliLog::kDebug+2,"<-");
303   fLogType = type;
304   fLogClassesString = allClasses;
305   AliDebug(AliLog::kDebug+2,"->");
306 }
307
308 //_____________________________________________________________________________
309 void AliRsnVAnalysisTaskSE::SetDebugForAllClasses()
310 {
311 //
312 // Set debug level for all classes for which it is required
313 //
314
315   AliDebug(AliLog::kDebug+2, "<-");
316   TObjArray* array = fLogClassesString.Tokenize(":");
317   TObjString *str;
318   TString strr;
319   for (Int_t i=0;i< array->GetEntriesFast();i++) {
320     str = (TObjString *) array->At(i);
321     strr = str->GetString();
322     AliLog::SetClassDebugLevel(strr.Data(), fLogType);
323     AliInfo(Form("Setting Debug to %s",strr.Data()));
324   }
325   AliDebug(AliLog::kDebug+2,"->");
326 }
327