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