2 // Class AliRsnAnalysisTaskBase
6 // authors: Martin Vala (martin.vala@cern.ch)
7 // Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
15 #include "AliAnalysisManager.h"
16 #include "AliAnalysisTask.h"
18 #include "AliESDEvent.h"
19 #include "AliAODEvent.h"
20 #include "AliRsnEvent.h"
21 #include "AliMCEvent.h"
23 #include "AliRsnAnalysisTaskBase.h"
26 ClassImp(AliRsnAnalysisTaskBase)
28 //________________________________________________________________________
29 AliRsnAnalysisTaskBase::AliRsnAnalysisTaskBase(const char *name)
30 : AliAnalysisTask(name, ""),
38 //=========================================================
39 // Default constructor
40 //=========================================================
42 DefineInput(0, TChain::Class());
43 // DefineInput ( 1, AliRsnReader::Class() );
44 // DefineInput ( 2, AliRsnPID::Class() );
47 //________________________________________________________________________
48 void AliRsnAnalysisTaskBase::InitIOVars()
50 //=========================================================
51 // Initial values for constructor
52 //=========================================================
53 AliDebug(AliLog::kDebug, "<-");
56 fUseAutoHandler = kFALSE;
57 for (Int_t i=0;i<2;i++)
72 AliDebug(AliLog::kDebug, "->");
75 //________________________________________________________________________
76 void AliRsnAnalysisTaskBase::LocalInit()
78 //=========================================================
80 //=========================================================
83 //________________________________________________________________________
84 Bool_t AliRsnAnalysisTaskBase::Notify()
86 //=========================================================
88 //=========================================================
90 return AliAnalysisTask::Notify();
93 //________________________________________________________________________
94 void AliRsnAnalysisTaskBase::SetInputType(EInputType type,AliAnalysisManager* am,Bool_t autohandler, Short_t inputIndex)
96 //=========================================================
98 // When autohandler is kTRUE handlers are created and sets
99 // to AliAnalysisManager (fAnalysisMgr) if exists
100 //=========================================================
102 AliDebug(AliLog::kDebug, "<-");
104 fInputType[inputIndex] = type;
107 UseAutoHandler(autohandler);
109 if (!fUseAutoHandler) return;
113 AliWarning(Form("fAnalysisMgr is %p and fUseAutoHandler is %d",fAnalysisMgr,fUseAutoHandler));
117 switch (fInputType[inputIndex])
123 fAODEH[0] = new AliAODInputHandler();
125 fAnalysisMgr->SetInputEventHandler(fAODEH[0]);
133 fESDEH[0] = new AliESDInputHandler();
135 fAnalysisMgr->SetInputEventHandler(fESDEH[0]);
144 fESDEH[0] = new AliESDInputHandler();
145 fMCEH[0] = new AliMCEventHandler();
146 if ((fESDEH[0]) && (fMCEH[0]))
148 fAnalysisMgr->SetInputEventHandler(fESDEH[0]);
149 fAnalysisMgr->SetMCtruthEventHandler(fMCEH[0]);
155 AliError("Not Implemented Yet ...");
159 AliError("Not Implemented Yet ...");
163 AliError("Type not supported ...");
166 AliDebug(AliLog::kDebug, "->");
169 //________________________________________________________________________
170 void AliRsnAnalysisTaskBase::ConnectInputData(Option_t *)
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 //=========================================================
179 ConnectInputDataByInputType(fInputType[0],0);
182 void AliRsnAnalysisTaskBase::ConnectInputDataByInputType(EInputType type ,Short_t inputIndex)
184 //=========================================================
185 // Connect input data by input type
186 //=========================================================
188 AliDebug(AliLog::kDebug, "<-");
194 ConnectAOD(inputIndex);
199 ConnectESD(inputIndex);
204 ConnectESDMC(inputIndex);
208 AliError("Not Implemented Yet ...");
212 ConnectRSN(inputIndex);
216 AliError("Type not supported ...");
219 AliDebug(AliLog::kDebug, "->");
221 //________________________________________________________________________
222 void AliRsnAnalysisTaskBase::ConnectRSN(Short_t inputIndex)
224 //=========================================================
225 // Connect input data by RSN input type
226 //=========================================================
228 AliDebug(AliLog::kDebug, "<-");
229 char ** address = (char **) GetBranchAddress(inputIndex, "rsnEvents");
232 fRSN[inputIndex] = (AliRsnEvent*)(*address);
236 fRSN[inputIndex] = 0;
237 SetBranchAddress(inputIndex, "rsnEvents", &fRSN[inputIndex]);
239 AliDebug(AliLog::kDebug, "->");
242 void AliRsnAnalysisTaskBase::ConnectESD(Short_t inputIndex)
244 //=========================================================
245 // Connect input data by ESD input type
246 //=========================================================
248 AliDebug(AliLog::kDebug, "<-");
250 TTree* tree = dynamic_cast<TTree*>(GetInputData(inputIndex));
251 if (!tree) { AliError("Could not read chain from input slot 0"); }
254 // Disable all branches, we want to process only MC
255 // tree->SetBranchStatus("*", kFALSE);
256 // tree->SetBranchStatus("fTracks.*", kTRUE);
258 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
260 if (!esdH) { AliError("Could not get ESDInputHandler"); }
262 fESD[inputIndex] = esdH->GetEvent();
264 AliDebug(AliLog::kDebug, "->");
267 //________________________________________________________________________
268 void AliRsnAnalysisTaskBase::ConnectESDMC(Short_t inputIndex)
270 //=========================================================
271 // Connect input data by ESDMC input type
272 //=========================================================
274 AliDebug(AliLog::kDebug, "<-");
277 TTree* tree = dynamic_cast<TTree*>(GetInputData(inputIndex));
278 if (!tree) { AliError("Could not read chain from input slot 0"); }
281 // Disable all branches, we want to process only MC
282 // tree->SetBranchStatus("*", kFALSE);
283 // tree->SetBranchStatus("fTracks.*", kTRUE);
285 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
287 if (!esdH) { AliError("Could not get ESDInputHandler"); }
289 fESD[inputIndex] = esdH->GetEvent();
291 AliDebug(AliLog::kDebug, "->");
294 //________________________________________________________________________
295 void AliRsnAnalysisTaskBase::ConnectAOD(Short_t inputIndex)
297 //=========================================================
298 // Connect input data by AOD input type
299 //=========================================================
301 AliDebug(AliLog::kDebug, "<-");
303 TTree* tree = dynamic_cast<TTree*>(GetInputData(inputIndex));
304 if (!tree) { AliError("Could not read chain from input slot 0");}
307 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
309 if (!aodH) { AliError("Could not get AODInputHandler"); }
312 fAOD[inputIndex] = aodH->GetEvent();
315 AliDebug(AliLog::kDebug, "->");
318 //________________________________________________________________________
319 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnEventFromInputType(const Short_t & index)
321 //=========================================================
322 // Gets Evetn from input type
323 //=========================================================
325 switch (fInputType[index])
329 return GetRsnFromAOD(index);
334 AliWarning("Not Implemented Yet ...");
335 return GetRsnFromESD(index);
340 return GetRsnFromESDMC(index);
344 AliWarning("Not Implemented Yet ...");
345 return (AliRsnEvent*) 0x0;
349 return GetRsnFromRSN(index);
353 AliError("Type not supported ...");
354 return (AliRsnEvent*) 0x0;
357 return (AliRsnEvent*) 0x0;
362 //________________________________________________________________________
363 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromAOD(const Short_t & index)
365 //=========================================================
366 // Gets RSN event from AOD
367 //=========================================================
369 if (!fAOD[index]) { AliError("fAOD not available."); return (AliRsnEvent *) 0x0; }
373 fRSN[0] = new AliRsnEvent();
374 fRSN[0]->SetName("rsnEvents");
377 // clear pevious event
380 if (!fReader.Fill(fRSN[0], (AliVEvent*) fAOD[index]))
382 return (AliRsnEvent*) 0x0;
385 if (!fPID.Process(fRSN[0])) AliWarning("Failed PID");
387 return (AliRsnEvent*) fRSN[0];
390 //________________________________________________________________________
391 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromESD(const Short_t & index)
393 //=========================================================
394 // Gets RSN event from ESD
395 //=========================================================
397 if (!fESD[index]) { AliError("fESD not available."); return (AliRsnEvent *) 0x0; }
401 fRSN[index] = new AliRsnEvent();
402 fRSN[index]->SetName("rsnEvents");
405 // clear pevious event
406 fRSN[index]->Clear();
408 if (!fReader.Fill(fRSN[index], (AliVEvent*) fESD[index]))
410 return (AliRsnEvent*) 0x0;
413 if (!fPID.Process(fRSN[index])) AliWarning("Failed PID");
417 //________________________________________________________________________
418 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromESDMC(const Short_t & index)
420 //=========================================================
421 // Gets RSN event from ESD and MC
422 //=========================================================
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; }
430 fRSN[index] = new AliRsnEvent();
431 fRSN[index]->SetName("rsnEvents");
434 // clear pevious event
435 fRSN[index]->Clear();
437 fMC[index] = mcHandler->MCEvent();
439 if (!fMC[index]) return (AliRsnEvent *) 0x0;
441 if (!fReader.Fill(fRSN[index], (AliVEvent*) fESD[index],fMC[index]))
443 return (AliRsnEvent*) 0x0;
446 if (!fPID.Process(fRSN[index]))
448 AliWarning("Failed PID");
449 return (AliRsnEvent*) 0x0;
454 //________________________________________________________________________
455 AliRsnEvent * AliRsnAnalysisTaskBase::GetRsnFromRSN(const Short_t & index)
457 //=========================================================
458 // Gets RSN event from RSN
459 // not fully implemented yet
460 //=========================================================
462 AliRsnEvent *event = fRSN[index];
463 // if ( fRsnEventBuffer->GetDeleteBufferWhenReset() == kTRUE )
465 // event = ( AliRsnEvent * ) fRSN[index]->Clone();
467 // AliInfo ( Form ( "%p %p",event,fRSN[index] ) );
471 //________________________________________________________________________
472 void AliRsnAnalysisTaskBase::UseAutoHandler(const Bool_t & theValue)
474 //=========================================================
475 // Sets should create handlers
476 //=========================================================
477 fUseAutoHandler = theValue;