AliTOFRecoParam instantiation: moved in the TOF tracker(s) (Chiara)
[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 {
166 if (fDebug > 1) AliInfo("Replicating header");
167 fgAODHeader = new AliAODHeader;
168 handler->AddBranch("AliAODHeader", &fgAODHeader);
169 }
170 if ((handler->NeedsTracksBranchReplication()) && !(fgAODTracks))
171 {
172 if (fDebug > 1) AliInfo("Replicating track branch\n");
173 fgAODTracks = new TClonesArray("AliAODTrack",500);
174 handler->AddBranch("TClonesArray", &fgAODTracks);
175 }
176 if ((handler->NeedsVerticesBranchReplication()) && !(fgAODVertices))
177 {
178 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
179 fgAODVertices = new TClonesArray("AliAODVertex",500);
180 handler->AddBranch("TClonesArray", &fgAODVertices);
181 }
182 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
183 {
184 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
185 fgAODV0s = new TClonesArray("AliAODv0",500);
186 handler->AddBranch("TClonesArray", &fgAODV0s);
187 }
188 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
189 {
190 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
191 fgAODTracklets = new AliAODTracklets("AliAODTracklets","AliAODTracklets");
192 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
193 }
194 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
195 {
196 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
197 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
198 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
199 }
200 if ((handler->NeedsJetsBranchReplication()) && !(fgAODJets))
201 {
202 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
203 fgAODJets = new TClonesArray("AliAODJet",500);
204 handler->AddBranch("TClonesArray", &fgAODJets);
205 }
206 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
207 {
208 AliInfo("Replicating FMDClusters branch\n");
209 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
210 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
211 }
212 if ((handler->NeedsCaloClustersBranchReplication()) && !(fgAODCaloClusters))
213 {
214 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
215 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
216 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
217 }
3f2431c4 218 }
3b9a675c 219 } else {
220 AliWarning("No AOD Event Handler connected.") ;
221 }
5232d0de 222 UserCreateOutputObjects();
223}
224
225void AliAnalysisTaskSE::Exec(Option_t* option)
226{
227//
228// Exec analysis of one event
259b7a8a 229 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
230 if( fInputHandler )
231 fEntry = fInputHandler->GetReadEntry();
232 else if( fMCEvent )
233 fEntry = fMCEvent->Header()->GetEvent();
4d0a82af 234 if ( !((Entry()-1)%100) && fDebug > 0)
259b7a8a 235 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
3f2431c4 236
237 AliAODHandler* handler = (AliAODHandler*)
238 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
c185e0db 239 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
240
241 if (handler && aodH) {
242 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
243 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
244 {
245 fgAODHeader = dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader());
daa81fe5 246 }
c185e0db 247 if ((handler->NeedsTracksBranchReplication()) && (fgAODTracks))
248 {
249 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
250 new (fgAODTracks) TClonesArray(*tracks);
251 }
252 if ((handler->NeedsVerticesBranchReplication()) && (fgAODVertices))
253 {
254 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
255 new (fgAODVertices) TClonesArray(*vertices);
256 }
257 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
258 {
259 TClonesArray* V0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
260 new (fgAODV0s) TClonesArray(*V0s);
261 }
262 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
263 {
264 fgAODTracklets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
265 }
266 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
267 {
268 TClonesArray* PMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
269 new (fgAODPMDClusters) TClonesArray(*PMDClusters);
270 }
271 if ((handler->NeedsJetsBranchReplication()) && (fgAODJets))
272 {
273 TClonesArray* Jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
274 new (fgAODJets) TClonesArray(*Jets);
275 }
276 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
277 {
278 TClonesArray* FMDClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
279 new (fgAODFMDClusters) TClonesArray(*FMDClusters);
280 }
281 if ((handler->NeedsCaloClustersBranchReplication()) && (fgAODCaloClusters))
282 {
283 TClonesArray* CaloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
284 new (fgAODCaloClusters) TClonesArray(*CaloClusters);
285 }
286 //
287 handler->SetAODIsReplicated();
288
3f2431c4 289 }
290 }
291
4d0a82af 292// Call the user analysis
5232d0de 293 UserExec(option);
2d108f6e 294 PostData(0, fTreeA);
295
5232d0de 296}
297
4d0a82af 298const char* AliAnalysisTaskSE::CurrentFileName()
299{
300// Returns the current file name
259b7a8a 301 if( fInputHandler )
302 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
303 else if( fMCEvent )
304 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 305 else return "";
4d0a82af 306}
5232d0de 307
0134949d 308void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj)
164e94ff 309{
310 // Add a new branch to the aod tree
311 AliAODHandler* handler = (AliAODHandler*)
312 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
313 if (handler) {
3b427089 314 handler->AddBranch(cname, addobj);
164e94ff 315 }
316}