]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisTaskSE.cxx
inserted the first calibration task for reconstruction algorithms
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.cxx
CommitLineData
5232d0de 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18#include <TROOT.h>
19#include <TSystem.h>
20#include <TInterpreter.h>
21#include <TChain.h>
22#include <TFile.h>
23#include <TList.h>
24
25#include "AliAnalysisTaskSE.h"
26#include "AliAnalysisManager.h"
27#include "AliESDEvent.h"
28#include "AliESD.h"
29#include "AliAODEvent.h"
3f2431c4 30#include "AliAODHeader.h"
c185e0db 31#include "AliAODTracklets.h"
5232d0de 32#include "AliVEvent.h"
33#include "AliAODHandler.h"
3f2431c4 34#include "AliAODInputHandler.h"
5232d0de 35#include "AliMCEventHandler.h"
36#include "AliInputEventHandler.h"
37#include "AliMCEvent.h"
38#include "AliStack.h"
4d0a82af 39#include "AliLog.h"
5232d0de 40
41
42ClassImp(AliAnalysisTaskSE)
43
44////////////////////////////////////////////////////////////////////////
c185e0db 45AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
46TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
47TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
48TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
49TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
50TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
51TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
52TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
53AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
54
5232d0de 55
56AliAnalysisTaskSE::AliAnalysisTaskSE():
57 AliAnalysisTask(),
58 fDebug(0),
80d13558 59 fEntry(0),
5232d0de 60 fInputEvent(0x0),
80d13558 61 fInputHandler(0x0),
5232d0de 62 fOutputAOD(0x0),
63 fMCEvent(0x0),
64 fTreeA(0x0)
65{
66 // Default constructor
67}
68
69AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
70 AliAnalysisTask(name, "AnalysisTaskSE"),
71 fDebug(0),
80d13558 72 fEntry(0),
5232d0de 73 fInputEvent(0x0),
80d13558 74 fInputHandler(0x0),
5232d0de 75 fOutputAOD(0x0),
76 fMCEvent(0x0),
77 fTreeA(0x0)
78{
79 // Default constructor
80 DefineInput (0, TChain::Class());
81 DefineOutput(0, TTree::Class());
82}
83
26f071d8 84AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
85 AliAnalysisTask(obj),
86 fDebug(0),
80d13558 87 fEntry(0),
26f071d8 88 fInputEvent(0x0),
80d13558 89 fInputHandler(0x0),
26f071d8 90 fOutputAOD(0x0),
91 fMCEvent(0x0),
92 fTreeA(0x0)
93{
94// Copy constructor
80d13558 95 fDebug = obj.fDebug;
96 fEntry = obj.fEntry;
97 fInputEvent = obj.fInputEvent;
98 fInputHandler = obj.fInputHandler;
99 fOutputAOD = obj.fOutputAOD;
100 fMCEvent = obj.fMCEvent;
101 fTreeA = obj.fTreeA;
f0b15803 102 printf("Constructor (3) \n");
26f071d8 103}
104
105
106AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
107{
108// Assignment
109 AliAnalysisTask::operator=(other);
80d13558 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;
26f071d8 117 return *this;
118}
5232d0de 119
120
121void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
122{
123// Connect the input data
124 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
125//
126// ESD
127//
f0b15803 128 fInputHandler = (AliInputEventHandler*)
259b7a8a 129 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
5232d0de 130//
131// Monte Carlo
132//
133 AliMCEventHandler* mcH = 0;
134 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
135 if (mcH) fMCEvent = mcH->MCEvent();
259b7a8a 136
137
138 if (fInputHandler) {
139 fInputEvent = fInputHandler->GetEvent();
140 } else if( fMCEvent ) {
141 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
142 } else {
143 AliError("No Input Event Handler connected") ;
144 return ;
145 }
5232d0de 146}
147
148void AliAnalysisTaskSE::CreateOutputObjects()
149{
150// Create the output container
151//
152// Default AOD
153 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
154
155 AliAODHandler* handler = (AliAODHandler*)
259b7a8a 156 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
5232d0de 157
c185e0db 158 // Check if AOD replication has been required
159
3b9a675c 160 if (handler) {
161 fOutputAOD = handler->GetAOD();
162 fTreeA = handler->GetTree();
c185e0db 163 if (!(handler->IsStandard())) {
164 if ((handler->NeedsHeaderReplication()) && !(fgAODHeader))
165 {
87022830 166 if (fDebug > 1) AliInfo("Replicating header");
167 fgAODHeader = new AliAODHeader;
168 handler->AddBranch("AliAODHeader", &fgAODHeader);
c185e0db 169 }
170 if ((handler->NeedsTracksBranchReplication()) && !(fgAODTracks))
171 {
172 if (fDebug > 1) AliInfo("Replicating track branch\n");
173 fgAODTracks = new TClonesArray("AliAODTrack",500);
87022830 174 fgAODTracks->SetName("tracks");
c185e0db 175 handler->AddBranch("TClonesArray", &fgAODTracks);
176 }
177 if ((handler->NeedsVerticesBranchReplication()) && !(fgAODVertices))
178 {
179 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
180 fgAODVertices = new TClonesArray("AliAODVertex",500);
87022830 181 fgAODVertices->SetName("vertices");
c185e0db 182 handler->AddBranch("TClonesArray", &fgAODVertices);
183 }
184 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
185 {
186 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
187 fgAODV0s = new TClonesArray("AliAODv0",500);
87022830 188 fgAODV0s->SetName("v0s");
c185e0db 189 handler->AddBranch("TClonesArray", &fgAODV0s);
190 }
191 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
192 {
193 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
87022830 194 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
c185e0db 195 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
196 }
197 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
198 {
199 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
200 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
87022830 201 fgAODPMDClusters->SetName("pmdClusters");
c185e0db 202 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
203 }
204 if ((handler->NeedsJetsBranchReplication()) && !(fgAODJets))
205 {
206 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
207 fgAODJets = new TClonesArray("AliAODJet",500);
87022830 208 fgAODJets->SetName("jets");
c185e0db 209 handler->AddBranch("TClonesArray", &fgAODJets);
210 }
211 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
212 {
213 AliInfo("Replicating FMDClusters branch\n");
214 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
87022830 215 fgAODFMDClusters->SetName("fmdClusters");
c185e0db 216 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
217 }
218 if ((handler->NeedsCaloClustersBranchReplication()) && !(fgAODCaloClusters))
219 {
220 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
221 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
87022830 222 fgAODCaloClusters->SetName("caloClusters");
c185e0db 223 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
224 }
3f2431c4 225 }
3b9a675c 226 } else {
227 AliWarning("No AOD Event Handler connected.") ;
228 }
5232d0de 229 UserCreateOutputObjects();
230}
231
232void AliAnalysisTaskSE::Exec(Option_t* option)
233{
234//
235// Exec analysis of one event
259b7a8a 236 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
237 if( fInputHandler )
238 fEntry = fInputHandler->GetReadEntry();
239 else if( fMCEvent )
240 fEntry = fMCEvent->Header()->GetEvent();
4d0a82af 241 if ( !((Entry()-1)%100) && fDebug > 0)
259b7a8a 242 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
3f2431c4 243
244 AliAODHandler* handler = (AliAODHandler*)
245 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
c185e0db 246 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
247
248 if (handler && aodH) {
249 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
250 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
251 {
252 fgAODHeader = dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader());
daa81fe5 253 }
c185e0db 254 if ((handler->NeedsTracksBranchReplication()) && (fgAODTracks))
255 {
256 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
257 new (fgAODTracks) TClonesArray(*tracks);
258 }
259 if ((handler->NeedsVerticesBranchReplication()) && (fgAODVertices))
260 {
261 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
262 new (fgAODVertices) TClonesArray(*vertices);
263 }
264 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
265 {
266 TClonesArray* V0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
267 new (fgAODV0s) TClonesArray(*V0s);
268 }
269 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
270 {
271 fgAODTracklets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
272 }
273 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
274 {
275 TClonesArray* PMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
276 new (fgAODPMDClusters) TClonesArray(*PMDClusters);
277 }
278 if ((handler->NeedsJetsBranchReplication()) && (fgAODJets))
279 {
280 TClonesArray* Jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
281 new (fgAODJets) TClonesArray(*Jets);
282 }
283 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
284 {
285 TClonesArray* FMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
286 new (fgAODFMDClusters) TClonesArray(*FMDClusters);
287 }
288 if ((handler->NeedsCaloClustersBranchReplication()) && (fgAODCaloClusters))
289 {
290 TClonesArray* CaloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
291 new (fgAODCaloClusters) TClonesArray(*CaloClusters);
292 }
293 //
294 handler->SetAODIsReplicated();
295
3f2431c4 296 }
297 }
298
4d0a82af 299// Call the user analysis
5232d0de 300 UserExec(option);
2d108f6e 301 PostData(0, fTreeA);
302
5232d0de 303}
304
4d0a82af 305const char* AliAnalysisTaskSE::CurrentFileName()
306{
307// Returns the current file name
259b7a8a 308 if( fInputHandler )
309 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
310 else if( fMCEvent )
311 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 312 else return "";
4d0a82af 313}
5232d0de 314
0134949d 315void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj)
164e94ff 316{
317 // Add a new branch to the aod tree
318 AliAODHandler* handler = (AliAODHandler*)
319 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
320 if (handler) {
3b427089 321 handler->AddBranch(cname, addobj);
164e94ff 322 }
323}