Coverity defect corrected.
[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)
93dca4c6 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 }
90a9a634 214
c185e0db 215 // Check if AOD replication has been required
3b9a675c 216 if (handler) {
217 fOutputAOD = handler->GetAOD();
218 fTreeA = handler->GetTree();
d7c65b93 219 if (fOutputAOD && !(handler->IsStandard())) {
abf59beb 220 if ((handler->NeedsHeaderReplication() || merging) && !(fgAODHeader))
c185e0db 221 {
87022830 222 if (fDebug > 1) AliInfo("Replicating header");
223 fgAODHeader = new AliAODHeader;
224 handler->AddBranch("AliAODHeader", &fgAODHeader);
c185e0db 225 }
5a922844 226 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
c185e0db 227 {
228 if (fDebug > 1) AliInfo("Replicating track branch\n");
229 fgAODTracks = new TClonesArray("AliAODTrack",500);
87022830 230 fgAODTracks->SetName("tracks");
c185e0db 231 handler->AddBranch("TClonesArray", &fgAODTracks);
232 }
4dd8a1c8 233 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
c185e0db 234 {
235 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
236 fgAODVertices = new TClonesArray("AliAODVertex",500);
87022830 237 fgAODVertices->SetName("vertices");
c185e0db 238 handler->AddBranch("TClonesArray", &fgAODVertices);
239 }
240 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
241 {
242 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
243 fgAODV0s = new TClonesArray("AliAODv0",500);
87022830 244 fgAODV0s->SetName("v0s");
c185e0db 245 handler->AddBranch("TClonesArray", &fgAODV0s);
246 }
247 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
248 {
249 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
87022830 250 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
c185e0db 251 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
252 }
253 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
254 {
255 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
256 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
87022830 257 fgAODPMDClusters->SetName("pmdClusters");
c185e0db 258 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
259 }
5a922844 260 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
c185e0db 261 {
262 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
263 fgAODJets = new TClonesArray("AliAODJet",500);
87022830 264 fgAODJets->SetName("jets");
c185e0db 265 handler->AddBranch("TClonesArray", &fgAODJets);
266 }
267 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
268 {
269 AliInfo("Replicating FMDClusters branch\n");
270 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
87022830 271 fgAODFMDClusters->SetName("fmdClusters");
c185e0db 272 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
273 }
5a922844 274 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
c185e0db 275 {
276 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
277 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
87022830 278 fgAODCaloClusters->SetName("caloClusters");
c185e0db 279 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
5a922844 280
93dca4c6 281 fgAODEmcalCells = new AliAODCaloCells("emcalCells","emcalCells",AliVCaloCells::kEMCALCell);
5a922844 282 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
283
93dca4c6 284 fgAODPhosCells = new AliAODCaloCells("phosCells","phosCells",AliVCaloCells::kPHOSCell);
5a922844 285 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
93dca4c6 286
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 }
cdf456b5 307 ConnectMultiHandler();
5232d0de 308 UserCreateOutputObjects();
cdf456b5 309 DisconnectMultiHandler();
5232d0de 310}
311
312void AliAnalysisTaskSE::Exec(Option_t* option)
313{
314//
315// Exec analysis of one event
2da1d158 316
317 ConnectMultiHandler();
318
27704f6c 319 if ( fDebug >= 10)
320 printf("Task is active %5d\n", IsActive());
8f6e7d10 321
259b7a8a 322 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
fdda6b64 323//
b9531017 324 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
fdda6b64 325 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
b9531017 326
fdda6b64 327 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
328//
5b173801 329// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
330 UInt_t isSelected = AliVEvent::kAny;
331 if( fInputHandler && fInputHandler->GetEventSelection()) {
ca9cb319 332 // Get the actual offline trigger mask for the event and AND it with the
333 // requested mask. If no mask requested select by default the event.
334 if (fOfflineTriggerMask)
335 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
04a79fa0 336 }
5b173801 337// Functionality below moved in the filter tasks (AG)
338// if (handler) handler->SetFillAOD(isSelected);
9b98c4df 339
80ce1b4e 340 if( fInputHandler ) {
341 fEntry = fInputHandler->GetReadEntry();
342 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
343 }
344
bf666461 345
39b02a2e 346// Notify the change of run number
276b8751 347 if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
39b02a2e 348 fCurrentRunNumber = InputEvent()->GetRunNumber();
349 NotifyRun();
350 }
04a79fa0 351
259b7a8a 352 else if( fMCEvent )
353 fEntry = fMCEvent->Header()->GetEvent();
4d0a82af 354 if ( !((Entry()-1)%100) && fDebug > 0)
259b7a8a 355 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
3f2431c4 356
fdda6b64 357
358
c185e0db 359
360 if (handler && aodH) {
04a79fa0 361 fMCEvent = aodH->MCEvent();
5a922844 362 Bool_t merging = aodH->GetMergeEvents();
1fbe12d4 363
364 // Do not analyze merged events if last embedded file has less events than normal event,
365 // skip analysis after last embeded event
366 if(merging){
367 if(aodH->GetReadEntry() + aodH->GetMergeOffset() >= aodH->GetTreeToMerge()->GetEntriesFast()){
368 //printf("Skip Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
369
370 // Do I need to add the lines before the return?
371 // Added protection in case the derived task is not an AOD producer.
372 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
373 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
374
375 DisconnectMultiHandler();
376
377 return;
378 }
379 //else printf("MERGE Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
380 }
381
9daedfd1 382 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
383
384 if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
abf59beb 385 if ((handler->NeedsHeaderReplication() || merging) && (fgAODHeader))
c185e0db 386 {
61d5496b 387 // copy the contents by assigment
9daedfd1 388 *fgAODHeader = *(aod->GetHeader());
daa81fe5 389 }
abf59beb 390 if ((handler->NeedsTracksBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODTracks))
c185e0db 391 {
9daedfd1 392 TClonesArray* tracks = aod->GetTracks();
c185e0db 393 new (fgAODTracks) TClonesArray(*tracks);
394 }
417ab5ac 395 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
c185e0db 396 {
9daedfd1 397 TClonesArray* vertices = aod->GetVertices();
c185e0db 398 new (fgAODVertices) TClonesArray(*vertices);
399 }
400 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
401 {
9daedfd1 402 TClonesArray* v0s = aod->GetV0s();
113bc2bd 403 new (fgAODV0s) TClonesArray(*v0s);
c185e0db 404 }
405 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
406 {
9daedfd1 407 *fgAODTracklets = *aod->GetTracklets();
c185e0db 408 }
409 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
410 {
9daedfd1 411 TClonesArray* pmdClusters = aod->GetPmdClusters();
113bc2bd 412 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
c185e0db 413 }
abf59beb 414 if ((handler->NeedsJetsBranchReplication() || (merging &&aodH->GetMergeTracks())) && (fgAODJets))
c185e0db 415 {
9daedfd1 416 TClonesArray* jets = aod->GetJets();
113bc2bd 417 new (fgAODJets) TClonesArray(*jets);
c185e0db 418 }
419 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
420 {
9daedfd1 421 TClonesArray* fmdClusters = aod->GetFmdClusters();
113bc2bd 422 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
c185e0db 423 }
abf59beb 424 if ((handler->NeedsCaloClustersBranchReplication() ||
425 (merging && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())))
426 && (fgAODCaloClusters))
c185e0db 427 {
9daedfd1 428 TClonesArray* caloClusters = aod->GetCaloClusters();
113bc2bd 429 new (fgAODCaloClusters) TClonesArray(*caloClusters);
430 }
431
432 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
433 {
9daedfd1 434 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
93dca4c6 435 if( mcParticles )
436 new (fgAODMCParticles) TClonesArray(*mcParticles);
c185e0db 437 }
866d8d78 438
abf59beb 439 if ((handler->NeedsDimuonsBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODDimuons))
866d8d78 440 {
8f6e7d10 441 fgAODDimuons->Clear();
442 TClonesArray& dimuons = *fgAODDimuons;
443 TClonesArray& tracksnew = *fgAODTracks;
444
397081d5 445 Int_t nMuonTrack[100];
446 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 0;
8f6e7d10 447 Int_t nMuons=0;
448 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
449 AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
450 if(track->IsMuonTrack()) {
451 nMuonTrack[nMuons]= ii;
452 nMuons++;
453 }
454 }
455 Int_t jDimuons=0;
456 if(nMuons >= 2){
457 for(Int_t i = 0; i < nMuons; i++){
458 Int_t index0 = nMuonTrack[i];
459 for(Int_t j = i+1; j < nMuons; j++){
460 Int_t index1 = nMuonTrack[j];
8f6e7d10 461 tracksnew.At(index0)->ResetBit(kIsReferenced);
462 tracksnew.At(index0)->SetUniqueID(0);
463 tracksnew.At(index1)->ResetBit(kIsReferenced);
464 tracksnew.At(index1)->SetUniqueID(0);
465 new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
466 }
467 }
468 }
866d8d78 469 }
5a922844 470 // Additional merging if needed
471 if (merging) {
93dca4c6 472 Int_t nc;
473
113bc2bd 474 // mcParticles
475 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
93dca4c6 476 if( mcparticles ){
477 Int_t npart = mcparticles->GetEntries();
478 nc = fgAODMCParticles->GetEntries();
479
480 for (Int_t i = 0; i < npart; i++) {
113bc2bd 481 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
c8de791b 482 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
93dca4c6 483 }
113bc2bd 484 }
93dca4c6 485
5a922844 486 // tracks
487 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
abf59beb 488 if(tracks && aodH->GetMergeTracks()){
93dca4c6 489 Int_t ntr = tracks->GetEntries();
490 nc = fgAODTracks->GetEntries();
491 for (Int_t i = 0; i < ntr; i++) {
5a922844 492 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
493 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
93dca4c6 494 newtrack->SetLabel(newtrack->GetLabel() + fgAODMCParticles->GetEntries());
495 }
496
497 for (Int_t i = 0; i < nc; i++)
498 {
499 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
500 track->ResetBit(kIsReferenced);
501 track->SetUniqueID(0);
502 }
c8de791b 503 }
504
5a922844 505 // clusters
506 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
abf59beb 507 if( clusters && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())) {
93dca4c6 508 Int_t ncl = clusters->GetEntries();
509 nc = fgAODCaloClusters->GetEntries();
510 for (Int_t i = 0; i < ncl; i++) {
5a922844 511 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
abf59beb 512 if(cluster->IsEMCAL() && !aodH->GetMergeEMCALClusters() ) continue;
513 if(cluster->IsPHOS() && !aodH->GetMergePHOSClusters() ) continue;
c8de791b 514 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
93dca4c6 515 }
516 }
517
518 // EMCAL cells
519 //*fgAODEmcalCells = *(aod->GetEMCALCells()); // This will be valid after 10.Mar.2011.
abf59beb 520 if(aodH->GetMergeEMCALCells()) {
521 AliAODCaloCells* copycells = aod->GetEMCALCells();
522 fgAODEmcalCells->CreateContainer(copycells->GetNumberOfCells());
523 nc = copycells->GetNumberOfCells();
d8e47d0b 524 while( nc-- ){ fgAODEmcalCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc)); }
525
abf59beb 526 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
527 if( cellsA ){
528 Int_t ncells = cellsA->GetNumberOfCells();
529 nc = fgAODEmcalCells->GetNumberOfCells();
530 for (Int_t i = 0; i < ncells; i++) {
531 Int_t cn = cellsA->GetCellNumber(i);
532 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
533 if (pos >= 0) {
534 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
535 fgAODEmcalCells->SetCell(pos, cn, amp);
536 } else {
537 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODEmcalCells);
538 fgAODEmcalCells->CreateContainer(nc+1);
539 Int_t nn = copycells1->GetNumberOfCells();
540 while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn)); }
541 fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i));
542 delete copycells1;
543 }
544 }
545 fgAODEmcalCells->Sort();
5a922844 546 }
abf59beb 547 } // merge emcal cells
548
113bc2bd 549
93dca4c6 550 // PHOS cells
551 //*fgAODPhosCells = *(aod->GetPHOSCells()); // This will be valid after 10.Mar.2011.
abf59beb 552 if(aodH->GetMergePHOSCells()) {
553 AliAODCaloCells* copycells = aod->GetPHOSCells();
554 fgAODPhosCells->CreateContainer(copycells->GetNumberOfCells());
555 nc = copycells->GetNumberOfCells();
556 while( nc-- ){ fgAODPhosCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc)); }
557 AliAODCaloCells* cellsP = aodH->GetEventToMerge()->GetPHOSCells();
558 if( cellsP ){
559 Int_t ncellsP = cellsP->GetNumberOfCells();
560 nc = fgAODPhosCells->GetNumberOfCells();
561
562 for (Int_t i = 0; i < ncellsP; i++) {
563 Int_t cn = cellsP->GetCellNumber(i);
564 Int_t pos = fgAODPhosCells->GetCellPosition(cn);
565 if (pos >= 0) {
566 Double_t amp = cellsP->GetAmplitude(i) + fgAODPhosCells->GetAmplitude(pos);
567 fgAODPhosCells->SetCell(pos, cn, amp);
568 } else {
569 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODPhosCells);
570 fgAODPhosCells->CreateContainer(nc+1);
571 Int_t nn = copycells1->GetNumberOfCells();
572 while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn)); }
573 fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i));
574 delete copycells1;
575 }
576 }
577 fgAODPhosCells->Sort();
93dca4c6 578 }
abf59beb 579 } // Merge PHOS Cells
93dca4c6 580
113bc2bd 581 } // merging
c185e0db 582
5a922844 583 handler->SetAODIsReplicated();
3f2431c4 584 }
585 }
586
93dca4c6 587
4d0a82af 588// Call the user analysis
2da1d158 589 if (!fMCEventHandler) {
5b173801 590 if (isSelected)
67d77d71 591 UserExec(option);
592 } else {
2da1d158 593 if (isSelected && (fMCEventHandler->InitOk()))
67d77d71 594 UserExec(option);
595 }
90a9a634 596
597// Added protection in case the derived task is not an AOD producer.
60a04972 598 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
599 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
93dca4c6 600
2da1d158 601 DisconnectMultiHandler();
5232d0de 602}
603
4d0a82af 604const char* AliAnalysisTaskSE::CurrentFileName()
605{
606// Returns the current file name
259b7a8a 607 if( fInputHandler )
608 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
609 else if( fMCEvent )
610 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 611 else return "";
4d0a82af 612}
5232d0de 613
3cee83d7 614void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
164e94ff 615{
616 // Add a new branch to the aod tree
b9531017 617 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
164e94ff 618 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
619 if (handler) {
3cee83d7 620 handler->AddBranch(cname, addobj, fname);
164e94ff 621 }
622}
3cee83d7 623
624Bool_t AliAnalysisTaskSE::IsStandardAOD() const
625{
626// Check if the output AOD handler is configured for standard or delta AOD.
627// Users should first check that AODEvent() returns non-null.
b9531017 628 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
3cee83d7 629 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
630 if (!handler) {
631 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
632 return kTRUE;
633 }
634 return handler->IsStandard();
635}
1ec2c8dc 636
637Bool_t AliAnalysisTaskSE::Notify()
638{
9a587f77 639 return (UserNotify());
1ec2c8dc 640}
641
cec9e119 642const AliEventTag *AliAnalysisTaskSE::EventTag() const
643{
644// Returns tag for the current event, if any. The return value should always be checked by the user.
645 if (!fInputHandler) {
646 Error("EventTag", "Input handler not yet available. Call this in UserExec");
647 return NULL;
648 }
649 return fInputHandler->GetEventTag();
650}
1ec2c8dc 651
cec9e119 652void AliAnalysisTaskSE::LoadBranches() const
653{
654// Load all branches declared in fBranchNames data member of the parent class.
655// Should be called in UserExec.
656 if (!fInputHandler) {
657 Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
658 return;
659 }
660 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
661 if (mgr->GetAutoBranchLoading()) return;
662 TString taskbranches;
663 GetBranches(fInputHandler->GetDataType(), taskbranches);
664 if (taskbranches.IsNull()) return;
665 TObjArray *arr = taskbranches.Tokenize(",");
666 TIter next(arr);
667 TObject *obj;
668 while ((obj=next())) mgr->LoadBranch(obj->GetName());
669}
2da1d158 670
671
672//_________________________________________________________________________________________________
673void AliAnalysisTaskSE::ConnectMultiHandler()
674{
675 //
676 // Connect MultiHandler
677 //
678 fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
679 fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
680 if (fMultiInputHandler) {
2da1d158 681 fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
682 fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
bae44bb7 683 } else {
684 fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
2da1d158 685 }
686 if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
687}
688
689//_________________________________________________________________________________________________
690void AliAnalysisTaskSE::DisconnectMultiHandler()
691{
692 //
693 // Disconnect MultiHandler
694 //
695 if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
696}