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