Factorization of the different raw fitting algorithms in EMCAL (Per Thomas)
[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"
90a9a634 27#include "AliAnalysisCuts.h"
60a04972 28#include "AliAnalysisDataSlot.h"
4747b4a7 29#include "AliAnalysisDataContainer.h"
90a9a634 30
5232d0de 31#include "AliESDEvent.h"
620ad672 32#include "AliESDfriend.h"
5232d0de 33#include "AliESD.h"
34#include "AliAODEvent.h"
3f2431c4 35#include "AliAODHeader.h"
c185e0db 36#include "AliAODTracklets.h"
5a922844 37#include "AliAODCaloCells.h"
113bc2bd 38#include "AliAODMCParticle.h"
5232d0de 39#include "AliVEvent.h"
40#include "AliAODHandler.h"
3f2431c4 41#include "AliAODInputHandler.h"
5232d0de 42#include "AliMCEventHandler.h"
43#include "AliInputEventHandler.h"
2da1d158 44#include "AliMultiInputEventHandler.h"
620ad672 45#include "AliESDInputHandler.h"
5232d0de 46#include "AliMCEvent.h"
47#include "AliStack.h"
4d0a82af 48#include "AliLog.h"
866d8d78 49#include "AliAODDimuon.h"
5232d0de 50
51
52ClassImp(AliAnalysisTaskSE)
53
54////////////////////////////////////////////////////////////////////////
90a9a634 55AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
56TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
57TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
58TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
59TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
60TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
61TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
62TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
63TClonesArray* AliAnalysisTaskSE::fgAODMCParticles = NULL;
64AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
65AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells = NULL;
66AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells = NULL;
866d8d78 67TClonesArray* AliAnalysisTaskSE::fgAODDimuons = NULL;
5232d0de 68
69AliAnalysisTaskSE::AliAnalysisTaskSE():
70 AliAnalysisTask(),
71 fDebug(0),
80d13558 72 fEntry(0),
5232d0de 73 fInputEvent(0x0),
620ad672 74 fESDfriend(0x0),
80d13558 75 fInputHandler(0x0),
5232d0de 76 fOutputAOD(0x0),
77 fMCEvent(0x0),
9a587f77 78 fTreeA(0x0),
79 fCurrentRunNumber(-1),
90a9a634 80 fHistosQA(0x0),
2da1d158 81 fOfflineTriggerMask(0),
82 fMultiInputHandler(0),
83 fMCEventHandler(0)
5232d0de 84{
85 // Default constructor
86}
87
88AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
89 AliAnalysisTask(name, "AnalysisTaskSE"),
90 fDebug(0),
80d13558 91 fEntry(0),
5232d0de 92 fInputEvent(0x0),
620ad672 93 fESDfriend(0x0),
80d13558 94 fInputHandler(0x0),
5232d0de 95 fOutputAOD(0x0),
96 fMCEvent(0x0),
1ec2c8dc 97 fTreeA(0x0),
98 fCurrentRunNumber(-1),
90a9a634 99 fHistosQA(0x0),
2da1d158 100 fOfflineTriggerMask(0),
101 fMultiInputHandler(0),
102 fMCEventHandler(0)
5232d0de 103{
104 // Default constructor
105 DefineInput (0, TChain::Class());
106 DefineOutput(0, TTree::Class());
107}
108
26f071d8 109AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
110 AliAnalysisTask(obj),
111 fDebug(0),
80d13558 112 fEntry(0),
26f071d8 113 fInputEvent(0x0),
620ad672 114 fESDfriend(0x0),
80d13558 115 fInputHandler(0x0),
26f071d8 116 fOutputAOD(0x0),
117 fMCEvent(0x0),
1ec2c8dc 118 fTreeA(0x0),
119 fCurrentRunNumber(-1),
90a9a634 120 fHistosQA(0x0),
2da1d158 121 fOfflineTriggerMask(0),
122 fMultiInputHandler(obj.fMultiInputHandler),
123 fMCEventHandler(obj.fMCEventHandler)
26f071d8 124{
125// Copy constructor
1ec2c8dc 126 fDebug = obj.fDebug;
127 fEntry = obj.fEntry;
128 fInputEvent = obj.fInputEvent;
620ad672 129 fESDfriend = obj.fESDfriend;
1ec2c8dc 130 fInputHandler = obj.fInputHandler;
131 fOutputAOD = obj.fOutputAOD;
132 fMCEvent = obj.fMCEvent;
133 fTreeA = obj.fTreeA;
134 fCurrentRunNumber = obj.fCurrentRunNumber;
135 fHistosQA = obj.fHistosQA;
90a9a634 136
26f071d8 137}
138
139
140AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
141{
142// Assignment
143 AliAnalysisTask::operator=(other);
1ec2c8dc 144 fDebug = other.fDebug;
145 fEntry = other.fEntry;
146 fInputEvent = other.fInputEvent;
620ad672 147 fESDfriend = other.fESDfriend;
1ec2c8dc 148 fInputHandler = other.fInputHandler;
149 fOutputAOD = other.fOutputAOD;
150 fMCEvent = other.fMCEvent;
151 fTreeA = other.fTreeA;
152 fCurrentRunNumber = other.fCurrentRunNumber;
153 fHistosQA = other.fHistosQA;
0c6c629b 154 fOfflineTriggerMask = other.fOfflineTriggerMask;
2da1d158 155 fMultiInputHandler = other.fMultiInputHandler;
156 fMCEventHandler = other.fMCEventHandler;
26f071d8 157 return *this;
158}
5232d0de 159
4747b4a7 160//______________________________________________________________________________
161Bool_t AliAnalysisTaskSE::CheckPostData() const
162{
163// Checks if data was posted to all outputs defined by the task. If task does
164// not have output slots this returns always kTRUE.
165 AliAnalysisDataContainer *coutput;
b2fce16b 166 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
4747b4a7 167 for (Int_t islot=1; islot<fNoutputs; islot++) {
168 coutput = GetOutputSlot(islot)->GetContainer();
b2fce16b 169 if (!mgr->GetOutputs()->FindObject(coutput)) continue;
4747b4a7 170 if (!coutput->GetData()) return kFALSE;
171 }
b2fce16b 172 CheckOwnership();
4747b4a7 173 return kTRUE;
174}
5232d0de 175
176void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
177{
178// Connect the input data
179 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
2da1d158 180
181 // Connect input handlers (multi input handler is handled)
182 ConnectMultiHandler();
183
259b7a8a 184 if (fInputHandler) {
620ad672 185 if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
186 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
187
188 fInputEvent = fInputHandler->GetEvent();
259b7a8a 189 } else if( fMCEvent ) {
190 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
191 } else {
192 AliError("No Input Event Handler connected") ;
193 return ;
194 }
2da1d158 195 // Disconnect multi handler
196 DisconnectMultiHandler();
5232d0de 197}
198
199void AliAnalysisTaskSE::CreateOutputObjects()
200{
201// Create the output container
202//
203// Default AOD
204 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
205
b9531017 206 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
259b7a8a 207 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
5232d0de 208
5a922844 209 Bool_t merging = kFALSE;
210 AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
211 if (aodIH) {
212 if (aodIH->GetMergeEvents()) merging = kTRUE;
213 }
214
90a9a634 215
c185e0db 216 // Check if AOD replication has been required
217
3b9a675c 218 if (handler) {
219 fOutputAOD = handler->GetAOD();
220 fTreeA = handler->GetTree();
d7c65b93 221 if (fOutputAOD && !(handler->IsStandard())) {
c185e0db 222 if ((handler->NeedsHeaderReplication()) && !(fgAODHeader))
223 {
87022830 224 if (fDebug > 1) AliInfo("Replicating header");
225 fgAODHeader = new AliAODHeader;
226 handler->AddBranch("AliAODHeader", &fgAODHeader);
c185e0db 227 }
5a922844 228 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
c185e0db 229 {
230 if (fDebug > 1) AliInfo("Replicating track branch\n");
231 fgAODTracks = new TClonesArray("AliAODTrack",500);
87022830 232 fgAODTracks->SetName("tracks");
c185e0db 233 handler->AddBranch("TClonesArray", &fgAODTracks);
234 }
4dd8a1c8 235 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
c185e0db 236 {
237 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
238 fgAODVertices = new TClonesArray("AliAODVertex",500);
87022830 239 fgAODVertices->SetName("vertices");
c185e0db 240 handler->AddBranch("TClonesArray", &fgAODVertices);
241 }
242 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
243 {
244 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
245 fgAODV0s = new TClonesArray("AliAODv0",500);
87022830 246 fgAODV0s->SetName("v0s");
c185e0db 247 handler->AddBranch("TClonesArray", &fgAODV0s);
248 }
249 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
250 {
251 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
87022830 252 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
c185e0db 253 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
254 }
255 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
256 {
257 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
258 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
87022830 259 fgAODPMDClusters->SetName("pmdClusters");
c185e0db 260 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
261 }
5a922844 262 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
c185e0db 263 {
264 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
265 fgAODJets = new TClonesArray("AliAODJet",500);
87022830 266 fgAODJets->SetName("jets");
c185e0db 267 handler->AddBranch("TClonesArray", &fgAODJets);
268 }
269 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
270 {
271 AliInfo("Replicating FMDClusters branch\n");
272 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
87022830 273 fgAODFMDClusters->SetName("fmdClusters");
c185e0db 274 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
275 }
5a922844 276 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
c185e0db 277 {
278 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
279 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
87022830 280 fgAODCaloClusters->SetName("caloClusters");
c185e0db 281 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
5a922844 282
283 fgAODEmcalCells = new AliAODCaloCells();
284 fgAODEmcalCells->SetName("emcalCells");
285 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
286
287 fgAODPhosCells = new AliAODCaloCells();
288 fgAODPhosCells->SetName("phosCells");
289 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
c185e0db 290 }
113bc2bd 291 if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))
292 {
293 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
294 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
295 fgAODMCParticles->SetName("mcparticles");
296 handler->AddBranch("TClonesArray", &fgAODMCParticles);
297 }
866d8d78 298 if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))
299 {
300 if (fDebug > 1) AliInfo("Replicating dimuon branch\n");
301 fgAODDimuons = new TClonesArray("AliAODDimuon",0);
302 fgAODDimuons->SetName("dimuons");
303 handler->AddBranch("TClonesArray", &fgAODDimuons);
304 }
305
5a922844 306 // cache the pointerd in the AODEvent
307 fOutputAOD->GetStdContent();
3f2431c4 308 }
3b9a675c 309 }
cdf456b5 310 ConnectMultiHandler();
5232d0de 311 UserCreateOutputObjects();
cdf456b5 312 DisconnectMultiHandler();
5232d0de 313}
314
315void AliAnalysisTaskSE::Exec(Option_t* option)
316{
317//
318// Exec analysis of one event
2da1d158 319
320 ConnectMultiHandler();
321
27704f6c 322 if ( fDebug >= 10)
323 printf("Task is active %5d\n", IsActive());
8f6e7d10 324
259b7a8a 325 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
fdda6b64 326//
b9531017 327 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
fdda6b64 328 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
b9531017 329
fdda6b64 330 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
331//
5b173801 332// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
333 UInt_t isSelected = AliVEvent::kAny;
334 if( fInputHandler && fInputHandler->GetEventSelection()) {
ca9cb319 335 // Get the actual offline trigger mask for the event and AND it with the
336 // requested mask. If no mask requested select by default the event.
337 if (fOfflineTriggerMask)
338 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
04a79fa0 339 }
5b173801 340// Functionality below moved in the filter tasks (AG)
341// if (handler) handler->SetFillAOD(isSelected);
9b98c4df 342
80ce1b4e 343 if( fInputHandler ) {
344 fEntry = fInputHandler->GetReadEntry();
345 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
346 }
347
bf666461 348
39b02a2e 349// Notify the change of run number
276b8751 350 if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
39b02a2e 351 fCurrentRunNumber = InputEvent()->GetRunNumber();
352 NotifyRun();
353 }
04a79fa0 354
259b7a8a 355 else if( fMCEvent )
356 fEntry = fMCEvent->Header()->GetEvent();
4d0a82af 357 if ( !((Entry()-1)%100) && fDebug > 0)
259b7a8a 358 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
3f2431c4 359
fdda6b64 360
361
c185e0db 362
363 if (handler && aodH) {
04a79fa0 364 fMCEvent = aodH->MCEvent();
5a922844 365 Bool_t merging = aodH->GetMergeEvents();
9daedfd1 366 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
367
368 if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
c185e0db 369 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
370 {
61d5496b 371 // copy the contents by assigment
9daedfd1 372 *fgAODHeader = *(aod->GetHeader());
daa81fe5 373 }
5a922844 374 if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
c185e0db 375 {
9daedfd1 376 TClonesArray* tracks = aod->GetTracks();
c185e0db 377 new (fgAODTracks) TClonesArray(*tracks);
378 }
417ab5ac 379 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
c185e0db 380 {
9daedfd1 381 TClonesArray* vertices = aod->GetVertices();
c185e0db 382 new (fgAODVertices) TClonesArray(*vertices);
383 }
384 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
385 {
9daedfd1 386 TClonesArray* v0s = aod->GetV0s();
113bc2bd 387 new (fgAODV0s) TClonesArray(*v0s);
c185e0db 388 }
389 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
390 {
9daedfd1 391 *fgAODTracklets = *aod->GetTracklets();
c185e0db 392 }
393 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
394 {
9daedfd1 395 TClonesArray* pmdClusters = aod->GetPmdClusters();
113bc2bd 396 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
c185e0db 397 }
5a922844 398 if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
c185e0db 399 {
9daedfd1 400 TClonesArray* jets = aod->GetJets();
113bc2bd 401 new (fgAODJets) TClonesArray(*jets);
c185e0db 402 }
403 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
404 {
9daedfd1 405 TClonesArray* fmdClusters = aod->GetFmdClusters();
113bc2bd 406 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
c185e0db 407 }
5a922844 408 if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
c185e0db 409 {
9daedfd1 410 TClonesArray* caloClusters = aod->GetCaloClusters();
113bc2bd 411 new (fgAODCaloClusters) TClonesArray(*caloClusters);
412 }
413
414 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
415 {
9daedfd1 416 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
113bc2bd 417 new (fgAODMCParticles) TClonesArray(*mcParticles);
c185e0db 418 }
866d8d78 419
420 if ((handler->NeedsDimuonsBranchReplication() || merging) && (fgAODDimuons))
421 {
8f6e7d10 422 fgAODDimuons->Clear();
423 TClonesArray& dimuons = *fgAODDimuons;
424 TClonesArray& tracksnew = *fgAODTracks;
425
397081d5 426 Int_t nMuonTrack[100];
427 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 0;
8f6e7d10 428 Int_t nMuons=0;
429 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
430 AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
431 if(track->IsMuonTrack()) {
432 nMuonTrack[nMuons]= ii;
433 nMuons++;
434 }
435 }
436 Int_t jDimuons=0;
437 if(nMuons >= 2){
438 for(Int_t i = 0; i < nMuons; i++){
439 Int_t index0 = nMuonTrack[i];
440 for(Int_t j = i+1; j < nMuons; j++){
441 Int_t index1 = nMuonTrack[j];
8f6e7d10 442 tracksnew.At(index0)->ResetBit(kIsReferenced);
443 tracksnew.At(index0)->SetUniqueID(0);
444 tracksnew.At(index1)->ResetBit(kIsReferenced);
445 tracksnew.At(index1)->SetUniqueID(0);
446 new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
447 }
448 }
449 }
866d8d78 450 }
8f6e7d10 451
5a922844 452 // Additional merging if needed
453 if (merging) {
113bc2bd 454 // mcParticles
455 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
456 Int_t npart = mcparticles->GetEntries();
457 Int_t nc = fgAODMCParticles->GetEntries();
458 Int_t nc0 = nc;
459
460 for (Int_t i = 0; i < npart; i++) {
461 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
c8de791b 462 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
113bc2bd 463 }
464
5a922844 465 // tracks
466 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
467 Int_t ntr = tracks->GetEntries();
113bc2bd 468 nc = fgAODTracks->GetEntries();
5a922844 469 for (Int_t i = 0; i < ntr; i++) {
470 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
471 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
113bc2bd 472 newtrack->SetLabel(newtrack->GetLabel() + nc0);
5a922844 473 }
c8de791b 474
475 for (Int_t i = 0; i < nc; i++)
476 {
477 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
478 track->ResetBit(kIsReferenced);
479 track->SetUniqueID(0);
480 }
481
482
5a922844 483 // clusters
484 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
485 Int_t ncl = clusters->GetEntries();
486 nc = fgAODCaloClusters->GetEntries();
487 for (Int_t i = 0; i < ncl; i++) {
488 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
c8de791b 489 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
5a922844 490 }
491 // cells
492 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
493 Int_t ncells = cellsA->GetNumberOfCells();
494 nc = fgAODEmcalCells->GetNumberOfCells();
495
496 for (Int_t i = 0; i < ncells; i++) {
497 Int_t cn = cellsA->GetCellNumber(i);
498 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
499 if (pos >= 0) {
500 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
501 fgAODEmcalCells->SetCell(pos, cn, amp);
502 } else {
503 Double_t amp = cellsA->GetAmplitude(i);
504 fgAODEmcalCells->SetCell(nc++, cn, amp);
505 fgAODEmcalCells->Sort();
506 }
507 }
113bc2bd 508
509
510 } // merging
c185e0db 511
5a922844 512 handler->SetAODIsReplicated();
3f2431c4 513 }
514 }
515
4d0a82af 516// Call the user analysis
2da1d158 517 if (!fMCEventHandler) {
5b173801 518 if (isSelected)
67d77d71 519 UserExec(option);
520 } else {
2da1d158 521 if (isSelected && (fMCEventHandler->InitOk()))
67d77d71 522 UserExec(option);
523 }
90a9a634 524
525// Added protection in case the derived task is not an AOD producer.
60a04972 526 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
527 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
2da1d158 528
529 DisconnectMultiHandler();
5232d0de 530}
531
4d0a82af 532const char* AliAnalysisTaskSE::CurrentFileName()
533{
534// Returns the current file name
259b7a8a 535 if( fInputHandler )
536 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
537 else if( fMCEvent )
538 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 539 else return "";
4d0a82af 540}
5232d0de 541
3cee83d7 542void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
164e94ff 543{
544 // Add a new branch to the aod tree
b9531017 545 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
164e94ff 546 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
547 if (handler) {
3cee83d7 548 handler->AddBranch(cname, addobj, fname);
164e94ff 549 }
550}
3cee83d7 551
552Bool_t AliAnalysisTaskSE::IsStandardAOD() const
553{
554// Check if the output AOD handler is configured for standard or delta AOD.
555// Users should first check that AODEvent() returns non-null.
b9531017 556 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
3cee83d7 557 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
558 if (!handler) {
559 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
560 return kTRUE;
561 }
562 return handler->IsStandard();
563}
1ec2c8dc 564
565Bool_t AliAnalysisTaskSE::Notify()
566{
9a587f77 567 return (UserNotify());
1ec2c8dc 568}
569
cec9e119 570const AliEventTag *AliAnalysisTaskSE::EventTag() const
571{
572// Returns tag for the current event, if any. The return value should always be checked by the user.
573 if (!fInputHandler) {
574 Error("EventTag", "Input handler not yet available. Call this in UserExec");
575 return NULL;
576 }
577 return fInputHandler->GetEventTag();
578}
1ec2c8dc 579
cec9e119 580void AliAnalysisTaskSE::LoadBranches() const
581{
582// Load all branches declared in fBranchNames data member of the parent class.
583// Should be called in UserExec.
584 if (!fInputHandler) {
585 Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
586 return;
587 }
588 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
589 if (mgr->GetAutoBranchLoading()) return;
590 TString taskbranches;
591 GetBranches(fInputHandler->GetDataType(), taskbranches);
592 if (taskbranches.IsNull()) return;
593 TObjArray *arr = taskbranches.Tokenize(",");
594 TIter next(arr);
595 TObject *obj;
596 while ((obj=next())) mgr->LoadBranch(obj->GetName());
597}
2da1d158 598
599
600//_________________________________________________________________________________________________
601void AliAnalysisTaskSE::ConnectMultiHandler()
602{
603 //
604 // Connect MultiHandler
605 //
606 fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
607 fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
608 if (fMultiInputHandler) {
2da1d158 609 fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
610 fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
bae44bb7 611 } else {
612 fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
2da1d158 613 }
614 if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
615}
616
617//_________________________________________________________________________________________________
618void AliAnalysisTaskSE::DisconnectMultiHandler()
619{
620 //
621 // Disconnect MultiHandler
622 //
623 if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
624}