1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
20 #include <TInterpreter.h>
25 #include "AliAnalysisTaskSE.h"
26 #include "AliAnalysisManager.h"
27 #include "AliAnalysisCuts.h"
28 #include "AliAnalysisDataSlot.h"
29 #include "AliAnalysisDataContainer.h"
31 #include "AliESDEvent.h"
32 #include "AliESDfriend.h"
34 #include "AliAODEvent.h"
35 #include "AliAODHeader.h"
36 #include "AliAODTracklets.h"
37 #include "AliAODCaloCells.h"
38 #include "AliAODCaloTrigger.h"
39 #include "AliAODMCParticle.h"
40 #include "AliVEvent.h"
41 #include "AliAODHandler.h"
42 #include "AliAODInputHandler.h"
43 #include "AliMCEventHandler.h"
44 #include "AliInputEventHandler.h"
45 #include "AliMultiInputEventHandler.h"
46 #include "AliESDInputHandler.h"
47 #include "AliMCEvent.h"
50 #include "AliAODDimuon.h"
53 ClassImp(AliAnalysisTaskSE)
55 ////////////////////////////////////////////////////////////////////////
56 AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
57 TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
58 TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
59 TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
60 TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
61 TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
62 TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
63 TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
64 TClonesArray* AliAnalysisTaskSE::fgAODMCParticles = NULL;
65 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
66 AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells = NULL;
67 AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells = NULL;
68 AliAODCaloTrigger* AliAnalysisTaskSE::fgAODEMCALTrigger = NULL;
69 AliAODCaloTrigger* AliAnalysisTaskSE::fgAODPHOSTrigger = NULL;
70 TClonesArray* AliAnalysisTaskSE::fgAODDimuons = NULL;
72 AliAnalysisTaskSE::AliAnalysisTaskSE():
82 fCurrentRunNumber(-1),
84 fOfflineTriggerMask(0),
85 fMultiInputHandler(0),
88 // Default constructor
91 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
92 AliAnalysisTask(name, "AnalysisTaskSE"),
101 fCurrentRunNumber(-1),
103 fOfflineTriggerMask(0),
104 fMultiInputHandler(0),
107 // Default constructor
108 DefineInput (0, TChain::Class());
109 DefineOutput(0, TTree::Class());
112 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
113 AliAnalysisTask(obj),
122 fCurrentRunNumber(-1),
124 fOfflineTriggerMask(0),
125 fMultiInputHandler(obj.fMultiInputHandler),
126 fMCEventHandler(obj.fMCEventHandler)
131 fInputEvent = obj.fInputEvent;
132 fESDfriend = obj.fESDfriend;
133 fInputHandler = obj.fInputHandler;
134 fOutputAOD = obj.fOutputAOD;
135 fMCEvent = obj.fMCEvent;
137 fCurrentRunNumber = obj.fCurrentRunNumber;
138 fHistosQA = obj.fHistosQA;
143 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
146 if(&other == this) return *this;
147 AliAnalysisTask::operator=(other);
149 AliAnalysisTask::operator=(other);
150 fDebug = other.fDebug;
151 fEntry = other.fEntry;
152 fInputEvent = other.fInputEvent;
153 fESDfriend = other.fESDfriend;
154 fInputHandler = other.fInputHandler;
155 fOutputAOD = other.fOutputAOD;
156 fMCEvent = other.fMCEvent;
157 fTreeA = other.fTreeA;
158 fCurrentRunNumber = other.fCurrentRunNumber;
159 fHistosQA = other.fHistosQA;
160 fOfflineTriggerMask = other.fOfflineTriggerMask;
161 fMultiInputHandler = other.fMultiInputHandler;
162 fMCEventHandler = other.fMCEventHandler;
166 //______________________________________________________________________________
167 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
169 // Connect the input data
170 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
172 // Connect input handlers (multi input handler is handled)
173 ConnectMultiHandler();
176 if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
177 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
179 fInputEvent = fInputHandler->GetEvent();
180 } else if( fMCEvent ) {
181 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
183 AliError("No Input Event Handler connected") ;
186 // Disconnect multi handler
187 DisconnectMultiHandler();
190 void AliAnalysisTaskSE::CreateOutputObjects()
192 // Create the output container
195 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
197 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
198 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
200 Bool_t merging = kFALSE;
201 AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
203 if (aodIH->GetMergeEvents()) merging = kTRUE;
206 // Check if AOD replication has been required
208 fOutputAOD = handler->GetAOD();
209 fTreeA = handler->GetTree();
210 if (fOutputAOD && !(handler->IsStandard())) {
211 if ((handler->NeedsHeaderReplication() || merging) && !(fgAODHeader))
213 if (fDebug > 1) AliInfo("Replicating header");
214 fgAODHeader = new AliAODHeader;
215 handler->AddBranch("AliAODHeader", &fgAODHeader);
217 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
219 if (fDebug > 1) AliInfo("Replicating track branch\n");
220 fgAODTracks = new TClonesArray("AliAODTrack",500);
221 fgAODTracks->SetName("tracks");
222 handler->AddBranch("TClonesArray", &fgAODTracks);
224 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
226 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
227 fgAODVertices = new TClonesArray("AliAODVertex",500);
228 fgAODVertices->SetName("vertices");
229 handler->AddBranch("TClonesArray", &fgAODVertices);
231 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
233 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
234 fgAODV0s = new TClonesArray("AliAODv0",500);
235 fgAODV0s->SetName("v0s");
236 handler->AddBranch("TClonesArray", &fgAODV0s);
238 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
240 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
241 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
242 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
244 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
246 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
247 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
248 fgAODPMDClusters->SetName("pmdClusters");
249 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
251 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
253 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
254 fgAODJets = new TClonesArray("AliAODJet",500);
255 fgAODJets->SetName("jets");
256 handler->AddBranch("TClonesArray", &fgAODJets);
258 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
260 AliInfo("Replicating FMDClusters branch\n");
261 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
262 fgAODFMDClusters->SetName("fmdClusters");
263 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
265 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
267 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
268 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
269 fgAODCaloClusters->SetName("caloClusters");
270 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
272 fgAODEmcalCells = new AliAODCaloCells("emcalCells","emcalCells",AliVCaloCells::kEMCALCell);
273 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
275 fgAODPhosCells = new AliAODCaloCells("phosCells","phosCells",AliVCaloCells::kPHOSCell);
276 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
278 if ((handler->NeedsCaloTriggerBranchReplication() || merging) && !(fgAODEMCALTrigger))
280 if (fDebug > 1) AliInfo("Replicating EMCAL Calo Trigger branches\n");
281 fgAODEMCALTrigger = new AliAODCaloTrigger("emcalTrigger","emcalTrigger");
282 handler->AddBranch("AliAODCaloTrigger", &fgAODEMCALTrigger);
284 if ((handler->NeedsCaloTriggerBranchReplication() || merging) && !(fgAODPHOSTrigger))
286 if (fDebug > 1) AliInfo("Replicating PHOS Calo Trigger branches\n");
287 fgAODPHOSTrigger = new AliAODCaloTrigger("phosTrigger","phosTrigger");
288 handler->AddBranch("AliAODCaloTrigger", &fgAODPHOSTrigger);
290 if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))
292 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
293 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
294 fgAODMCParticles->SetName("mcparticles");
295 handler->AddBranch("TClonesArray", &fgAODMCParticles);
297 if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))
299 if (fDebug > 1) AliInfo("Replicating dimuon branch\n");
300 fgAODDimuons = new TClonesArray("AliAODDimuon",0);
301 fgAODDimuons->SetName("dimuons");
302 handler->AddBranch("TClonesArray", &fgAODDimuons);
305 // cache the pointerd in the AODEvent
306 fOutputAOD->GetStdContent();
309 ConnectMultiHandler();
310 UserCreateOutputObjects();
311 DisconnectMultiHandler();
314 void AliAnalysisTaskSE::Exec(Option_t* option)
317 // Exec analysis of one event
319 ConnectMultiHandler();
322 printf("Task is active %5d\n", IsActive());
324 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
326 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
327 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
329 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
331 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
332 UInt_t isSelected = AliVEvent::kAny;
333 if( fInputHandler && (fInputHandler->GetEventSelection() || aodH)) {
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();
339 // Functionality below moved in the filter tasks (AG)
340 // if (handler) handler->SetFillAOD(isSelected);
342 if( fInputHandler ) {
343 fEntry = fInputHandler->GetReadEntry();
344 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
348 // Notify the change of run number
349 if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
350 fCurrentRunNumber = InputEvent()->GetRunNumber();
355 fEntry = fMCEvent->Header()->GetEvent();
356 if ( !((Entry()-1)%100) && fDebug > 0)
357 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
362 if (handler && aodH) {
363 fMCEvent = aodH->MCEvent();
364 Bool_t merging = aodH->GetMergeEvents();
366 // Do not analyze merged events if last embedded file has less events than normal event,
367 // skip analysis after last embeded event
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());
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);
377 DisconnectMultiHandler();
381 //else printf("MERGE Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
384 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
386 if (aod && !(handler->IsStandard()) && !(handler->AODIsReplicated())) {
387 if ((handler->NeedsHeaderReplication() || merging) && (fgAODHeader))
389 // copy the contents by assigment
390 *fgAODHeader = *(aod->GetHeader());
392 if ((handler->NeedsTracksBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODTracks))
394 TClonesArray* tracks = aod->GetTracks();
395 new (fgAODTracks) TClonesArray(*tracks);
397 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
399 TClonesArray* vertices = aod->GetVertices();
400 new (fgAODVertices) TClonesArray(*vertices);
402 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
404 TClonesArray* v0s = aod->GetV0s();
405 new (fgAODV0s) TClonesArray(*v0s);
407 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
409 *fgAODTracklets = *aod->GetTracklets();
411 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
413 TClonesArray* pmdClusters = aod->GetPmdClusters();
414 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
416 if ((handler->NeedsJetsBranchReplication() || (merging &&aodH->GetMergeTracks())) && (fgAODJets))
418 TClonesArray* jets = aod->GetJets();
419 new (fgAODJets) TClonesArray(*jets);
421 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
423 TClonesArray* fmdClusters = aod->GetFmdClusters();
424 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
426 if ((handler->NeedsCaloClustersBranchReplication() ||
427 (merging && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())))
428 && (fgAODCaloClusters))
430 TClonesArray* caloClusters = aod->GetCaloClusters();
431 new (fgAODCaloClusters) TClonesArray(*caloClusters);
434 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
436 TClonesArray* mcParticles = (TClonesArray*) (aod->FindListObject("mcparticles"));
438 new (fgAODMCParticles) TClonesArray(*mcParticles);
441 if ((handler->NeedsDimuonsBranchReplication() || (merging && aodH->GetMergeTracks())) && (fgAODDimuons))
443 fgAODDimuons->Clear();
444 TClonesArray& dimuons = *fgAODDimuons;
445 TClonesArray& tracksnew = *fgAODTracks;
447 Int_t nMuonTrack[100];
448 for(Int_t imuon = 0; imuon < 100; imuon++) nMuonTrack[imuon] = 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;
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];
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));
472 // Additional merging if needed
477 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
479 Int_t npart = mcparticles->GetEntries();
480 nc = fgAODMCParticles->GetEntries();
482 for (Int_t i = 0; i < npart; i++) {
483 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
484 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
489 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
490 if(tracks && aodH->GetMergeTracks()){
491 Int_t ntr = tracks->GetEntries();
492 nc = fgAODTracks->GetEntries();
493 for (Int_t i = 0; i < ntr; i++) {
494 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
495 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
496 newtrack->SetLabel(newtrack->GetLabel() + fgAODMCParticles->GetEntries());
499 for (Int_t i = 0; i < nc; i++)
501 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
502 track->ResetBit(kIsReferenced);
503 track->SetUniqueID(0);
508 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
509 if( clusters && (aodH->GetMergeEMCALClusters() || aodH->GetMergePHOSClusters())) {
510 Int_t ncl = clusters->GetEntries();
511 nc = fgAODCaloClusters->GetEntries();
512 for (Int_t i = 0; i < ncl; i++) {
513 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
514 if(cluster->IsEMCAL() && !aodH->GetMergeEMCALClusters() ) continue;
515 if(cluster->IsPHOS() && !aodH->GetMergePHOSClusters() ) continue;
516 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
521 //*fgAODEmcalCells = *(aod->GetEMCALCells()); // This will be valid after 10.Mar.2011.
522 if(aodH->GetMergeEMCALCells())
524 AliAODCaloCells* copycells = aod->GetEMCALCells();
525 fgAODEmcalCells->CreateContainer(copycells->GetNumberOfCells());
526 nc = copycells->GetNumberOfCells();
528 while( nc-- ){ fgAODEmcalCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc),
529 copycells->GetTime(nc),copycells->GetMCLabel(nc),copycells->GetEFraction(nc)); }
531 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
534 Int_t ncells = cellsA->GetNumberOfCells();
535 nc = fgAODEmcalCells->GetNumberOfCells();
537 for (Int_t i = 0; i < ncells; i++)
539 Int_t cn = cellsA->GetCellNumber(i);
540 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
544 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
546 //Check if it is MC, depending on that assing the mc lable, time and e fraction
550 if(cellsA->GetMCLabel(i) >= 0 && fgAODEmcalCells->GetMCLabel(i) < 0)
552 mclabel = cellsA->GetMCLabel(i) ;
553 time = fgAODEmcalCells->GetTime(i) ; // Time from data
554 if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;
556 else if(fgAODEmcalCells->GetMCLabel(i) >= 0 && cellsA->GetMCLabel(i) < 0)
558 mclabel = fgAODEmcalCells->GetMCLabel(i) ;
559 time = cellsA->GetTime(i) ; // Time from data
560 if(amp > 0) efrac = fgAODEmcalCells->GetAmplitude(i) / amp;
563 { // take all from input
564 mclabel = cellsA->GetMCLabel(i) ;
565 time = cellsA->GetTime(i) ;
566 if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;
569 fgAODEmcalCells->SetCell(pos, cn, amp,cellsA->GetTime(i),mclabel,efrac);
573 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODEmcalCells);
574 fgAODEmcalCells->CreateContainer(nc+1);
575 Int_t nn = copycells1->GetNumberOfCells();
577 while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn),
578 copycells1->GetTime(nn),copycells1->GetMCLabel(nn),0.); }
580 fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i),cellsA->GetTime(i), cellsA->GetMCLabel(i),0.);
585 fgAODEmcalCells->Sort();
587 } // merge emcal cells
591 //*fgAODPhosCells = *(aod->GetPHOSCells()); // This will be valid after 10.Mar.2011.
592 if(aodH->GetMergePHOSCells())
594 AliAODCaloCells* copycells = aod->GetPHOSCells();
595 fgAODPhosCells->CreateContainer(copycells->GetNumberOfCells());
596 nc = copycells->GetNumberOfCells();
598 while( nc-- ){ fgAODPhosCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc),
599 copycells->GetTime(nc),copycells->GetMCLabel(nc),copycells->GetEFraction(nc)); }
601 AliAODCaloCells* cellsP = aodH->GetEventToMerge()->GetPHOSCells();
604 Int_t ncellsP = cellsP->GetNumberOfCells();
605 nc = fgAODPhosCells->GetNumberOfCells();
607 for (Int_t i = 0; i < ncellsP; i++)
609 Int_t cn = cellsP->GetCellNumber(i);
610 Int_t pos = fgAODPhosCells->GetCellPosition(cn);
614 Double_t amp = cellsP->GetAmplitude(i) + fgAODPhosCells->GetAmplitude(pos);
616 //Check if it is MC, depending on that assing the mc lable, time and e fraction
620 if(cellsP->GetMCLabel(i) >= 0 && fgAODPhosCells->GetMCLabel(i) < 0)
622 mclabel = cellsP->GetMCLabel(i) ;
623 time = fgAODPhosCells->GetTime(i) ; // Time from data
624 if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;
626 else if(fgAODPhosCells->GetMCLabel(i) >= 0 && cellsP->GetMCLabel(i) < 0)
628 mclabel = fgAODPhosCells->GetMCLabel(i) ;
629 time = cellsP->GetTime(i) ; // Time from data
630 if(amp > 0) efrac = fgAODPhosCells->GetAmplitude(i) / amp;
633 { // take all from input
634 mclabel = cellsP->GetMCLabel(i) ;
635 time = cellsP->GetTime(i) ;
636 if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;
639 fgAODPhosCells->SetCell(pos, cn, amp,cellsP->GetTime(i),mclabel,efrac);
643 AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODPhosCells);
644 fgAODPhosCells->CreateContainer(nc+1);
645 Int_t nn = copycells1->GetNumberOfCells();
647 while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn),
648 copycells1->GetTime(nn),copycells1->GetMCLabel(nn),0.); }
650 fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i),cellsP->GetTime(i), cellsP->GetMCLabel(i),0.);
655 fgAODPhosCells->Sort();
657 } // Merge PHOS Cells
659 if (aodH->GetMergeEMCALTrigger() && aod->GetCaloTrigger("EMCAL"))
661 Int_t tsEMCAL[48][64], px, py, ts;
662 Float_t foEMCAL[48][64], am;
664 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
670 AliAODCaloTrigger& trg0 = *(aod->GetCaloTrigger("EMCAL"));
674 trg0.GetPosition(px, py);
676 if (px > -1 && py > -1)
678 trg0.GetL1TimeSum(ts);
679 if (ts > -1) tsEMCAL[px][py] += ts;
681 trg0.GetAmplitude(am);
682 if (am > -1) foEMCAL[px][py] += am;
686 AliAODCaloTrigger& trg1 = *((aodH->GetEventToMerge())->GetCaloTrigger("EMCAL"));
691 trg1.GetPosition(px, py);
693 if (px > -1 && py > -1)
695 trg1.GetL1TimeSum(ts);
696 if (ts > -1) tsEMCAL[px][py] += ts;
698 trg1.GetAmplitude(am);
699 if (am > -1) foEMCAL[px][py] += am;
704 for (Int_t i = 0; i < 48; i++)
705 for (Int_t j = 0; j < 64; j++)
706 if (tsEMCAL[i][j] || foEMCAL[i][j]) nEntries++;
708 fgAODEMCALTrigger->Allocate(nEntries);
709 Int_t timesL0[10]; for (int i = 0; i < 10; i++) timesL0[i] = -1;
711 for (Int_t i = 0; i < 48; i++)
712 for (Int_t j = 0; j < 64; j++)
713 if (tsEMCAL[i][j] || foEMCAL[i][j])
714 fgAODEMCALTrigger->Add(i, j, foEMCAL[i][j], -1., timesL0, 0, tsEMCAL[i][j], 0);
717 if (aodH->GetMergePHOSTrigger())
719 // To be implemented by PHOS
723 handler->SetAODIsReplicated();
728 // Call the user analysis
729 if (!fMCEventHandler) {
733 if (isSelected && (fMCEventHandler->InitOk()))
737 // Added protection in case the derived task is not an AOD producer.
738 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
739 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
741 DisconnectMultiHandler();
744 const char* AliAnalysisTaskSE::CurrentFileName()
746 // Returns the current file name
748 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
750 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
754 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
756 // Add a new branch to the aod tree
757 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
758 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
760 handler->AddBranch(cname, addobj, fname);
764 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
766 // Check if the output AOD handler is configured for standard or delta AOD.
767 // Users should first check that AODEvent() returns non-null.
768 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
769 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
771 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
774 return handler->IsStandard();
777 Bool_t AliAnalysisTaskSE::Notify()
779 return (UserNotify());
782 const AliEventTag *AliAnalysisTaskSE::EventTag() const
784 // Returns tag for the current event, if any. The return value should always be checked by the user.
785 if (!fInputHandler) {
786 Error("EventTag", "Input handler not yet available. Call this in UserExec");
789 return fInputHandler->GetEventTag();
792 void AliAnalysisTaskSE::LoadBranches() const
794 // Load all branches declared in fBranchNames data member of the parent class.
795 // Should be called in UserExec.
796 if (!fInputHandler) {
797 Error("LoadBranches", "Input handler not available yet. Call this in UserExec");
800 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
801 if (mgr->GetAutoBranchLoading()) return;
802 TString taskbranches;
803 GetBranches(fInputHandler->GetDataType(), taskbranches);
804 if (taskbranches.IsNull()) return;
805 TObjArray *arr = taskbranches.Tokenize(",");
808 while ((obj=next())) mgr->LoadBranch(obj->GetName());
812 //_________________________________________________________________________________________________
813 void AliAnalysisTaskSE::ConnectMultiHandler()
816 // Connect MultiHandler
818 fInputHandler = (AliInputEventHandler *)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
819 fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
820 if (fMultiInputHandler) {
821 fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
822 fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
824 fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
826 if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
829 //_________________________________________________________________________________________________
830 void AliAnalysisTaskSE::DisconnectMultiHandler()
833 // Disconnect MultiHandler
835 if (fMultiInputHandler) fInputHandler = fMultiInputHandler;