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