More clean-up
[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();
9daedfd1 348 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
349
350 if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
c185e0db 351 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
352 {
61d5496b 353 // copy the contents by assigment
9daedfd1 354 *fgAODHeader = *(aod->GetHeader());
daa81fe5 355 }
5a922844 356 if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
c185e0db 357 {
9daedfd1 358 TClonesArray* tracks = aod->GetTracks();
c185e0db 359 new (fgAODTracks) TClonesArray(*tracks);
360 }
417ab5ac 361 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
c185e0db 362 {
9daedfd1 363 TClonesArray* vertices = aod->GetVertices();
c185e0db 364 new (fgAODVertices) TClonesArray(*vertices);
365 }
366 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
367 {
9daedfd1 368 TClonesArray* v0s = aod->GetV0s();
113bc2bd 369 new (fgAODV0s) TClonesArray(*v0s);
c185e0db 370 }
371 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
372 {
9daedfd1 373 *fgAODTracklets = *aod->GetTracklets();
c185e0db 374 }
375 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
376 {
9daedfd1 377 TClonesArray* pmdClusters = aod->GetPmdClusters();
113bc2bd 378 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
c185e0db 379 }
5a922844 380 if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
c185e0db 381 {
9daedfd1 382 TClonesArray* jets = aod->GetJets();
113bc2bd 383 new (fgAODJets) TClonesArray(*jets);
c185e0db 384 }
385 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
386 {
9daedfd1 387 TClonesArray* fmdClusters = aod->GetFmdClusters();
113bc2bd 388 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
c185e0db 389 }
5a922844 390 if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
c185e0db 391 {
9daedfd1 392 TClonesArray* caloClusters = aod->GetCaloClusters();
113bc2bd 393 new (fgAODCaloClusters) TClonesArray(*caloClusters);
394 }
395
396 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
397 {
9daedfd1 398 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
113bc2bd 399 new (fgAODMCParticles) TClonesArray(*mcParticles);
c185e0db 400 }
866d8d78 401
402 if ((handler->NeedsDimuonsBranchReplication() || merging) && (fgAODDimuons))
403 {
8f6e7d10 404 fgAODDimuons->Clear();
405 TClonesArray& dimuons = *fgAODDimuons;
406 TClonesArray& tracksnew = *fgAODTracks;
407
397081d5 408 Int_t nMuonTrack[100];
409 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 0;
8f6e7d10 410 Int_t nMuons=0;
411 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
412 AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
413 if(track->IsMuonTrack()) {
414 nMuonTrack[nMuons]= ii;
415 nMuons++;
416 }
417 }
418 Int_t jDimuons=0;
419 if(nMuons >= 2){
420 for(Int_t i = 0; i < nMuons; i++){
421 Int_t index0 = nMuonTrack[i];
422 for(Int_t j = i+1; j < nMuons; j++){
423 Int_t index1 = nMuonTrack[j];
8f6e7d10 424 tracksnew.At(index0)->ResetBit(kIsReferenced);
425 tracksnew.At(index0)->SetUniqueID(0);
426 tracksnew.At(index1)->ResetBit(kIsReferenced);
427 tracksnew.At(index1)->SetUniqueID(0);
428 new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
429 }
430 }
431 }
866d8d78 432 }
8f6e7d10 433
5a922844 434 // Additional merging if needed
435 if (merging) {
113bc2bd 436 // mcParticles
437 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
438 Int_t npart = mcparticles->GetEntries();
439 Int_t nc = fgAODMCParticles->GetEntries();
440 Int_t nc0 = nc;
441
442 for (Int_t i = 0; i < npart; i++) {
443 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
c8de791b 444 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
113bc2bd 445 }
446
5a922844 447 // tracks
448 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
449 Int_t ntr = tracks->GetEntries();
113bc2bd 450 nc = fgAODTracks->GetEntries();
5a922844 451 for (Int_t i = 0; i < ntr; i++) {
452 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
453 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
113bc2bd 454 newtrack->SetLabel(newtrack->GetLabel() + nc0);
5a922844 455 }
c8de791b 456
457 for (Int_t i = 0; i < nc; i++)
458 {
459 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
460 track->ResetBit(kIsReferenced);
461 track->SetUniqueID(0);
462 }
463
464
5a922844 465 // clusters
466 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
467 Int_t ncl = clusters->GetEntries();
468 nc = fgAODCaloClusters->GetEntries();
469 for (Int_t i = 0; i < ncl; i++) {
470 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
c8de791b 471 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
5a922844 472 }
473 // cells
474 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
475 Int_t ncells = cellsA->GetNumberOfCells();
476 nc = fgAODEmcalCells->GetNumberOfCells();
477
478 for (Int_t i = 0; i < ncells; i++) {
479 Int_t cn = cellsA->GetCellNumber(i);
480 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
481 if (pos >= 0) {
482 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
483 fgAODEmcalCells->SetCell(pos, cn, amp);
484 } else {
485 Double_t amp = cellsA->GetAmplitude(i);
486 fgAODEmcalCells->SetCell(nc++, cn, amp);
487 fgAODEmcalCells->Sort();
488 }
489 }
113bc2bd 490
491
492 } // merging
c185e0db 493
5a922844 494 handler->SetAODIsReplicated();
3f2431c4 495 }
496 }
497
4d0a82af 498// Call the user analysis
2da1d158 499 if (!fMCEventHandler) {
5b173801 500 if (isSelected)
67d77d71 501 UserExec(option);
502 } else {
2da1d158 503 if (isSelected && (fMCEventHandler->InitOk()))
67d77d71 504 UserExec(option);
505 }
90a9a634 506
507// Added protection in case the derived task is not an AOD producer.
60a04972 508 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
509 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
2da1d158 510
511 DisconnectMultiHandler();
5232d0de 512}
513
4d0a82af 514const char* AliAnalysisTaskSE::CurrentFileName()
515{
516// Returns the current file name
259b7a8a 517 if( fInputHandler )
518 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
519 else if( fMCEvent )
520 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 521 else return "";
4d0a82af 522}
5232d0de 523
3cee83d7 524void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
164e94ff 525{
526 // Add a new branch to the aod tree
b9531017 527 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
164e94ff 528 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
529 if (handler) {
3cee83d7 530 handler->AddBranch(cname, addobj, fname);
164e94ff 531 }
532}
3cee83d7 533
534Bool_t AliAnalysisTaskSE::IsStandardAOD() const
535{
536// Check if the output AOD handler is configured for standard or delta AOD.
537// Users should first check that AODEvent() returns non-null.
b9531017 538 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
3cee83d7 539 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
540 if (!handler) {
541 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
542 return kTRUE;
543 }
544 return handler->IsStandard();
545}
1ec2c8dc 546
547Bool_t AliAnalysisTaskSE::Notify()
548{
9a587f77 549 return (UserNotify());
1ec2c8dc 550}
551
cec9e119 552const AliEventTag *AliAnalysisTaskSE::EventTag() const
553{
554// Returns tag for the current event, if any. The return value should always be checked by the user.
555 if (!fInputHandler) {
556 Error("EventTag", "Input handler not yet available. Call this in UserExec");
557 return NULL;
558 }
559 return fInputHandler->GetEventTag();
560}
1ec2c8dc 561
cec9e119 562void AliAnalysisTaskSE::LoadBranches() const
563{
564// Load all branches declared in fBranchNames data member of the parent class.
565// Should be called in UserExec.
566 if (!fInputHandler) {
567 Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
568 return;
569 }
570 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
571 if (mgr->GetAutoBranchLoading()) return;
572 TString taskbranches;
573 GetBranches(fInputHandler->GetDataType(), taskbranches);
574 if (taskbranches.IsNull()) return;
575 TObjArray *arr = taskbranches.Tokenize(",");
576 TIter next(arr);
577 TObject *obj;
578 while ((obj=next())) mgr->LoadBranch(obj->GetName());
579}
2da1d158 580
581
582//_________________________________________________________________________________________________
583void AliAnalysisTaskSE::ConnectMultiHandler()
584{
585 //
586 // Connect MultiHandler
587 //
588 fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
589 fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
590 if (fMultiInputHandler) {
2da1d158 591 fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
592 fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
bae44bb7 593 } else {
594 fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
2da1d158 595 }
596 if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
597}
598
599//_________________________________________________________________________________________________
600void AliAnalysisTaskSE::DisconnectMultiHandler()
601{
602 //
603 // Disconnect MultiHandler
604 //
605 if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
606}