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