Fixed grep syntax on OS X in the Analysis Plugin
[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////////////////////////////////////////////////////////////////////////
f8faa5ab 58AliVHeader* 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
f6eaa73b 344
2da1d158 345 ConnectMultiHandler();
f6eaa73b 346 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
347 if (mgr->GetDebugLevel() > 1) {
348 if (!mgr->GetTopTasks()->FindObject(this))
349 printf(" -> Executing sub-task %s\n", GetName());
350 }
27704f6c 351 if ( fDebug >= 10)
352 printf("Task is active %5d\n", IsActive());
8f6e7d10 353
259b7a8a 354 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
fdda6b64 355//
f6eaa73b 356 AliAODHandler* handler = dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
b9531017 357
fdda6b64 358 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
359//
5b173801 360// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
361 UInt_t isSelected = AliVEvent::kAny;
61200abd 362 if( fInputHandler && (fInputHandler->GetEventSelection() || aodH)) {
ca9cb319 363 // Get the actual offline trigger mask for the event and AND it with the
364 // requested mask. If no mask requested select by default the event.
365 if (fOfflineTriggerMask)
94908bce 366 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
04a79fa0 367 }
5b173801 368// Functionality below moved in the filter tasks (AG)
369// if (handler) handler->SetFillAOD(isSelected);
9b98c4df 370
80ce1b4e 371 if( fInputHandler ) {
94908bce 372 fEntry = fInputHandler->GetReadEntry();
373 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
80ce1b4e 374 }
375
bf666461 376
94908bce 377 // Notify the change of run number
276b8751 378 if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
39b02a2e 379 fCurrentRunNumber = InputEvent()->GetRunNumber();
380 NotifyRun();
94908bce 381 } else if( fMCEvent )
382 fEntry = fMCEvent->Header()->GetEvent();
3f2431c4 383
94908bce 384 if ( !((Entry()-1)%100) && fDebug > 0)
385 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
fdda6b64 386
94908bce 387 if (aodH) fMCEvent = aodH->MCEvent();
c185e0db 388
389 if (handler && aodH) {
5a922844 390 Bool_t merging = aodH->GetMergeEvents();
94908bce 391 // Do not analyze merged events if last embedded file has less events than normal event,
392 // skip analysis after last embeded event
393 if(merging){
394 if(aodH->GetReadEntry() + aodH->GetMergeOffset() >= aodH->GetTreeToMerge()->GetEntriesFast()){
395 // Do I need to add the lines before the return?
396 // Added protection in case the derived task is not an AOD producer.
397 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
398 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
399 DisconnectMultiHandler();
400 return;
401 }
402 }
1fbe12d4 403
9daedfd1 404 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
405
406 if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
abf59beb 407 if ((handler->NeedsHeaderReplication() || merging) && (fgAODHeader))
c185e0db 408 {
61d5496b 409 // copy the contents by assigment
9daedfd1 410 *fgAODHeader = *(aod->GetHeader());
daa81fe5 411 }
2981307f 412 if ((handler->NeedsTOFHeaderReplication() || merging) && (fgTOFHeader))
413 {
939166e6 414 if (aod->GetTOFHeader()) *fgTOFHeader = *(aod->GetTOFHeader());
2981307f 415 }
939166e6 416 if ((handler->NeedsVZEROReplication() || merging) && (fgAODVZERO) && aod->GetVZEROData())
2981307f 417 {
418 *fgAODVZERO = *(aod->GetVZEROData());
419 }
420
abf59beb 421 if ((handler->NeedsTracksBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODTracks))
c185e0db 422 {
9daedfd1 423 TClonesArray* tracks = aod->GetTracks();
c185e0db 424 new (fgAODTracks) TClonesArray(*tracks);
425 }
417ab5ac 426 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
c185e0db 427 {
9daedfd1 428 TClonesArray* vertices = aod->GetVertices();
c185e0db 429 new (fgAODVertices) TClonesArray(*vertices);
430 }
431 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
432 {
9daedfd1 433 TClonesArray* v0s = aod->GetV0s();
113bc2bd 434 new (fgAODV0s) TClonesArray(*v0s);
c185e0db 435 }
436 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
437 {
9daedfd1 438 *fgAODTracklets = *aod->GetTracklets();
c185e0db 439 }
440 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
441 {
9daedfd1 442 TClonesArray* pmdClusters = aod->GetPmdClusters();
113bc2bd 443 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
c185e0db 444 }
abf59beb 445 if ((handler->NeedsJetsBranchReplication() || (merging &&aodH->GetMergeTracks())) && (fgAODJets))
c185e0db 446 {
9daedfd1 447 TClonesArray* jets = aod->GetJets();
113bc2bd 448 new (fgAODJets) TClonesArray(*jets);
c185e0db 449 }
450 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
451 {
9daedfd1 452 TClonesArray* fmdClusters = aod->GetFmdClusters();
113bc2bd 453 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
c185e0db 454 }
abf59beb 455 if ((handler->NeedsCaloClustersBranchReplication() ||
456 (merging && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())))
457 && (fgAODCaloClusters))
c185e0db 458 {
9daedfd1 459 TClonesArray* caloClusters = aod->GetCaloClusters();
113bc2bd 460 new (fgAODCaloClusters) TClonesArray(*caloClusters);
461 }
462
463 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
464 {
9daedfd1 465 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
93dca4c6 466 if( mcParticles )
467 new (fgAODMCParticles) TClonesArray(*mcParticles);
c185e0db 468 }
866d8d78 469
abf59beb 470 if ((handler->NeedsDimuonsBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODDimuons))
866d8d78 471 {
8f6e7d10 472 fgAODDimuons->Clear();
473 TClonesArray& dimuons = *fgAODDimuons;
474 TClonesArray& tracksnew = *fgAODTracks;
475
397081d5 476 Int_t nMuonTrack[100];
477 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 0;
8f6e7d10 478 Int_t nMuons=0;
479 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
480 AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
481 if(track->IsMuonTrack()) {
482 nMuonTrack[nMuons]= ii;
483 nMuons++;
484 }
485 }
486 Int_t jDimuons=0;
487 if(nMuons >= 2){
488 for(Int_t i = 0; i < nMuons; i++){
489 Int_t index0 = nMuonTrack[i];
490 for(Int_t j = i+1; j < nMuons; j++){
491 Int_t index1 = nMuonTrack[j];
8f6e7d10 492 tracksnew.At(index0)->ResetBit(kIsReferenced);
493 tracksnew.At(index0)->SetUniqueID(0);
494 tracksnew.At(index1)->ResetBit(kIsReferenced);
495 tracksnew.At(index1)->SetUniqueID(0);
496 new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
497 }
498 }
499 }
866d8d78 500 }
fc05a533 501 if ((handler->NeedsHMPIDBranchReplication()) && (fgAODHmpidRings))
502 {
503 TClonesArray* hmpidRings = aod->GetHMPIDrings();
504 new (fgAODHmpidRings) TClonesArray(*hmpidRings);
505 }
506
507
508
5a922844 509 // Additional merging if needed
510 if (merging) {
93dca4c6 511 Int_t nc;
512
113bc2bd 513 // mcParticles
514 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
93dca4c6 515 if( mcparticles ){
516 Int_t npart = mcparticles->GetEntries();
517 nc = fgAODMCParticles->GetEntries();
518
519 for (Int_t i = 0; i < npart; i++) {
113bc2bd 520 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
c8de791b 521 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
93dca4c6 522 }
113bc2bd 523 }
93dca4c6 524
5a922844 525 // tracks
526 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
abf59beb 527 if(tracks && aodH->GetMergeTracks()){
93dca4c6 528 Int_t ntr = tracks->GetEntries();
529 nc = fgAODTracks->GetEntries();
530 for (Int_t i = 0; i < ntr; i++) {
5a922844 531 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
532 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
93dca4c6 533 newtrack->SetLabel(newtrack->GetLabel() + fgAODMCParticles->GetEntries());
534 }
535
536 for (Int_t i = 0; i < nc; i++)
537 {
538 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
539 track->ResetBit(kIsReferenced);
540 track->SetUniqueID(0);
541 }
c8de791b 542 }
543
5a922844 544 // clusters
545 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
abf59beb 546 if( clusters && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())) {
93dca4c6 547 Int_t ncl = clusters->GetEntries();
548 nc = fgAODCaloClusters->GetEntries();
549 for (Int_t i = 0; i < ncl; i++) {
5a922844 550 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
abf59beb 551 if(cluster->IsEMCAL() && !aodH->GetMergeEMCALClusters() ) continue;
552 if(cluster->IsPHOS() && !aodH->GetMergePHOSClusters() ) continue;
c8de791b 553 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
93dca4c6 554 }
555 }
556
557 // EMCAL cells
558 //*fgAODEmcalCells = *(aod->GetEMCALCells()); // This will be valid after 10.Mar.2011.
77e93dc2 559 if(aodH->GetMergeEMCALCells())
560 {
abf59beb 561 AliAODCaloCells* copycells = aod->GetEMCALCells();
562 fgAODEmcalCells->CreateContainer(copycells->GetNumberOfCells());
563 nc = copycells->GetNumberOfCells();
77e93dc2 564
565 while( nc-- ){ fgAODEmcalCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc),
566 copycells->GetTime(nc),copycells->GetMCLabel(nc),copycells->GetEFraction(nc)); }
567
abf59beb 568 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
77e93dc2 569 if( cellsA )
570 {
abf59beb 571 Int_t ncells = cellsA->GetNumberOfCells();
572 nc = fgAODEmcalCells->GetNumberOfCells();
77e93dc2 573
574 for (Int_t i = 0; i < ncells; i++)
575 {
abf59beb 576 Int_t cn = cellsA->GetCellNumber(i);
577 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
77e93dc2 578
579 if (pos >= 0)
580 {
abf59beb 581 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
77e93dc2 582
583 //Check if it is MC, depending on that assing the mc lable, time and e fraction
f6eaa73b 584// Double_t time = 0;
77e93dc2 585 Int_t mclabel =-1;
cb297d50 586 Double_t efrac = 0;
b6d11ecb 587 if(cellsA->GetMCLabel(i) >= 0 && fgAODEmcalCells->GetMCLabel(pos) < 0)
77e93dc2 588 {
589 mclabel = cellsA->GetMCLabel(i) ;
f6eaa73b 590// time = fgAODEmcalCells->GetTime(pos) ; // Time from data
77e93dc2 591 if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;
592 }
b6d11ecb 593 else if(fgAODEmcalCells->GetMCLabel(pos) >= 0 && cellsA->GetMCLabel(i) < 0)
77e93dc2 594 {
b6d11ecb 595 mclabel = fgAODEmcalCells->GetMCLabel(pos) ;
f6eaa73b 596// time = cellsA->GetTime(i) ; // Time from data
b6d11ecb 597 if(amp > 0) efrac = fgAODEmcalCells->GetAmplitude(pos) / amp;
77e93dc2 598 }
599 else
600 { // take all from input
601 mclabel = cellsA->GetMCLabel(i) ;
f6eaa73b 602// time = cellsA->GetTime(i) ;
77e93dc2 603 if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;
604 }
605
606 fgAODEmcalCells->SetCell(pos, cn, amp,cellsA->GetTime(i),mclabel,efrac);
607
608 } else
609 {
abf59beb 610 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODEmcalCells);
611 fgAODEmcalCells->CreateContainer(nc+1);
612 Int_t nn = copycells1->GetNumberOfCells();
77e93dc2 613
614 while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn),
a1ae2d35 615 copycells1->GetTime(nn),copycells1->GetMCLabel(nn),copycells1->GetEFraction(nn)); }
77e93dc2 616
a1ae2d35 617 fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i),cellsA->GetTime(i), cellsA->GetMCLabel(i),1.);
77e93dc2 618
abf59beb 619 delete copycells1;
77e93dc2 620 }
621 }
abf59beb 622 fgAODEmcalCells->Sort();
77e93dc2 623 }
624 } // merge emcal cells
abf59beb 625
113bc2bd 626
93dca4c6 627 // PHOS cells
628 //*fgAODPhosCells = *(aod->GetPHOSCells()); // This will be valid after 10.Mar.2011.
77e93dc2 629 if(aodH->GetMergePHOSCells())
630 {
abf59beb 631 AliAODCaloCells* copycells = aod->GetPHOSCells();
632 fgAODPhosCells->CreateContainer(copycells->GetNumberOfCells());
633 nc = copycells->GetNumberOfCells();
77e93dc2 634
635 while( nc-- ){ fgAODPhosCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc),
636 copycells->GetTime(nc),copycells->GetMCLabel(nc),copycells->GetEFraction(nc)); }
637
abf59beb 638 AliAODCaloCells* cellsP = aodH->GetEventToMerge()->GetPHOSCells();
77e93dc2 639 if( cellsP )
640 {
abf59beb 641 Int_t ncellsP = cellsP->GetNumberOfCells();
642 nc = fgAODPhosCells->GetNumberOfCells();
643
77e93dc2 644 for (Int_t i = 0; i < ncellsP; i++)
645 {
abf59beb 646 Int_t cn = cellsP->GetCellNumber(i);
647 Int_t pos = fgAODPhosCells->GetCellPosition(cn);
77e93dc2 648
649 if (pos >= 0)
650 {
abf59beb 651 Double_t amp = cellsP->GetAmplitude(i) + fgAODPhosCells->GetAmplitude(pos);
77e93dc2 652
653 //Check if it is MC, depending on that assing the mc lable, time and e fraction
f6eaa73b 654// Double_t time = 0;
77e93dc2 655 Int_t mclabel =-1;
cb297d50 656 Double_t efrac = 0;
b6d11ecb 657 if(cellsP->GetMCLabel(i) >= 0 && fgAODPhosCells->GetMCLabel(pos) < 0)
77e93dc2 658 {
659 mclabel = cellsP->GetMCLabel(i) ;
f6eaa73b 660// time = fgAODPhosCells->GetTime(pos) ; // Time from data
77e93dc2 661 if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;
662 }
b6d11ecb 663 else if(fgAODPhosCells->GetMCLabel(pos) >= 0 && cellsP->GetMCLabel(i) < 0)
77e93dc2 664 {
b6d11ecb 665 mclabel = fgAODPhosCells->GetMCLabel(pos) ;
f6eaa73b 666// time = cellsP->GetTime(i) ; // Time from data
b6d11ecb 667 if(amp > 0) efrac = fgAODPhosCells->GetAmplitude(pos) / amp;
77e93dc2 668 }
669 else
670 { // take all from input
671 mclabel = cellsP->GetMCLabel(i) ;
f6eaa73b 672// time = cellsP->GetTime(i) ;
77e93dc2 673 if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;
674 }
675
676 fgAODPhosCells->SetCell(pos, cn, amp,cellsP->GetTime(i),mclabel,efrac);
677
678 } else
679 {
abf59beb 680 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODPhosCells);
681 fgAODPhosCells->CreateContainer(nc+1);
682 Int_t nn = copycells1->GetNumberOfCells();
77e93dc2 683
684 while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn),
a1ae2d35 685 copycells1->GetTime(nn),copycells1->GetMCLabel(nn),copycells1->GetEFraction(nn)); }
77e93dc2 686
a1ae2d35 687 fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i),cellsP->GetTime(i), cellsP->GetMCLabel(i),1.);
77e93dc2 688
abf59beb 689 delete copycells1;
77e93dc2 690 }
691 }
abf59beb 692 fgAODPhosCells->Sort();
77e93dc2 693 }
694 } // Merge PHOS Cells
720f7306 695
77e93dc2 696 if (aodH->GetMergeEMCALTrigger() && aod->GetCaloTrigger("EMCAL"))
720f7306 697 {
77e93dc2 698 Int_t tsEMCAL[48][64], px, py, ts;
699 Float_t foEMCAL[48][64], am;
720f7306 700
701 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
702 {
77e93dc2 703 tsEMCAL[i][j] = 0;
704 foEMCAL[i][j] = 0.;
720f7306 705 }
77e93dc2 706
707 AliAODCaloTrigger& trg0 = *(aod->GetCaloTrigger("EMCAL"));
708 trg0.Reset();
709 while (trg0.Next())
710 {
711 trg0.GetPosition(px, py);
712
713 if (px > -1 && py > -1)
714 {
715 trg0.GetL1TimeSum(ts);
716 if (ts > -1) tsEMCAL[px][py] += ts;
717
718 trg0.GetAmplitude(am);
719 if (am > -1) foEMCAL[px][py] += am;
720 }
721 }
722
723 AliAODCaloTrigger& trg1 = *((aodH->GetEventToMerge())->GetCaloTrigger("EMCAL"));
724
725 trg1.Reset();
726 while (trg1.Next())
727 {
728 trg1.GetPosition(px, py);
729
730 if (px > -1 && py > -1)
731 {
732 trg1.GetL1TimeSum(ts);
733 if (ts > -1) tsEMCAL[px][py] += ts;
734
735 trg1.GetAmplitude(am);
736 if (am > -1) foEMCAL[px][py] += am;
737 }
738 }
739
740 int nEntries = 0;
741 for (Int_t i = 0; i < 48; i++)
742 for (Int_t j = 0; j < 64; j++)
743 if (tsEMCAL[i][j] || foEMCAL[i][j]) nEntries++;
744
745 fgAODEMCALTrigger->Allocate(nEntries);
746 Int_t timesL0[10]; for (int i = 0; i < 10; i++) timesL0[i] = -1;
747
748 for (Int_t i = 0; i < 48; i++)
749 for (Int_t j = 0; j < 64; j++)
750 if (tsEMCAL[i][j] || foEMCAL[i][j])
751 fgAODEMCALTrigger->Add(i, j, foEMCAL[i][j], -1., timesL0, 0, tsEMCAL[i][j], 0);
752 }
720f7306 753
754 if (aodH->GetMergePHOSTrigger())
755 {
756 // To be implemented by PHOS
757 }
113bc2bd 758 } // merging
c185e0db 759
5a922844 760 handler->SetAODIsReplicated();
3f2431c4 761 }
762 }
763
93dca4c6 764
4d0a82af 765// Call the user analysis
98d1fc33 766 if (isSelected) UserExec(option);
90a9a634 767
768// Added protection in case the derived task is not an AOD producer.
60a04972 769 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
770 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
93dca4c6 771
2da1d158 772 DisconnectMultiHandler();
5232d0de 773}
774
4d0a82af 775const char* AliAnalysisTaskSE::CurrentFileName()
776{
777// Returns the current file name
259b7a8a 778 if( fInputHandler )
779 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
780 else if( fMCEvent )
781 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 782 else return "";
4d0a82af 783}
5232d0de 784
3cee83d7 785void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
164e94ff 786{
787 // Add a new branch to the aod tree
b9531017 788 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
164e94ff 789 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
790 if (handler) {
3cee83d7 791 handler->AddBranch(cname, addobj, fname);
164e94ff 792 }
793}
3cee83d7 794
795Bool_t AliAnalysisTaskSE::IsStandardAOD() const
796{
797// Check if the output AOD handler is configured for standard or delta AOD.
798// Users should first check that AODEvent() returns non-null.
b9531017 799 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
3cee83d7 800 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
801 if (!handler) {
802 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
803 return kTRUE;
804 }
805 return handler->IsStandard();
806}
1ec2c8dc 807
808Bool_t AliAnalysisTaskSE::Notify()
809{
9a587f77 810 return (UserNotify());
1ec2c8dc 811}
812
cec9e119 813const AliEventTag *AliAnalysisTaskSE::EventTag() const
814{
815// Returns tag for the current event, if any. The return value should always be checked by the user.
816 if (!fInputHandler) {
817 Error("EventTag", "Input handler not yet available. Call this in UserExec");
818 return NULL;
819 }
820 return fInputHandler->GetEventTag();
821}
1ec2c8dc 822
cec9e119 823void AliAnalysisTaskSE::LoadBranches() const
824{
825// Load all branches declared in fBranchNames data member of the parent class.
826// Should be called in UserExec.
827 if (!fInputHandler) {
828 Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
829 return;
830 }
831 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
832 if (mgr->GetAutoBranchLoading()) return;
833 TString taskbranches;
834 GetBranches(fInputHandler->GetDataType(), taskbranches);
835 if (taskbranches.IsNull()) return;
836 TObjArray *arr = taskbranches.Tokenize(",");
837 TIter next(arr);
838 TObject *obj;
839 while ((obj=next())) mgr->LoadBranch(obj->GetName());
09d5920f 840 delete arr;
cec9e119 841}
2da1d158 842
843
844//_________________________________________________________________________________________________
845void AliAnalysisTaskSE::ConnectMultiHandler()
846{
847 //
848 // Connect MultiHandler
849 //
850 fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
851 fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
852 if (fMultiInputHandler) {
2da1d158 853 fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
205cbea7 854 fMCEventHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
bae44bb7 855 } else {
205cbea7 856 fMCEventHandler = dynamic_cast<AliInputEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
2da1d158 857 }
858 if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
859}
860
861//_________________________________________________________________________________________________
862void AliAnalysisTaskSE::DisconnectMultiHandler()
863{
864 //
865 // Disconnect MultiHandler
866 //
867 if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
868}