]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTaskBase.cxx
6b8354771ce19b4b1a321806bd279e1fc7f818fe
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisTaskBase.cxx
1 //
2 // Class AliRsnAnalysisTaskBase
3 //
4 // TODO
5 //
6 // authors: Martin Vala (martin.vala@cern.ch)
7 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
8 //
9 #include <TTree.h>
10 #include <TH1F.h>
11 #include <TCanvas.h>
12
13 #include "AliLog.h"
14
15 #include "AliAnalysisManager.h"
16 #include "AliAnalysisTask.h"
17
18 #include "AliESDEvent.h"
19 #include "AliAODEvent.h"
20 #include "AliRsnEvent.h"
21 #include "AliMCEvent.h"
22
23 #include "AliRsnAnalysisTaskBase.h"
24
25
26 ClassImp(AliRsnAnalysisTaskBase)
27
28 //________________________________________________________________________
29 AliRsnAnalysisTaskBase::AliRsnAnalysisTaskBase(const char *name)
30     : AliAnalysisTask(name, ""),
31     fNumOfEvents(100),
32     fUseAutoHandler(100),
33     fRsnInput(),
34     fReader(),
35     fPID(),
36     fAnalysisMgr(0x0)
37 {
38 //=========================================================
39 // Default constructor
40 //=========================================================
41   InitIOVars();
42   DefineInput(0, TChain::Class());
43 //   DefineInput ( 1, AliRsnReader::Class() );
44 //   DefineInput ( 2, AliRsnPID::Class() );
45 }
46
47 //________________________________________________________________________
48 void AliRsnAnalysisTaskBase::InitIOVars()
49 {
50 //=========================================================
51 // Initial values for constructor
52 //=========================================================
53   AliDebug(AliLog::kDebug, "<-");
54
55   fNumOfEvents=0;
56   fUseAutoHandler = kFALSE;
57   for (Int_t i=0;i<2;i++)
58   {
59     fChain[i] = 0;
60     fRSN[i] = 0;
61     fESD[i] = 0;
62     fMC[i] = 0;
63     fAOD[i] = 0;
64     fESDEH[i] = 0;
65     fMCEH[i] = 0;
66     fAODEH[i] = 0;
67     fInputType[i] = kRSN;
68   }
69
70   fAnalysisMgr=0;
71
72   AliDebug(AliLog::kDebug, "->");
73 }
74
75 //________________________________________________________________________
76 void AliRsnAnalysisTaskBase::LocalInit()
77 {
78 //=========================================================
79 // LocalInit()
80 //=========================================================
81 }
82
83 //________________________________________________________________________
84 Bool_t AliRsnAnalysisTaskBase::Notify()
85 {
86 //=========================================================
87 // Notify()
88 //=========================================================
89
90   return AliAnalysisTask::Notify();
91 }
92
93 //________________________________________________________________________
94 void AliRsnAnalysisTaskBase::SetInputType(EInputType type,AliAnalysisManager* am,Bool_t autohandler, Short_t inputIndex)
95 {
96 //=========================================================
97 // Sets input type.
98 // When autohandler is kTRUE handlers are created and sets
99 // to AliAnalysisManager (fAnalysisMgr) if exists
100 //=========================================================
101
102   AliDebug(AliLog::kDebug, "<-");
103
104   fInputType[inputIndex] = type;
105   fAnalysisMgr = am;
106
107   UseAutoHandler(autohandler);
108
109   if (!fUseAutoHandler) return;
110
111   if (!fAnalysisMgr)
112   {
113     AliWarning(Form("fAnalysisMgr is %p and fUseAutoHandler is %d",fAnalysisMgr,fUseAutoHandler));
114     return;
115   }
116
117   switch (fInputType[inputIndex])
118   {
119     case kAOD:
120     {
121       if (fAnalysisMgr)
122       {
123         fAODEH[0] = new AliAODInputHandler();
124         if (fAODEH[0])
125           fAnalysisMgr->SetInputEventHandler(fAODEH[0]);
126       }
127       break;
128     }
129     case kESD:
130     {
131       if (fAnalysisMgr)
132       {
133         fESDEH[0] = new AliESDInputHandler();
134         if (fESDEH[0])
135           fAnalysisMgr->SetInputEventHandler(fESDEH[0]);
136       }
137
138       break;
139     }
140     case kESDMC:
141     {
142       if (fAnalysisMgr)
143       {
144         fESDEH[0] = new AliESDInputHandler();
145         fMCEH[0] = new AliMCEventHandler();
146         if ((fESDEH[0]) && (fMCEH[0]))
147         {
148           fAnalysisMgr->SetInputEventHandler(fESDEH[0]);
149           fAnalysisMgr->SetMCtruthEventHandler(fMCEH[0]);
150         }
151       }
152       break;
153     }
154     case kMC:
155       AliError("Not Implemented Yet ...");
156       break;
157     case kRSN:
158     {
159       AliError("Not Implemented Yet ...");
160       break;
161     }
162     default:
163       AliError("Type not supported ...");
164       break;
165   }
166   AliDebug(AliLog::kDebug, "->");
167 }
168
169 //________________________________________________________________________
170 void AliRsnAnalysisTaskBase::ConnectInputData(Option_t *)
171 {
172 //=========================================================
173 // ConectInputData() for AliAnalysisTask
174 // just define myTask->SetInputType ( AliRsnAnalysisTaskBase::kRSN ); for Rsn input
175 // just define myTask->SetInputType ( AliRsnAnalysisTaskBase::kESDMC ); for ESD and MC input
176 // just define myTask->SetInputType ( AliRsnAnalysisTaskBase::kAOD ); for Rsn input
177 //=========================================================
178
179   ConnectInputDataByInputType(fInputType[0],0);
180 }
181
182 void AliRsnAnalysisTaskBase::ConnectInputDataByInputType(EInputType type ,Short_t inputIndex)
183 {
184 //=========================================================
185 // Connect input data by input type
186 //=========================================================
187
188   AliDebug(AliLog::kDebug, "<-");
189
190   switch (type)
191   {
192     case kAOD:
193     {
194       ConnectAOD(inputIndex);
195       break;
196     }
197     case kESD:
198     {
199       ConnectESD(inputIndex);
200       break;
201     }
202     case kESDMC:
203     {
204       ConnectESDMC(inputIndex);
205       break;
206     }
207     case kMC:
208       AliError("Not Implemented Yet ...");
209       break;
210     case kRSN:
211     {
212       ConnectRSN(inputIndex);
213       break;
214     }
215     default:
216       AliError("Type not supported ...");
217       break;
218   }
219   AliDebug(AliLog::kDebug, "->");
220 }
221 //________________________________________________________________________
222 void AliRsnAnalysisTaskBase::ConnectRSN(Short_t inputIndex)
223 {
224 //=========================================================
225 // Connect input data by RSN input type
226 //=========================================================
227
228   AliDebug(AliLog::kDebug, "<-");
229   char ** address = (char **) GetBranchAddress(inputIndex, "rsnEvents");
230   if (address)
231   {
232     fRSN[inputIndex] = (AliRsnEvent*)(*address);
233   }
234   else
235   {
236     fRSN[inputIndex] = 0;
237     SetBranchAddress(inputIndex, "rsnEvents", &fRSN[inputIndex]);
238   }
239   AliDebug(AliLog::kDebug, "->");
240 }
241
242 void AliRsnAnalysisTaskBase::ConnectESD(Short_t inputIndex)
243 {
244 //=========================================================
245 // Connect input data by ESD input type
246 //=========================================================
247
248   AliDebug(AliLog::kDebug, "<-");
249
250   TTree* tree = dynamic_cast<TTree*>(GetInputData(inputIndex));
251   if (!tree) { AliError("Could not read chain from input slot 0"); }
252   else
253   {
254     // Disable all branches, we want to process only MC
255 //     tree->SetBranchStatus("*", kFALSE);
256 //     tree->SetBranchStatus("fTracks.*", kTRUE);
257
258     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
259
260     if (!esdH) { AliError("Could not get ESDInputHandler"); }
261     else
262       fESD[inputIndex] = esdH->GetEvent();
263   }
264   AliDebug(AliLog::kDebug, "->");
265
266 }
267 //________________________________________________________________________
268 void AliRsnAnalysisTaskBase::ConnectESDMC(Short_t inputIndex)
269 {
270 //=========================================================
271 // Connect input data by ESDMC input type
272 //=========================================================
273
274   AliDebug(AliLog::kDebug, "<-");
275
276
277   TTree* tree = dynamic_cast<TTree*>(GetInputData(inputIndex));
278   if (!tree) { AliError("Could not read chain from input slot 0"); }
279   else
280   {
281     // Disable all branches, we want to process only MC
282 //     tree->SetBranchStatus("*", kFALSE);
283 //     tree->SetBranchStatus("fTracks.*", kTRUE);
284
285     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
286
287     if (!esdH) { AliError("Could not get ESDInputHandler"); }
288     else
289       fESD[inputIndex] = esdH->GetEvent();
290   }
291   AliDebug(AliLog::kDebug, "->");
292
293 }
294 //________________________________________________________________________
295 void AliRsnAnalysisTaskBase::ConnectAOD(Short_t inputIndex)
296 {
297 //=========================================================
298 // Connect input data by AOD input type
299 //=========================================================
300
301   AliDebug(AliLog::kDebug, "<-");
302
303   TTree* tree = dynamic_cast<TTree*>(GetInputData(inputIndex));
304   if (!tree) { AliError("Could not read chain from input slot 0");}
305   else
306   {
307     AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
308
309     if (!aodH) { AliError("Could not get AODInputHandler"); }
310     else
311     {
312       fAOD[inputIndex] = aodH->GetEvent();
313     }
314   }
315   AliDebug(AliLog::kDebug, "->");
316 }
317
318 //________________________________________________________________________
319 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnEventFromInputType(const Short_t & index)
320 {
321 //=========================================================
322 // Gets Evetn from input type
323 //=========================================================
324
325   switch (fInputType[index])
326   {
327     case kAOD:
328     {
329       return GetRsnFromAOD(index);
330       break;
331     }
332     case kESD:
333     {
334       AliWarning("Not Implemented Yet ...");
335       return GetRsnFromESD(index);
336       break;
337     }
338     case kESDMC:
339     {
340       return GetRsnFromESDMC(index);
341       break;
342     }
343     case kMC:
344       AliWarning("Not Implemented Yet ...");
345       return (AliRsnEvent*) 0x0;
346       break;
347     case kRSN:
348     {
349       return GetRsnFromRSN(index);
350       break;
351     }
352     default:
353       AliError("Type not supported ...");
354       return (AliRsnEvent*) 0x0;
355       break;
356   }
357   return (AliRsnEvent*) 0x0;
358 }
359
360
361
362 //________________________________________________________________________
363 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromAOD(const Short_t & index)
364 {
365 //=========================================================
366 // Gets RSN event from AOD
367 //=========================================================
368
369   if (!fAOD[index]) { AliError("fAOD not available."); return (AliRsnEvent *) 0x0; }
370
371   if (!fRSN[0])
372   {
373     fRSN[0] = new AliRsnEvent();
374     fRSN[0]->SetName("rsnEvents");
375     fRSN[0]->Init();
376   }
377   // clear pevious event
378   fRSN[0]->Clear();
379
380   if (!fReader.Fill(fRSN[0], (AliVEvent*)  fAOD[index]))
381   {
382     return (AliRsnEvent*) 0x0;
383   };
384
385   if (!fPID.Process(fRSN[0])) AliWarning("Failed PID");
386
387   return (AliRsnEvent*) fRSN[0];
388
389 }
390 //________________________________________________________________________
391 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromESD(const Short_t & index)
392 {
393 //=========================================================
394 // Gets RSN event from ESD
395 //=========================================================
396
397   if (!fESD[index]) { AliError("fESD not available."); return (AliRsnEvent *) 0x0; }
398
399   if (!fRSN[index])
400   {
401     fRSN[index] = new AliRsnEvent();
402     fRSN[index]->SetName("rsnEvents");
403     fRSN[index]->Init();
404   }
405   // clear pevious event
406   fRSN[index]->Clear();
407
408   if (!fReader.Fill(fRSN[index], (AliVEvent*) fESD[index]))
409   {
410     return (AliRsnEvent*) 0x0;
411   };
412
413   if (!fPID.Process(fRSN[index])) AliWarning("Failed PID");
414
415   return fRSN[index];
416 }
417 //________________________________________________________________________
418 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromESDMC(const Short_t & index)
419 {
420 //=========================================================
421 // Gets RSN event from ESD and MC
422 //=========================================================
423
424   if (!fESD[index]) { AliError("fESD not available."); return (AliRsnEvent *) 0x0; }
425   AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
426   if (!mcHandler) { AliError("Could not retrieve MC event handler"); return (AliRsnEvent *) 0x0; }
427
428   if (!fRSN[index])
429   {
430     fRSN[index] = new AliRsnEvent();
431     fRSN[index]->SetName("rsnEvents");
432     fRSN[index]->Init();
433   }
434   // clear pevious event
435   fRSN[index]->Clear();
436
437   fMC[index] = mcHandler->MCEvent();
438
439   if (!fMC[index]) return (AliRsnEvent *) 0x0;
440
441   if (!fReader.Fill(fRSN[index], (AliVEvent*) fESD[index],fMC[index]))
442   {
443     return (AliRsnEvent*) 0x0;
444   };
445
446   if (!fPID.Process(fRSN[index]))
447   {
448     AliWarning("Failed PID");
449     return (AliRsnEvent*) 0x0;
450   }
451
452   return fRSN[index];
453 }
454 //________________________________________________________________________
455 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromRSN(const Short_t & index)
456 {
457 //=========================================================
458 // Gets RSN event from RSN
459 // not fully implemented yet
460 //=========================================================
461
462   AliRsnEvent *event = fRSN[index];
463 //   if ( fRsnEventBuffer->GetDeleteBufferWhenReset() == kTRUE )
464 //   {
465 //     event = ( AliRsnEvent * ) fRSN[index]->Clone();
466 //   }
467 //   AliInfo ( Form ( "%p %p",event,fRSN[index] ) );
468   return event;
469 }
470
471 //________________________________________________________________________
472 void AliRsnAnalysisTaskBase::UseAutoHandler(const Bool_t & theValue)
473 {
474 //=========================================================
475 // Sets should create handlers
476 //=========================================================
477   fUseAutoHandler = theValue;
478 }