revert previous commit on this class
[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"
720f7306 38#include "AliAODCaloTrigger.h"
113bc2bd 39#include "AliAODMCParticle.h"
5232d0de 40#include "AliVEvent.h"
41#include "AliAODHandler.h"
3f2431c4 42#include "AliAODInputHandler.h"
5232d0de 43#include "AliMCEventHandler.h"
44#include "AliInputEventHandler.h"
2da1d158 45#include "AliMultiInputEventHandler.h"
620ad672 46#include "AliESDInputHandler.h"
5232d0de 47#include "AliMCEvent.h"
48#include "AliStack.h"
4d0a82af 49#include "AliLog.h"
866d8d78 50#include "AliAODDimuon.h"
5232d0de 51
52
53ClassImp(AliAnalysisTaskSE)
54
55////////////////////////////////////////////////////////////////////////
90a9a634 56AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
57TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
58TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
59TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
60TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
61TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
62TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
63TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
64TClonesArray* AliAnalysisTaskSE::fgAODMCParticles = NULL;
65AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
66AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells = NULL;
67AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells = NULL;
720f7306 68AliAODCaloTrigger* AliAnalysisTaskSE::fgAODEMCALTrigger = NULL;
69AliAODCaloTrigger* AliAnalysisTaskSE::fgAODPHOSTrigger = NULL;
866d8d78 70TClonesArray* AliAnalysisTaskSE::fgAODDimuons = NULL;
5232d0de 71
72AliAnalysisTaskSE::AliAnalysisTaskSE():
73 AliAnalysisTask(),
74 fDebug(0),
80d13558 75 fEntry(0),
5232d0de 76 fInputEvent(0x0),
620ad672 77 fESDfriend(0x0),
80d13558 78 fInputHandler(0x0),
5232d0de 79 fOutputAOD(0x0),
80 fMCEvent(0x0),
9a587f77 81 fTreeA(0x0),
82 fCurrentRunNumber(-1),
90a9a634 83 fHistosQA(0x0),
2da1d158 84 fOfflineTriggerMask(0),
85 fMultiInputHandler(0),
86 fMCEventHandler(0)
5232d0de 87{
88 // Default constructor
89}
90
91AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
92 AliAnalysisTask(name, "AnalysisTaskSE"),
93 fDebug(0),
80d13558 94 fEntry(0),
5232d0de 95 fInputEvent(0x0),
620ad672 96 fESDfriend(0x0),
80d13558 97 fInputHandler(0x0),
5232d0de 98 fOutputAOD(0x0),
99 fMCEvent(0x0),
1ec2c8dc 100 fTreeA(0x0),
101 fCurrentRunNumber(-1),
90a9a634 102 fHistosQA(0x0),
2da1d158 103 fOfflineTriggerMask(0),
104 fMultiInputHandler(0),
105 fMCEventHandler(0)
5232d0de 106{
107 // Default constructor
108 DefineInput (0, TChain::Class());
109 DefineOutput(0, TTree::Class());
110}
111
26f071d8 112AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
113 AliAnalysisTask(obj),
114 fDebug(0),
80d13558 115 fEntry(0),
26f071d8 116 fInputEvent(0x0),
620ad672 117 fESDfriend(0x0),
80d13558 118 fInputHandler(0x0),
26f071d8 119 fOutputAOD(0x0),
120 fMCEvent(0x0),
1ec2c8dc 121 fTreeA(0x0),
122 fCurrentRunNumber(-1),
90a9a634 123 fHistosQA(0x0),
2da1d158 124 fOfflineTriggerMask(0),
125 fMultiInputHandler(obj.fMultiInputHandler),
126 fMCEventHandler(obj.fMCEventHandler)
26f071d8 127{
128// Copy constructor
1ec2c8dc 129 fDebug = obj.fDebug;
130 fEntry = obj.fEntry;
131 fInputEvent = obj.fInputEvent;
620ad672 132 fESDfriend = obj.fESDfriend;
1ec2c8dc 133 fInputHandler = obj.fInputHandler;
134 fOutputAOD = obj.fOutputAOD;
135 fMCEvent = obj.fMCEvent;
136 fTreeA = obj.fTreeA;
137 fCurrentRunNumber = obj.fCurrentRunNumber;
138 fHistosQA = obj.fHistosQA;
90a9a634 139
26f071d8 140}
141
142
143AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
144{
145// Assignment
e99fb5c9 146 if(&other == this) return *this;
147 AliAnalysisTask::operator=(other);
148
26f071d8 149 AliAnalysisTask::operator=(other);
1ec2c8dc 150 fDebug = other.fDebug;
151 fEntry = other.fEntry;
152 fInputEvent = other.fInputEvent;
620ad672 153 fESDfriend = other.fESDfriend;
1ec2c8dc 154 fInputHandler = other.fInputHandler;
155 fOutputAOD = other.fOutputAOD;
156 fMCEvent = other.fMCEvent;
157 fTreeA = other.fTreeA;
158 fCurrentRunNumber = other.fCurrentRunNumber;
159 fHistosQA = other.fHistosQA;
0c6c629b 160 fOfflineTriggerMask = other.fOfflineTriggerMask;
2da1d158 161 fMultiInputHandler = other.fMultiInputHandler;
162 fMCEventHandler = other.fMCEventHandler;
26f071d8 163 return *this;
164}
5232d0de 165
4747b4a7 166//______________________________________________________________________________
5232d0de 167void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
168{
169// Connect the input data
170 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
2da1d158 171
172 // Connect input handlers (multi input handler is handled)
93dca4c6 173 ConnectMultiHandler();
174
259b7a8a 175 if (fInputHandler) {
620ad672 176 if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
177 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
178
179 fInputEvent = fInputHandler->GetEvent();
259b7a8a 180 } else if( fMCEvent ) {
181 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
182 } else {
183 AliError("No Input Event Handler connected") ;
184 return ;
185 }
2da1d158 186 // Disconnect multi handler
187 DisconnectMultiHandler();
5232d0de 188}
189
190void AliAnalysisTaskSE::CreateOutputObjects()
191{
192// Create the output container
193//
194// Default AOD
195 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
196
b9531017 197 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
259b7a8a 198 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
5232d0de 199
5a922844 200 Bool_t merging = kFALSE;
201 AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
202 if (aodIH) {
203 if (aodIH->GetMergeEvents()) merging = kTRUE;
204 }
90a9a634 205
c185e0db 206 // Check if AOD replication has been required
3b9a675c 207 if (handler) {
208 fOutputAOD = handler->GetAOD();
209 fTreeA = handler->GetTree();
d7c65b93 210 if (fOutputAOD && !(handler->IsStandard())) {
abf59beb 211 if ((handler->NeedsHeaderReplication() || merging) && !(fgAODHeader))
c185e0db 212 {
87022830 213 if (fDebug > 1) AliInfo("Replicating header");
214 fgAODHeader = new AliAODHeader;
215 handler->AddBranch("AliAODHeader", &fgAODHeader);
c185e0db 216 }
5a922844 217 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
c185e0db 218 {
219 if (fDebug > 1) AliInfo("Replicating track branch\n");
220 fgAODTracks = new TClonesArray("AliAODTrack",500);
87022830 221 fgAODTracks->SetName("tracks");
c185e0db 222 handler->AddBranch("TClonesArray", &fgAODTracks);
223 }
4dd8a1c8 224 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
c185e0db 225 {
226 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
227 fgAODVertices = new TClonesArray("AliAODVertex",500);
87022830 228 fgAODVertices->SetName("vertices");
c185e0db 229 handler->AddBranch("TClonesArray", &fgAODVertices);
230 }
231 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
232 {
233 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
234 fgAODV0s = new TClonesArray("AliAODv0",500);
87022830 235 fgAODV0s->SetName("v0s");
c185e0db 236 handler->AddBranch("TClonesArray", &fgAODV0s);
237 }
238 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
239 {
240 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
87022830 241 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
c185e0db 242 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
243 }
244 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
245 {
246 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
247 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
87022830 248 fgAODPMDClusters->SetName("pmdClusters");
c185e0db 249 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
250 }
5a922844 251 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
c185e0db 252 {
253 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
254 fgAODJets = new TClonesArray("AliAODJet",500);
87022830 255 fgAODJets->SetName("jets");
c185e0db 256 handler->AddBranch("TClonesArray", &fgAODJets);
257 }
258 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
259 {
260 AliInfo("Replicating FMDClusters branch\n");
261 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
87022830 262 fgAODFMDClusters->SetName("fmdClusters");
c185e0db 263 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
264 }
5a922844 265 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
c185e0db 266 {
267 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
268 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
87022830 269 fgAODCaloClusters->SetName("caloClusters");
c185e0db 270 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
5a922844 271
93dca4c6 272 fgAODEmcalCells = new AliAODCaloCells("emcalCells","emcalCells",AliVCaloCells::kEMCALCell);
5a922844 273 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
274
93dca4c6 275 fgAODPhosCells = new AliAODCaloCells("phosCells","phosCells",AliVCaloCells::kPHOSCell);
5a922844 276 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
720f7306 277 }
278 if ((handler->NeedsCaloTriggerBranchReplication() || merging) && !(fgAODEMCALTrigger))
279 {
280 if (fDebug > 1) AliInfo("Replicating EMCAL Calo Trigger branches\n");
281 fgAODEMCALTrigger = new AliAODCaloTrigger("emcalTrigger","emcalTrigger");
282 handler->AddBranch("AliAODCaloTrigger", &fgAODEMCALTrigger);
283 }
284 if ((handler->NeedsCaloTriggerBranchReplication() || merging) && !(fgAODPHOSTrigger))
285 {
286 if (fDebug > 1) AliInfo("Replicating PHOS Calo Trigger branches\n");
287 fgAODPHOSTrigger = new AliAODCaloTrigger("phosTrigger","phosTrigger");
288 handler->AddBranch("AliAODCaloTrigger", &fgAODPHOSTrigger);
c185e0db 289 }
113bc2bd 290 if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))
291 {
292 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
293 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
294 fgAODMCParticles->SetName("mcparticles");
295 handler->AddBranch("TClonesArray", &fgAODMCParticles);
296 }
866d8d78 297 if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))
298 {
299 if (fDebug > 1) AliInfo("Replicating dimuon branch\n");
300 fgAODDimuons = new TClonesArray("AliAODDimuon",0);
301 fgAODDimuons->SetName("dimuons");
302 handler->AddBranch("TClonesArray", &fgAODDimuons);
303 }
304
5a922844 305 // cache the pointerd in the AODEvent
306 fOutputAOD->GetStdContent();
3f2431c4 307 }
3b9a675c 308 }
cdf456b5 309 ConnectMultiHandler();
5232d0de 310 UserCreateOutputObjects();
cdf456b5 311 DisconnectMultiHandler();
5232d0de 312}
313
314void AliAnalysisTaskSE::Exec(Option_t* option)
315{
316//
317// Exec analysis of one event
2da1d158 318
319 ConnectMultiHandler();
320
27704f6c 321 if ( fDebug >= 10)
322 printf("Task is active %5d\n", IsActive());
8f6e7d10 323
259b7a8a 324 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
fdda6b64 325//
b9531017 326 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
fdda6b64 327 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
b9531017 328
fdda6b64 329 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
330//
5b173801 331// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
332 UInt_t isSelected = AliVEvent::kAny;
61200abd 333 if( fInputHandler && (fInputHandler->GetEventSelection() || aodH)) {
ca9cb319 334 // Get the actual offline trigger mask for the event and AND it with the
335 // requested mask. If no mask requested select by default the event.
336 if (fOfflineTriggerMask)
337 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
04a79fa0 338 }
5b173801 339// Functionality below moved in the filter tasks (AG)
340// if (handler) handler->SetFillAOD(isSelected);
9b98c4df 341
80ce1b4e 342 if( fInputHandler ) {
343 fEntry = fInputHandler->GetReadEntry();
344 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
345 }
346
bf666461 347
39b02a2e 348// Notify the change of run number
276b8751 349 if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
39b02a2e 350 fCurrentRunNumber = InputEvent()->GetRunNumber();
351 NotifyRun();
352 }
04a79fa0 353
259b7a8a 354 else if( fMCEvent )
355 fEntry = fMCEvent->Header()->GetEvent();
4d0a82af 356 if ( !((Entry()-1)%100) && fDebug > 0)
259b7a8a 357 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
3f2431c4 358
fdda6b64 359
360
c185e0db 361
362 if (handler && aodH) {
04a79fa0 363 fMCEvent = aodH->MCEvent();
5a922844 364 Bool_t merging = aodH->GetMergeEvents();
1fbe12d4 365
366 // Do not analyze merged events if last embedded file has less events than normal event,
367 // skip analysis after last embeded event
368 if(merging){
369 if(aodH->GetReadEntry() + aodH->GetMergeOffset() >= aodH->GetTreeToMerge()->GetEntriesFast()){
370 //printf("Skip Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
371
372 // Do I need to add the lines before the return?
373 // Added protection in case the derived task is not an AOD producer.
374 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
375 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
376
377 DisconnectMultiHandler();
378
379 return;
380 }
381 //else printf("MERGE Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
382 }
383
9daedfd1 384 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
385
386 if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
abf59beb 387 if ((handler->NeedsHeaderReplication() || merging) && (fgAODHeader))
c185e0db 388 {
61d5496b 389 // copy the contents by assigment
9daedfd1 390 *fgAODHeader = *(aod->GetHeader());
daa81fe5 391 }
abf59beb 392 if ((handler->NeedsTracksBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODTracks))
c185e0db 393 {
9daedfd1 394 TClonesArray* tracks = aod->GetTracks();
c185e0db 395 new (fgAODTracks) TClonesArray(*tracks);
396 }
417ab5ac 397 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
c185e0db 398 {
9daedfd1 399 TClonesArray* vertices = aod->GetVertices();
c185e0db 400 new (fgAODVertices) TClonesArray(*vertices);
401 }
402 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
403 {
9daedfd1 404 TClonesArray* v0s = aod->GetV0s();
113bc2bd 405 new (fgAODV0s) TClonesArray(*v0s);
c185e0db 406 }
407 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
408 {
9daedfd1 409 *fgAODTracklets = *aod->GetTracklets();
c185e0db 410 }
411 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
412 {
9daedfd1 413 TClonesArray* pmdClusters = aod->GetPmdClusters();
113bc2bd 414 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
c185e0db 415 }
abf59beb 416 if ((handler->NeedsJetsBranchReplication() || (merging &&aodH->GetMergeTracks())) && (fgAODJets))
c185e0db 417 {
9daedfd1 418 TClonesArray* jets = aod->GetJets();
113bc2bd 419 new (fgAODJets) TClonesArray(*jets);
c185e0db 420 }
421 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
422 {
9daedfd1 423 TClonesArray* fmdClusters = aod->GetFmdClusters();
113bc2bd 424 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
c185e0db 425 }
abf59beb 426 if ((handler->NeedsCaloClustersBranchReplication() ||
427 (merging && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())))
428 && (fgAODCaloClusters))
c185e0db 429 {
9daedfd1 430 TClonesArray* caloClusters = aod->GetCaloClusters();
113bc2bd 431 new (fgAODCaloClusters) TClonesArray(*caloClusters);
432 }
433
434 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
435 {
9daedfd1 436 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
93dca4c6 437 if( mcParticles )
438 new (fgAODMCParticles) TClonesArray(*mcParticles);
c185e0db 439 }
866d8d78 440
abf59beb 441 if ((handler->NeedsDimuonsBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODDimuons))
866d8d78 442 {
8f6e7d10 443 fgAODDimuons->Clear();
444 TClonesArray& dimuons = *fgAODDimuons;
445 TClonesArray& tracksnew = *fgAODTracks;
446
397081d5 447 Int_t nMuonTrack[100];
448 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 0;
8f6e7d10 449 Int_t nMuons=0;
450 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
451 AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
452 if(track->IsMuonTrack()) {
453 nMuonTrack[nMuons]= ii;
454 nMuons++;
455 }
456 }
457 Int_t jDimuons=0;
458 if(nMuons >= 2){
459 for(Int_t i = 0; i < nMuons; i++){
460 Int_t index0 = nMuonTrack[i];
461 for(Int_t j = i+1; j < nMuons; j++){
462 Int_t index1 = nMuonTrack[j];
8f6e7d10 463 tracksnew.At(index0)->ResetBit(kIsReferenced);
464 tracksnew.At(index0)->SetUniqueID(0);
465 tracksnew.At(index1)->ResetBit(kIsReferenced);
466 tracksnew.At(index1)->SetUniqueID(0);
467 new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
468 }
469 }
470 }
866d8d78 471 }
5a922844 472 // Additional merging if needed
473 if (merging) {
93dca4c6 474 Int_t nc;
475
113bc2bd 476 // mcParticles
477 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
93dca4c6 478 if( mcparticles ){
479 Int_t npart = mcparticles->GetEntries();
480 nc = fgAODMCParticles->GetEntries();
481
482 for (Int_t i = 0; i < npart; i++) {
113bc2bd 483 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
c8de791b 484 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
93dca4c6 485 }
113bc2bd 486 }
93dca4c6 487
5a922844 488 // tracks
489 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
abf59beb 490 if(tracks && aodH->GetMergeTracks()){
93dca4c6 491 Int_t ntr = tracks->GetEntries();
492 nc = fgAODTracks->GetEntries();
493 for (Int_t i = 0; i < ntr; i++) {
5a922844 494 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
495 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
93dca4c6 496 newtrack->SetLabel(newtrack->GetLabel() + fgAODMCParticles->GetEntries());
497 }
498
499 for (Int_t i = 0; i < nc; i++)
500 {
501 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
502 track->ResetBit(kIsReferenced);
503 track->SetUniqueID(0);
504 }
c8de791b 505 }
506
5a922844 507 // clusters
508 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
abf59beb 509 if( clusters && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())) {
93dca4c6 510 Int_t ncl = clusters->GetEntries();
511 nc = fgAODCaloClusters->GetEntries();
512 for (Int_t i = 0; i < ncl; i++) {
5a922844 513 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
abf59beb 514 if(cluster->IsEMCAL() && !aodH->GetMergeEMCALClusters() ) continue;
515 if(cluster->IsPHOS() && !aodH->GetMergePHOSClusters() ) continue;
c8de791b 516 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
93dca4c6 517 }
518 }
519
520 // EMCAL cells
521 //*fgAODEmcalCells = *(aod->GetEMCALCells()); // This will be valid after 10.Mar.2011.
abf59beb 522 if(aodH->GetMergeEMCALCells()) {
523 AliAODCaloCells* copycells = aod->GetEMCALCells();
524 fgAODEmcalCells->CreateContainer(copycells->GetNumberOfCells());
525 nc = copycells->GetNumberOfCells();
d8e47d0b 526 while( nc-- ){ fgAODEmcalCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc)); }
527
abf59beb 528 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
529 if( cellsA ){
530 Int_t ncells = cellsA->GetNumberOfCells();
531 nc = fgAODEmcalCells->GetNumberOfCells();
532 for (Int_t i = 0; i < ncells; i++) {
533 Int_t cn = cellsA->GetCellNumber(i);
534 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
535 if (pos >= 0) {
536 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
537 fgAODEmcalCells->SetCell(pos, cn, amp);
538 } else {
539 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODEmcalCells);
540 fgAODEmcalCells->CreateContainer(nc+1);
541 Int_t nn = copycells1->GetNumberOfCells();
542 while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn)); }
543 fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i));
544 delete copycells1;
545 }
546 }
547 fgAODEmcalCells->Sort();
5a922844 548 }
abf59beb 549 } // merge emcal cells
550
113bc2bd 551
93dca4c6 552 // PHOS cells
553 //*fgAODPhosCells = *(aod->GetPHOSCells()); // This will be valid after 10.Mar.2011.
abf59beb 554 if(aodH->GetMergePHOSCells()) {
555 AliAODCaloCells* copycells = aod->GetPHOSCells();
556 fgAODPhosCells->CreateContainer(copycells->GetNumberOfCells());
557 nc = copycells->GetNumberOfCells();
558 while( nc-- ){ fgAODPhosCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc)); }
559 AliAODCaloCells* cellsP = aodH->GetEventToMerge()->GetPHOSCells();
560 if( cellsP ){
561 Int_t ncellsP = cellsP->GetNumberOfCells();
562 nc = fgAODPhosCells->GetNumberOfCells();
563
564 for (Int_t i = 0; i < ncellsP; i++) {
565 Int_t cn = cellsP->GetCellNumber(i);
566 Int_t pos = fgAODPhosCells->GetCellPosition(cn);
567 if (pos >= 0) {
568 Double_t amp = cellsP->GetAmplitude(i) + fgAODPhosCells->GetAmplitude(pos);
569 fgAODPhosCells->SetCell(pos, cn, amp);
570 } else {
571 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODPhosCells);
572 fgAODPhosCells->CreateContainer(nc+1);
573 Int_t nn = copycells1->GetNumberOfCells();
574 while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn)); }
575 fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i));
576 delete copycells1;
577 }
578 }
579 fgAODPhosCells->Sort();
93dca4c6 580 }
abf59beb 581 } // Merge PHOS Cells
720f7306 582
583 if (aodH->GetMergeEMCALTrigger())
584 {
585 Int_t EMCALts[48][64], px, py, ts;
586 Float_t EMCALfo[48][64], am;
587
588 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
589 {
590 EMCALts[i][j] = 0;
591 EMCALfo[i][j] = 0.;
592 }
593
594 AliAODCaloTrigger& trg0 = *(aod->GetCaloTrigger("EMCAL"));
595
596 trg0.Reset();
597 while (trg0.Next())
598 {
599 trg0.GetPosition(px, py);
600
601 if (px > -1 && py > -1)
602 {
603 trg0.GetL1TimeSum(ts);
604 if (ts > -1) EMCALts[px][py] += ts;
605
606 trg0.GetAmplitude(am);
607 if (am > -1) EMCALfo[px][py] += am;
608 }
609 }
610
611 AliAODCaloTrigger& trg1 = *((aodH->GetEventToMerge())->GetCaloTrigger("EMCAL"));
93dca4c6 612
720f7306 613 trg1.Reset();
614 while (trg1.Next())
615 {
616 trg1.GetPosition(px, py);
617
618 if (px > -1 && py > -1)
619 {
620 trg1.GetL1TimeSum(ts);
621 if (ts > -1) EMCALts[px][py] += ts;
622
623 trg1.GetAmplitude(am);
624 if (am > -1) EMCALfo[px][py] += am;
625 }
626 }
627
628 int nEntries = 0;
629 for (Int_t i = 0; i < 48; i++)
630 for (Int_t j = 0; j < 64; j++)
631 if (EMCALts[i][j] || EMCALfo[i][j]) nEntries++;
632
633 fgAODEMCALTrigger->Allocate(nEntries);
634 Int_t L0times[10]; for (int i = 0; i < 10; i++) L0times[i] = -1;
635
636 for (Int_t i = 0; i < 48; i++)
637 for (Int_t j = 0; j < 64; j++)
638 if (EMCALts[i][j] || EMCALfo[i][j])
639 fgAODEMCALTrigger->Add(i, j, EMCALfo[i][j], -1., L0times, 0, EMCALts[i][j], 0);
640 }
641
642 if (aodH->GetMergePHOSTrigger())
643 {
644 // To be implemented by PHOS
645 }
113bc2bd 646 } // merging
c185e0db 647
5a922844 648 handler->SetAODIsReplicated();
3f2431c4 649 }
650 }
651
93dca4c6 652
4d0a82af 653// Call the user analysis
2da1d158 654 if (!fMCEventHandler) {
5b173801 655 if (isSelected)
67d77d71 656 UserExec(option);
657 } else {
2da1d158 658 if (isSelected && (fMCEventHandler->InitOk()))
67d77d71 659 UserExec(option);
660 }
90a9a634 661
662// Added protection in case the derived task is not an AOD producer.
60a04972 663 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
664 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
93dca4c6 665
2da1d158 666 DisconnectMultiHandler();
5232d0de 667}
668
4d0a82af 669const char* AliAnalysisTaskSE::CurrentFileName()
670{
671// Returns the current file name
259b7a8a 672 if( fInputHandler )
673 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
674 else if( fMCEvent )
675 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 676 else return "";
4d0a82af 677}
5232d0de 678
3cee83d7 679void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
164e94ff 680{
681 // Add a new branch to the aod tree
b9531017 682 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
164e94ff 683 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
684 if (handler) {
3cee83d7 685 handler->AddBranch(cname, addobj, fname);
164e94ff 686 }
687}
3cee83d7 688
689Bool_t AliAnalysisTaskSE::IsStandardAOD() const
690{
691// Check if the output AOD handler is configured for standard or delta AOD.
692// Users should first check that AODEvent() returns non-null.
b9531017 693 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
3cee83d7 694 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
695 if (!handler) {
696 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
697 return kTRUE;
698 }
699 return handler->IsStandard();
700}
1ec2c8dc 701
702Bool_t AliAnalysisTaskSE::Notify()
703{
9a587f77 704 return (UserNotify());
1ec2c8dc 705}
706
cec9e119 707const AliEventTag *AliAnalysisTaskSE::EventTag() const
708{
709// Returns tag for the current event, if any. The return value should always be checked by the user.
710 if (!fInputHandler) {
711 Error("EventTag", "Input handler not yet available. Call this in UserExec");
712 return NULL;
713 }
714 return fInputHandler->GetEventTag();
715}
1ec2c8dc 716
cec9e119 717void AliAnalysisTaskSE::LoadBranches() const
718{
719// Load all branches declared in fBranchNames data member of the parent class.
720// Should be called in UserExec.
721 if (!fInputHandler) {
722 Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
723 return;
724 }
725 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
726 if (mgr->GetAutoBranchLoading()) return;
727 TString taskbranches;
728 GetBranches(fInputHandler->GetDataType(), taskbranches);
729 if (taskbranches.IsNull()) return;
730 TObjArray *arr = taskbranches.Tokenize(",");
731 TIter next(arr);
732 TObject *obj;
733 while ((obj=next())) mgr->LoadBranch(obj->GetName());
734}
2da1d158 735
736
737//_________________________________________________________________________________________________
738void AliAnalysisTaskSE::ConnectMultiHandler()
739{
740 //
741 // Connect MultiHandler
742 //
743 fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
744 fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
745 if (fMultiInputHandler) {
2da1d158 746 fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
747 fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
bae44bb7 748 } else {
749 fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
2da1d158 750 }
751 if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
752}
753
754//_________________________________________________________________________________________________
755void AliAnalysisTaskSE::DisconnectMultiHandler()
756{
757 //
758 // Disconnect MultiHandler
759 //
760 if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
761}