1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 #include <TInterpreter.h>
25 #include "AliAnalysisTaskSE.h"
26 #include "AliAnalysisManager.h"
27 #include "AliESDEvent.h"
29 #include "AliAODEvent.h"
30 #include "AliAODHeader.h"
31 #include "AliVEvent.h"
32 #include "AliAODHandler.h"
33 #include "AliAODInputHandler.h"
34 #include "AliMCEventHandler.h"
35 #include "AliInputEventHandler.h"
36 #include "AliMCEvent.h"
41 ClassImp(AliAnalysisTaskSE)
43 ////////////////////////////////////////////////////////////////////////
44 Bool_t AliAnalysisTaskSE::fgHeaderCopied = kFALSE;
45 AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
47 AliAnalysisTaskSE::AliAnalysisTaskSE():
57 // Default constructor
60 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
61 AliAnalysisTask(name, "AnalysisTaskSE"),
70 // Default constructor
71 DefineInput (0, TChain::Class());
72 DefineOutput(0, TTree::Class());
75 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
88 fInputEvent = obj.fInputEvent;
89 fInputHandler = obj.fInputHandler;
90 fOutputAOD = obj.fOutputAOD;
91 fMCEvent = obj.fMCEvent;
93 printf("Constructor (3) \n");
97 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
100 AliAnalysisTask::operator=(other);
101 fDebug = other.fDebug;
102 fEntry = other.fEntry;
103 fInputEvent = other.fInputEvent;
104 fInputHandler = other.fInputHandler;
105 fOutputAOD = other.fOutputAOD;
106 fMCEvent = other.fMCEvent;
107 fTreeA = other.fTreeA;
112 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
114 // Connect the input data
115 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
119 fInputHandler = (AliInputEventHandler*)
120 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
124 AliMCEventHandler* mcH = 0;
125 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
126 if (mcH) fMCEvent = mcH->MCEvent();
130 fInputEvent = fInputHandler->GetEvent();
131 } else if( fMCEvent ) {
132 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
134 AliError("No Input Event Handler connected") ;
139 void AliAnalysisTaskSE::CreateOutputObjects()
141 // Create the output container
144 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
146 AliAODHandler* handler = (AliAODHandler*)
147 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
150 fOutputAOD = handler->GetAOD();
151 fTreeA = handler->GetTree();
154 // Check if AOD Header replication has been required
155 if (!(handler->IsStandard()) &&
156 (handler->NeedsHeaderReplication()) &&
159 fgAODHeader = new AliAODHeader;
160 handler->AddBranch("AliAODHeader", &fgAODHeader);
163 AliWarning("No AOD Event Handler connected.") ;
165 UserCreateOutputObjects();
168 void AliAnalysisTaskSE::Exec(Option_t* option)
171 // Exec analysis of one event
172 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
174 fEntry = fInputHandler->GetReadEntry();
176 fEntry = fMCEvent->Header()->GetEvent();
177 if ( !((Entry()-1)%100) && fDebug > 0)
178 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
180 AliAODHandler* handler = (AliAODHandler*)
181 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
183 if (!(handler->IsStandard()) &&
184 (handler->NeedsHeaderReplication()) &&
187 // Header should be replicated
188 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
191 fgAODHeader = dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader());
192 fgHeaderCopied = kTRUE;
196 // Call the user analysis
202 const char* AliAnalysisTaskSE::CurrentFileName()
204 // Returns the current file name
206 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
208 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
212 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj)
214 // Add a new branch to the aod tree
215 AliAODHandler* handler = (AliAODHandler*)
216 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
218 handler->AddBranch(cname, addobj);