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 "AliAnalysisDataSlot.h"
28 #include "AliESDEvent.h"
30 #include "AliAODEvent.h"
31 #include "AliAODHeader.h"
32 #include "AliAODTracklets.h"
33 #include "AliVEvent.h"
34 #include "AliAODHandler.h"
35 #include "AliAODInputHandler.h"
36 #include "AliMCEventHandler.h"
37 #include "AliInputEventHandler.h"
38 #include "AliMCEvent.h"
43 ClassImp(AliAnalysisTaskSE)
45 ////////////////////////////////////////////////////////////////////////
46 AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
47 TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
48 TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
49 TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
50 TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
51 TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
52 TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
53 TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
54 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
57 AliAnalysisTaskSE::AliAnalysisTaskSE():
67 // Default constructor
70 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
71 AliAnalysisTask(name, "AnalysisTaskSE"),
80 // Default constructor
81 DefineInput (0, TChain::Class());
82 DefineOutput(0, TTree::Class());
85 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
98 fInputEvent = obj.fInputEvent;
99 fInputHandler = obj.fInputHandler;
100 fOutputAOD = obj.fOutputAOD;
101 fMCEvent = obj.fMCEvent;
103 printf("Constructor (3) \n");
107 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
110 AliAnalysisTask::operator=(other);
111 fDebug = other.fDebug;
112 fEntry = other.fEntry;
113 fInputEvent = other.fInputEvent;
114 fInputHandler = other.fInputHandler;
115 fOutputAOD = other.fOutputAOD;
116 fMCEvent = other.fMCEvent;
117 fTreeA = other.fTreeA;
122 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
124 // Connect the input data
125 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
129 fInputHandler = (AliInputEventHandler*)
130 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
134 AliMCEventHandler* mcH = 0;
135 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
136 if (mcH) fMCEvent = mcH->MCEvent();
140 fInputEvent = fInputHandler->GetEvent();
141 } else if( fMCEvent ) {
142 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
144 AliError("No Input Event Handler connected") ;
149 void AliAnalysisTaskSE::CreateOutputObjects()
151 // Create the output container
154 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
156 AliAODHandler* handler = (AliAODHandler*)
157 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
159 // Check if AOD replication has been required
162 fOutputAOD = handler->GetAOD();
163 fTreeA = handler->GetTree();
164 if (!(handler->IsStandard())) {
165 if ((handler->NeedsHeaderReplication()) && !(fgAODHeader))
167 if (fDebug > 1) AliInfo("Replicating header");
168 fgAODHeader = new AliAODHeader;
169 handler->AddBranch("AliAODHeader", &fgAODHeader);
171 if ((handler->NeedsTracksBranchReplication()) && !(fgAODTracks))
173 if (fDebug > 1) AliInfo("Replicating track branch\n");
174 fgAODTracks = new TClonesArray("AliAODTrack",500);
175 fgAODTracks->SetName("tracks");
176 handler->AddBranch("TClonesArray", &fgAODTracks);
178 if ((handler->NeedsVerticesBranchReplication()) && !(fgAODVertices))
180 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
181 fgAODVertices = new TClonesArray("AliAODVertex",500);
182 fgAODVertices->SetName("vertices");
183 handler->AddBranch("TClonesArray", &fgAODVertices);
185 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
187 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
188 fgAODV0s = new TClonesArray("AliAODv0",500);
189 fgAODV0s->SetName("v0s");
190 handler->AddBranch("TClonesArray", &fgAODV0s);
192 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
194 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
195 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
196 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
198 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
200 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
201 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
202 fgAODPMDClusters->SetName("pmdClusters");
203 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
205 if ((handler->NeedsJetsBranchReplication()) && !(fgAODJets))
207 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
208 fgAODJets = new TClonesArray("AliAODJet",500);
209 fgAODJets->SetName("jets");
210 handler->AddBranch("TClonesArray", &fgAODJets);
212 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
214 AliInfo("Replicating FMDClusters branch\n");
215 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
216 fgAODFMDClusters->SetName("fmdClusters");
217 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
219 if ((handler->NeedsCaloClustersBranchReplication()) && !(fgAODCaloClusters))
221 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
222 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
223 fgAODCaloClusters->SetName("caloClusters");
224 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
228 AliWarning("No AOD Event Handler connected.") ;
230 UserCreateOutputObjects();
233 void AliAnalysisTaskSE::Exec(Option_t* option)
236 // Exec analysis of one event
237 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
239 fEntry = fInputHandler->GetReadEntry();
241 fEntry = fMCEvent->Header()->GetEvent();
242 if ( !((Entry()-1)%100) && fDebug > 0)
243 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
245 AliAODHandler* handler = (AliAODHandler*)
246 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
247 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
249 if (handler && aodH) {
250 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
251 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
253 // copy the contents by assigment
254 *fgAODHeader = *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
256 if ((handler->NeedsTracksBranchReplication()) && (fgAODTracks))
258 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
259 new (fgAODTracks) TClonesArray(*tracks);
261 if ((handler->NeedsVerticesBranchReplication()) && (fgAODVertices))
263 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
264 new (fgAODVertices) TClonesArray(*vertices);
266 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
268 TClonesArray* V0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
269 new (fgAODV0s) TClonesArray(*V0s);
271 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
273 *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
275 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
277 TClonesArray* PMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
278 new (fgAODPMDClusters) TClonesArray(*PMDClusters);
280 if ((handler->NeedsJetsBranchReplication()) && (fgAODJets))
282 TClonesArray* Jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
283 new (fgAODJets) TClonesArray(*Jets);
285 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
287 TClonesArray* FMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
288 new (fgAODFMDClusters) TClonesArray(*FMDClusters);
290 if ((handler->NeedsCaloClustersBranchReplication()) && (fgAODCaloClusters))
292 TClonesArray* CaloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
293 new (fgAODCaloClusters) TClonesArray(*CaloClusters);
296 handler->SetAODIsReplicated();
301 // Call the user analysis
303 // Added protection in case the derived task is not an AOD producer.
304 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
305 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
308 const char* AliAnalysisTaskSE::CurrentFileName()
310 // Returns the current file name
312 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
314 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
318 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
320 // Add a new branch to the aod tree
321 AliAODHandler* handler = (AliAODHandler*)
322 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
324 handler->AddBranch(cname, addobj, fname);
328 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
330 // Check if the output AOD handler is configured for standard or delta AOD.
331 // Users should first check that AODEvent() returns non-null.
332 AliAODHandler* handler = (AliAODHandler*)
333 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
335 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
338 return handler->IsStandard();