]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnVAnalysisTaskME.cxx
Upgrades for setting up a working version of ME task
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnVAnalysisTaskME.cxx
1 //
2 // Class AliRsnVAnalysisTaskME
3 //
4 // Virtual Class derivated from AliAnalysisTaskME which will be base class
5 // for all RSN ME tasks
6 //
7 // authors: Martin Vala (martin.vala@cern.ch)
8 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
9 //
10
11 #include <TH1.h>
12 #include <AliLog.h>
13 #include "AliESDEvent.h"
14 #include "AliMCEvent.h"
15 #include "AliAODEvent.h"
16 #include "AliAODTrack.h"
17 #include "AliMultiEventInputHandler.h"
18 #include "AliRsnVAnalysisTaskME.h"
19
20 ClassImp(AliRsnVAnalysisTaskME)
21
22 //_____________________________________________________________________________
23 AliRsnVAnalysisTaskME::AliRsnVAnalysisTaskME(const char *name, Int_t numOfOutputs) :
24     AliAnalysisTaskME(name),
25     fLogType(AliLog::kInfo),
26     fLogClassesString(""),
27     fESDEvent(0x0),
28     fMCEvent(0x0),
29     fAODEvent(0x0),
30     fNumberOfOutputs(numOfOutputs),
31     fTaskInfo(name)
32 {
33 //
34 // Default constructor
35 //
36   AliDebug(AliLog::kDebug+2,"<-");
37
38   if (fNumberOfOutputs < 0) fNumberOfOutputs = 0;
39   if (fNumberOfOutputs > kMaxNumberOfOutputs) {
40     AliWarning(Form("We support only %d outputs. If you need more ask for it.", kMaxNumberOfOutputs));
41     AliWarning(Form("For now we are setting it to %d.", kMaxNumberOfOutputs));
42     fNumberOfOutputs = kMaxNumberOfOutputs;
43   }
44
45   DefineOutput(1, TList::Class());
46
47   AliDebug(AliLog::kDebug+2,"->");
48 }
49
50 AliRsnVAnalysisTaskME::AliRsnVAnalysisTaskME(const AliRsnVAnalysisTaskME& copy) : AliAnalysisTaskME(copy),
51     fLogType(copy.fLogType),
52     fLogClassesString(copy.fLogClassesString),
53     fESDEvent(copy.fESDEvent),
54     fMCEvent(copy.fMCEvent),
55     fAODEvent(copy.fAODEvent),
56     fTaskInfo(copy.fTaskInfo)
57 {
58   AliDebug(AliLog::kDebug+2,"<-");
59   AliDebug(AliLog::kDebug+2,"->");
60 }
61
62 //_____________________________________________________________________________
63 void AliRsnVAnalysisTaskME::LocalInit()
64 {
65 //
66 // LocalInit()
67 //
68
69   SetDebugForAllClasses();
70   AliDebug(AliLog::kDebug+2,"<-");
71   AliAnalysisTaskME::LocalInit();
72   AliDebug(AliLog::kDebug+2,"->");
73 }
74
75 //_____________________________________________________________________________
76 Bool_t AliRsnVAnalysisTaskME::Notify()
77 {
78 //
79 // Notify()
80 //
81
82   AliDebug(AliLog::kDebug+2,"<-");
83   if (!AliAnalysisTaskME::Notify()) return kFALSE;
84   AliDebug(AliLog::kDebug+2,"->");
85
86   return kTRUE;
87 }
88
89
90 //_____________________________________________________________________________
91 void AliRsnVAnalysisTaskME::ConnectInputData(Option_t *opt)
92 {
93 //
94 // ConnectInputData
95 //
96
97   SetDebugForAllClasses();
98
99   AliDebug(AliLog::kDebug+2,"<-");
100
101   AliAnalysisTaskME::ConnectInputData(opt);
102
103   AliDebug(AliLog::kDebug+2,"->");
104 }
105
106 //_____________________________________________________________________________
107 void AliRsnVAnalysisTaskME::RsnUserCreateOutputObjects()
108 {
109 //
110 // Rsn User Create Output Objects
111 //
112
113   AliDebug(AliLog::kDebug+2,"<-");
114
115   AliDebug(AliLog::kDebug+2,"->");
116 }
117
118
119 //_____________________________________________________________________________
120 void AliRsnVAnalysisTaskME::UserCreateOutputObjects()
121 {
122 //
123 // User Create Output Objects
124 //
125
126   SetDebugForAllClasses();
127
128   AliDebug(AliLog::kDebug+2,"<-");
129
130   fOutList[0] = new TList();
131   fOutList[0]->SetOwner();
132   fTaskInfo.GenerateInfoList(fOutList[0]);
133   RsnUserCreateOutputObjects();
134
135   AliDebug(AliLog::kDebug+2,"<-");
136 }
137
138 //_____________________________________________________________________________
139 void AliRsnVAnalysisTaskME::UserExec(Option_t* opt)
140 {
141 //
142 // User Exec
143 //
144
145   AliDebug(AliLog::kDebug+2,"<-");
146
147   RsnUserExec(opt);
148
149   FillInfo();
150
151   fTaskInfo.PrintInfo(fEntry);
152
153   PostData(1, fOutList[0]);
154
155   AliDebug(AliLog::kDebug+2,"->");
156 }
157
158 //_____________________________________________________________________________
159 void AliRsnVAnalysisTaskME::RsnUserExec(Option_t*)
160 {
161 //
162 // Rsn User Exec
163 //
164
165   AliDebug(AliLog::kDebug+2,"<-");
166
167   if (!CheckAndPrintEvents()) return;
168
169   AliDebug(AliLog::kDebug+2,"->");
170 }
171
172 //_____________________________________________________________________________
173 Bool_t AliRsnVAnalysisTaskME::CheckAndPrintEvents()
174 {
175 //
176 // Check for supported events
177 // return false in the case of unkown format
178 // or number of events is less or equal 1
179 //
180
181   AliInfo(Form("Current Entry %d", Entry()));
182   Int_t nEvents = fInputHandler->GetBufferSize();
183   if (nEvents <= 1) return kFALSE;
184   fESDEvent = dynamic_cast<AliESDEvent*>(GetEvent(0));
185   fAODEvent = dynamic_cast<AliAODEvent*>(GetEvent(0));
186
187   if (fESDEvent) {
188     AliESDEvent **allESDEvents = new AliESDEvent*[nEvents];
189     for (Int_t i = 0; i < nEvents; i++) {
190       allESDEvents[i] = dynamic_cast<AliESDEvent*>(GetEvent(i));
191       if (!allESDEvents[i]) {
192         AliWarning(Form("Null ESD event in index %d", i));
193         continue;
194       }
195       AliDebug(AliLog::kDebug, Form("ESD event %d has %d tracks", i, allESDEvents[i]->GetNumberOfTracks()));
196     }
197     delete [] allESDEvents;
198   } else if (fAODEvent) {
199     AliAODEvent **allAODEvents = new AliAODEvent*[nEvents];
200     for (Int_t i = 0; i < nEvents; i++) {
201       allAODEvents[i] = dynamic_cast<AliAODEvent*>(GetEvent(i));
202       if (!allAODEvents[i]) {
203         AliWarning(Form("Null AOD event in index %d", i));
204         continue;
205       }
206       AliDebug(AliLog::kDebug, Form("AOD event %d has %d tracks", i, allAODEvents[i]->GetNumberOfTracks()));
207     }
208     delete [] allAODEvents;
209   } else {
210     AliWarning("Unknown input format");
211     return kFALSE;
212   }
213
214   return kTRUE;
215 }
216
217 //_____________________________________________________________________________
218 void AliRsnVAnalysisTaskME::Terminate(Option_t* opt)
219 {
220 //
221 // Terminate
222 //
223
224   AliDebug(AliLog::kDebug+2,"<-");
225   AliAnalysisTask::Terminate();
226
227   fOutList[0] = dynamic_cast<TList*>(GetOutputData(1));
228   if (!fOutList[0]) {
229     AliError(Form("At end of analysis, fOutList is %p", fOutList));
230     return;
231   }
232
233   RsnTerminate(opt);
234
235   TH1I *hEventInfo = (TH1I*) fOutList[0]->FindObject(fTaskInfo.GetEventHistogramName());
236   if (!hEventInfo) {
237     AliError(Form("hEventInfo is %p", hEventInfo));
238     return;
239   }
240
241   AliInfo(Form("=== %s ==================", GetName()));
242   AliInfo(Form("Number Of Events Processed : %10d", (Long64_t)hEventInfo->Integral()));
243   AliInfo(Form("Number Of Events Accepted  : %10d", (Long64_t)hEventInfo->GetBinContent(2)));
244   AliInfo(Form("Number Of Events Skipped   : %10d", (Long64_t)hEventInfo->GetBinContent(1)));
245   AliInfo(Form("=== end %s ==============", GetName()));
246
247   AliDebug(AliLog::kDebug+2,"->");
248 }
249
250 //_____________________________________________________________________________
251 void AliRsnVAnalysisTaskME::RsnTerminate(Option_t*)
252 {
253 //
254 // RsnTerminate
255 //
256
257   AliDebug(AliLog::kDebug+2,"<-");
258   AliDebug(AliLog::kDebug+2,"->");
259 }
260
261 //_____________________________________________________________________________
262 void AliRsnVAnalysisTaskME::FillInfo()
263 {
264 //
265 // Fills Info
266 //
267
268   fTaskInfo.FillInfo();
269 }
270
271 //_____________________________________________________________________________
272 void AliRsnVAnalysisTaskME::SetLogType(AliLog::EType_t type, TString allClasses)
273 {
274 //
275 // Sets Log Type
276 //
277
278   AliDebug(AliLog::kDebug+2,"<-");
279   fLogType = type;
280   fLogClassesString = allClasses;
281   AliDebug(AliLog::kDebug+2,"->");
282 }
283 //_____________________________________________________________________________
284 void AliRsnVAnalysisTaskME::SetDebugForAllClasses()
285 {
286 //
287 // Set Debug For All Classes
288 //
289
290   AliDebug(AliLog::kDebug+2,"<-");
291   TObjArray* array = fLogClassesString.Tokenize(":");
292   TObjString *str;
293   TString strr;
294   for (Int_t i = 0;i < array->GetEntriesFast();i++) {
295     str = (TObjString *) array->At(i);
296     strr = str->GetString();
297     AliLog::SetClassDebugLevel(strr.Data(), fLogType);
298     AliInfo(Form("Setting Debug to %s", strr.Data()));
299   }
300   AliDebug(AliLog::kDebug+2,"->");
301 }