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 AliAODHandler* handler = (AliAODHandler*)
285 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
286 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
288 // Was event selected ?
289 Bool_t isSelected = kTRUE;
290 if( fInputHandler ) {
291 isSelected = fInputHandler->IsEventSelected();
292 fEntry = fInputHandler->GetReadEntry();
295 if (handler) handler->SetFillAOD(isSelected);
298 // Notify the change of run number
299 if (InputEvent()->GetRunNumber() != fCurrentRunNumber) {
300 fCurrentRunNumber = InputEvent()->GetRunNumber();
305 fEntry = fMCEvent->Header()->GetEvent();
306 if ( !((Entry()-1)%100) && fDebug > 0)
307 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
312 if (handler && aodH) {
313 fMCEvent = aodH->MCEvent();
314 Bool_t merging = aodH->GetMergeEvents();
316 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
317 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
319 // copy the contents by assigment
320 *fgAODHeader = *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
322 if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
324 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
325 new (fgAODTracks) TClonesArray(*tracks);
327 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
329 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
330 new (fgAODVertices) TClonesArray(*vertices);
332 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
334 TClonesArray* v0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
335 new (fgAODV0s) TClonesArray(*v0s);
337 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
339 *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
341 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
343 TClonesArray* pmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
344 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
346 if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
348 TClonesArray* jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
349 new (fgAODJets) TClonesArray(*jets);
351 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
353 TClonesArray* fmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
354 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
356 if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
358 TClonesArray* caloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
359 new (fgAODCaloClusters) TClonesArray(*caloClusters);
362 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
364 TClonesArray* mcParticles = (TClonesArray*) ((dynamic_cast<AliAODEvent*>(InputEvent()))->FindListObject("mcparticles"));
365 new (fgAODMCParticles) TClonesArray(*mcParticles);
368 // Additional merging if needed
371 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
372 Int_t npart = mcparticles->GetEntries();
373 Int_t nc = fgAODMCParticles->GetEntries();
376 for (Int_t i = 0; i < npart; i++) {
377 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
378 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
382 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
383 Int_t ntr = tracks->GetEntries();
384 nc = fgAODTracks->GetEntries();
385 for (Int_t i = 0; i < ntr; i++) {
386 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
387 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
389 newtrack->SetLabel(newtrack->GetLabel() + nc0);
392 for (Int_t i = 0; i < nc; i++)
394 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
395 track->ResetBit(kIsReferenced);
396 track->SetUniqueID(0);
401 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
402 Int_t ncl = clusters->GetEntries();
403 nc = fgAODCaloClusters->GetEntries();
404 for (Int_t i = 0; i < ncl; i++) {
405 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
406 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
409 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
410 Int_t ncells = cellsA->GetNumberOfCells();
411 nc = fgAODEmcalCells->GetNumberOfCells();
413 for (Int_t i = 0; i < ncells; i++) {
414 Int_t cn = cellsA->GetCellNumber(i);
415 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
417 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
418 fgAODEmcalCells->SetCell(pos, cn, amp);
420 Double_t amp = cellsA->GetAmplitude(i);
421 fgAODEmcalCells->SetCell(nc++, cn, amp);
422 fgAODEmcalCells->Sort();
429 handler->SetAODIsReplicated();
433 // Call the user analysis
434 if (!fSelectCollisions || isSelected)
437 // Added protection in case the derived task is not an AOD producer.
438 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
439 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
442 const char* AliAnalysisTaskSE::CurrentFileName()
444 // Returns the current file name
446 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
448 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
452 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
454 // Add a new branch to the aod tree
455 AliAODHandler* handler = (AliAODHandler*)
456 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
458 handler->AddBranch(cname, addobj, fname);
462 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
464 // Check if the output AOD handler is configured for standard or delta AOD.
465 // Users should first check that AODEvent() returns non-null.
466 AliAODHandler* handler = (AliAODHandler*)
467 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
469 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
472 return handler->IsStandard();
475 Bool_t AliAnalysisTaskSE::Notify()
477 return (UserNotify());