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"
30 #include "AliESDEvent.h"
32 #include "AliAODEvent.h"
33 #include "AliAODHeader.h"
34 #include "AliAODTracklets.h"
35 #include "AliAODCaloCells.h"
36 #include "AliAODMCParticle.h"
37 #include "AliVEvent.h"
38 #include "AliAODHandler.h"
39 #include "AliAODInputHandler.h"
40 #include "AliMCEventHandler.h"
41 #include "AliInputEventHandler.h"
42 #include "AliMCEvent.h"
47 ClassImp(AliAnalysisTaskSE)
49 ////////////////////////////////////////////////////////////////////////
50 AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
51 TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
52 TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
53 TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
54 TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
55 TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
56 TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
57 TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
58 TClonesArray* AliAnalysisTaskSE::fgAODMCParticles = NULL;
59 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
60 AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells = NULL;
61 AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells = NULL;
63 AliAnalysisTaskSE::AliAnalysisTaskSE():
72 fCurrentRunNumber(-1),
76 // Default constructor
79 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
80 AliAnalysisTask(name, "AnalysisTaskSE"),
88 fCurrentRunNumber(-1),
92 // Default constructor
93 DefineInput (0, TChain::Class());
94 DefineOutput(0, TTree::Class());
97 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
106 fCurrentRunNumber(-1),
113 fInputEvent = obj.fInputEvent;
114 fInputHandler = obj.fInputHandler;
115 fOutputAOD = obj.fOutputAOD;
116 fMCEvent = obj.fMCEvent;
118 fCurrentRunNumber = obj.fCurrentRunNumber;
119 fHistosQA = obj.fHistosQA;
124 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
127 AliAnalysisTask::operator=(other);
128 fDebug = other.fDebug;
129 fEntry = other.fEntry;
130 fInputEvent = other.fInputEvent;
131 fInputHandler = other.fInputHandler;
132 fOutputAOD = other.fOutputAOD;
133 fMCEvent = other.fMCEvent;
134 fTreeA = other.fTreeA;
135 fCurrentRunNumber = other.fCurrentRunNumber;
136 fHistosQA = other.fHistosQA;
137 fSelectCollisions = other.fSelectCollisions;
142 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
144 // Connect the input data
145 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
149 fInputHandler = (AliInputEventHandler*)
150 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
154 AliMCEventHandler* mcH = 0;
155 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
157 fMCEvent = mcH->MCEvent();
161 fInputEvent = fInputHandler->GetEvent();
162 } else if( fMCEvent ) {
163 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
165 AliError("No Input Event Handler connected") ;
170 void AliAnalysisTaskSE::CreateOutputObjects()
172 // Create the output container
175 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
177 AliAODHandler* handler = (AliAODHandler*)
178 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
180 Bool_t merging = kFALSE;
181 AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
183 if (aodIH->GetMergeEvents()) merging = kTRUE;
187 // Check if AOD replication has been required
190 fOutputAOD = handler->GetAOD();
191 fTreeA = handler->GetTree();
192 if (fOutputAOD && !(handler->IsStandard())) {
193 if ((handler->NeedsHeaderReplication()) && !(fgAODHeader))
195 if (fDebug > 1) AliInfo("Replicating header");
196 fgAODHeader = new AliAODHeader;
197 handler->AddBranch("AliAODHeader", &fgAODHeader);
199 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
201 if (fDebug > 1) AliInfo("Replicating track branch\n");
202 fgAODTracks = new TClonesArray("AliAODTrack",500);
203 fgAODTracks->SetName("tracks");
204 handler->AddBranch("TClonesArray", &fgAODTracks);
206 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
208 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
209 fgAODVertices = new TClonesArray("AliAODVertex",500);
210 fgAODVertices->SetName("vertices");
211 handler->AddBranch("TClonesArray", &fgAODVertices);
213 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
215 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
216 fgAODV0s = new TClonesArray("AliAODv0",500);
217 fgAODV0s->SetName("v0s");
218 handler->AddBranch("TClonesArray", &fgAODV0s);
220 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
222 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
223 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
224 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
226 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
228 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
229 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
230 fgAODPMDClusters->SetName("pmdClusters");
231 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
233 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
235 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
236 fgAODJets = new TClonesArray("AliAODJet",500);
237 fgAODJets->SetName("jets");
238 handler->AddBranch("TClonesArray", &fgAODJets);
240 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
242 AliInfo("Replicating FMDClusters branch\n");
243 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
244 fgAODFMDClusters->SetName("fmdClusters");
245 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
247 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
249 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
250 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
251 fgAODCaloClusters->SetName("caloClusters");
252 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
254 fgAODEmcalCells = new AliAODCaloCells();
255 fgAODEmcalCells->SetName("emcalCells");
256 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
258 fgAODPhosCells = new AliAODCaloCells();
259 fgAODPhosCells->SetName("phosCells");
260 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
262 if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))
264 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
265 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
266 fgAODMCParticles->SetName("mcparticles");
267 handler->AddBranch("TClonesArray", &fgAODMCParticles);
269 // cache the pointerd in the AODEvent
270 fOutputAOD->GetStdContent();
273 AliWarning("No AOD Event Handler connected.") ;
275 UserCreateOutputObjects();
278 void AliAnalysisTaskSE::Exec(Option_t* option)
281 // Exec analysis of one event
282 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
284 Bool_t isSelected = kTRUE;
285 if( fInputHandler ) {
286 isSelected = fInputHandler->IsEventSelected();
287 fEntry = fInputHandler->GetReadEntry();
290 // Notify the change of run number
291 if (InputEvent()->GetRunNumber() != fCurrentRunNumber) {
292 fCurrentRunNumber = InputEvent()->GetRunNumber();
297 fEntry = fMCEvent->Header()->GetEvent();
298 if ( !((Entry()-1)%100) && fDebug > 0)
299 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
301 AliAODHandler* handler = (AliAODHandler*)
302 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
303 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
305 if (handler && aodH) {
306 fMCEvent = aodH->MCEvent();
307 Bool_t merging = aodH->GetMergeEvents();
309 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
310 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
312 // copy the contents by assigment
313 *fgAODHeader = *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
315 if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
317 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
318 new (fgAODTracks) TClonesArray(*tracks);
320 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
322 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
323 new (fgAODVertices) TClonesArray(*vertices);
325 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
327 TClonesArray* v0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
328 new (fgAODV0s) TClonesArray(*v0s);
330 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
332 *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
334 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
336 TClonesArray* pmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
337 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
339 if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
341 TClonesArray* jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
342 new (fgAODJets) TClonesArray(*jets);
344 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
346 TClonesArray* fmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
347 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
349 if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
351 TClonesArray* caloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
352 new (fgAODCaloClusters) TClonesArray(*caloClusters);
355 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
357 TClonesArray* mcParticles = (TClonesArray*) ((dynamic_cast<AliAODEvent*>(InputEvent()))->FindListObject("mcparticles"));
358 new (fgAODMCParticles) TClonesArray(*mcParticles);
361 // Additional merging if needed
364 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
365 Int_t npart = mcparticles->GetEntries();
366 Int_t nc = fgAODMCParticles->GetEntries();
369 for (Int_t i = 0; i < npart; i++) {
370 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
371 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
375 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
376 Int_t ntr = tracks->GetEntries();
377 nc = fgAODTracks->GetEntries();
378 for (Int_t i = 0; i < ntr; i++) {
379 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
380 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
382 newtrack->SetLabel(newtrack->GetLabel() + nc0);
385 for (Int_t i = 0; i < nc; i++)
387 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
388 track->ResetBit(kIsReferenced);
389 track->SetUniqueID(0);
394 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
395 Int_t ncl = clusters->GetEntries();
396 nc = fgAODCaloClusters->GetEntries();
397 for (Int_t i = 0; i < ncl; i++) {
398 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
399 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
402 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
403 Int_t ncells = cellsA->GetNumberOfCells();
404 nc = fgAODEmcalCells->GetNumberOfCells();
406 for (Int_t i = 0; i < ncells; i++) {
407 Int_t cn = cellsA->GetCellNumber(i);
408 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
410 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
411 fgAODEmcalCells->SetCell(pos, cn, amp);
413 Double_t amp = cellsA->GetAmplitude(i);
414 fgAODEmcalCells->SetCell(nc++, cn, amp);
415 fgAODEmcalCells->Sort();
422 handler->SetAODIsReplicated();
426 // Call the user analysis
427 if (!fSelectCollisions || isSelected)
430 // Added protection in case the derived task is not an AOD producer.
431 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
432 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
435 const char* AliAnalysisTaskSE::CurrentFileName()
437 // Returns the current file name
439 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
441 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
445 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
447 // Add a new branch to the aod tree
448 AliAODHandler* handler = (AliAODHandler*)
449 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
451 handler->AddBranch(cname, addobj, fname);
455 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
457 // Check if the output AOD handler is configured for standard or delta AOD.
458 // Users should first check that AODEvent() returns non-null.
459 AliAODHandler* handler = (AliAODHandler*)
460 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
462 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
465 return handler->IsStandard();
468 Bool_t AliAnalysisTaskSE::Notify()
470 return (UserNotify());