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;
106 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
109 AliAnalysisTask::operator=(other);
110 fDebug = other.fDebug;
111 fEntry = other.fEntry;
112 fInputEvent = other.fInputEvent;
113 fInputHandler = other.fInputHandler;
114 fOutputAOD = other.fOutputAOD;
115 fMCEvent = other.fMCEvent;
116 fTreeA = other.fTreeA;
121 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
123 // Connect the input data
124 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
128 fInputHandler = (AliInputEventHandler*)
129 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
133 AliMCEventHandler* mcH = 0;
134 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
136 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 if( fInputHandler ) {
240 fEntry = fInputHandler->GetReadEntry();
245 fEntry = fMCEvent->Header()->GetEvent();
246 if ( !((Entry()-1)%100) && fDebug > 0)
247 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
249 AliAODHandler* handler = (AliAODHandler*)
250 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
251 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
253 if (handler && aodH) {
254 fMCEvent = aodH->MCEvent();
256 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
257 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
259 // copy the contents by assigment
260 *fgAODHeader = *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
262 if ((handler->NeedsTracksBranchReplication()) && (fgAODTracks))
264 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
265 new (fgAODTracks) TClonesArray(*tracks);
267 if ((handler->NeedsVerticesBranchReplication()) && (fgAODVertices))
269 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
270 new (fgAODVertices) TClonesArray(*vertices);
272 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
274 TClonesArray* V0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
275 new (fgAODV0s) TClonesArray(*V0s);
277 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
279 *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
281 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
283 TClonesArray* PMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
284 new (fgAODPMDClusters) TClonesArray(*PMDClusters);
286 if ((handler->NeedsJetsBranchReplication()) && (fgAODJets))
288 TClonesArray* Jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
289 new (fgAODJets) TClonesArray(*Jets);
291 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
293 TClonesArray* FMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
294 new (fgAODFMDClusters) TClonesArray(*FMDClusters);
296 if ((handler->NeedsCaloClustersBranchReplication()) && (fgAODCaloClusters))
298 TClonesArray* CaloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
299 new (fgAODCaloClusters) TClonesArray(*CaloClusters);
302 handler->SetAODIsReplicated();
307 // Call the user analysis
309 // Added protection in case the derived task is not an AOD producer.
310 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
311 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
314 const char* AliAnalysisTaskSE::CurrentFileName()
316 // Returns the current file name
318 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
320 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
324 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
326 // Add a new branch to the aod tree
327 AliAODHandler* handler = (AliAODHandler*)
328 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
330 handler->AddBranch(cname, addobj, fname);
334 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
336 // Check if the output AOD handler is configured for standard or delta AOD.
337 // Users should first check that AODEvent() returns non-null.
338 AliAODHandler* handler = (AliAODHandler*)
339 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
341 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
344 return handler->IsStandard();