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 "AliAnalysisDataSlot.h"
28 #include "AliESDEvent.h"
30 #include "AliAODEvent.h"
31 #include "AliAODHeader.h"
32 #include "AliAODTracklets.h"
33 #include "AliAODCaloCells.h"
34 #include "AliAODMCParticle.h"
35 #include "AliVEvent.h"
36 #include "AliAODHandler.h"
37 #include "AliAODInputHandler.h"
38 #include "AliMCEventHandler.h"
39 #include "AliInputEventHandler.h"
40 #include "AliMCEvent.h"
45 ClassImp(AliAnalysisTaskSE)
47 ////////////////////////////////////////////////////////////////////////
48 AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
49 TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
50 TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
51 TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
52 TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
53 TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
54 TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
55 TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
56 TClonesArray* AliAnalysisTaskSE::fgAODMCParticles = NULL;
57 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
58 AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells = NULL;
59 AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells = NULL;
62 AliAnalysisTaskSE::AliAnalysisTaskSE():
71 fCurrentRunNumber(-1),
74 // Default constructor
77 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
78 AliAnalysisTask(name, "AnalysisTaskSE"),
86 fCurrentRunNumber(-1),
89 // Default constructor
90 DefineInput (0, TChain::Class());
91 DefineOutput(0, TTree::Class());
94 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
103 fCurrentRunNumber(-1),
109 fInputEvent = obj.fInputEvent;
110 fInputHandler = obj.fInputHandler;
111 fOutputAOD = obj.fOutputAOD;
112 fMCEvent = obj.fMCEvent;
114 fCurrentRunNumber = obj.fCurrentRunNumber;
115 fHistosQA = obj.fHistosQA;
119 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
122 AliAnalysisTask::operator=(other);
123 fDebug = other.fDebug;
124 fEntry = other.fEntry;
125 fInputEvent = other.fInputEvent;
126 fInputHandler = other.fInputHandler;
127 fOutputAOD = other.fOutputAOD;
128 fMCEvent = other.fMCEvent;
129 fTreeA = other.fTreeA;
130 fCurrentRunNumber = other.fCurrentRunNumber;
131 fHistosQA = other.fHistosQA;
136 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
138 // Connect the input data
139 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
143 fInputHandler = (AliInputEventHandler*)
144 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
148 AliMCEventHandler* mcH = 0;
149 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
151 fMCEvent = mcH->MCEvent();
155 fInputEvent = fInputHandler->GetEvent();
156 } else if( fMCEvent ) {
157 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
159 AliError("No Input Event Handler connected") ;
164 void AliAnalysisTaskSE::CreateOutputObjects()
166 // Create the output container
169 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
171 AliAODHandler* handler = (AliAODHandler*)
172 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
174 Bool_t merging = kFALSE;
175 AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
177 if (aodIH->GetMergeEvents()) merging = kTRUE;
180 // Check if AOD replication has been required
183 fOutputAOD = handler->GetAOD();
184 fTreeA = handler->GetTree();
185 if (!(handler->IsStandard())) {
186 if ((handler->NeedsHeaderReplication()) && !(fgAODHeader))
188 if (fDebug > 1) AliInfo("Replicating header");
189 fgAODHeader = new AliAODHeader;
190 handler->AddBranch("AliAODHeader", &fgAODHeader);
192 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
194 if (fDebug > 1) AliInfo("Replicating track branch\n");
195 fgAODTracks = new TClonesArray("AliAODTrack",500);
196 fgAODTracks->SetName("tracks");
197 handler->AddBranch("TClonesArray", &fgAODTracks);
199 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
201 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
202 fgAODVertices = new TClonesArray("AliAODVertex",500);
203 fgAODVertices->SetName("vertices");
204 handler->AddBranch("TClonesArray", &fgAODVertices);
206 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
208 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
209 fgAODV0s = new TClonesArray("AliAODv0",500);
210 fgAODV0s->SetName("v0s");
211 handler->AddBranch("TClonesArray", &fgAODV0s);
213 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
215 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
216 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
217 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
219 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
221 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
222 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
223 fgAODPMDClusters->SetName("pmdClusters");
224 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
226 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
228 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
229 fgAODJets = new TClonesArray("AliAODJet",500);
230 fgAODJets->SetName("jets");
231 handler->AddBranch("TClonesArray", &fgAODJets);
233 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
235 AliInfo("Replicating FMDClusters branch\n");
236 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
237 fgAODFMDClusters->SetName("fmdClusters");
238 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
240 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
242 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
243 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
244 fgAODCaloClusters->SetName("caloClusters");
245 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
247 fgAODEmcalCells = new AliAODCaloCells();
248 fgAODEmcalCells->SetName("emcalCells");
249 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
251 fgAODPhosCells = new AliAODCaloCells();
252 fgAODPhosCells->SetName("phosCells");
253 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
255 if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))
257 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
258 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
259 fgAODMCParticles->SetName("mcparticles");
260 handler->AddBranch("TClonesArray", &fgAODMCParticles);
262 // cache the pointerd in the AODEvent
263 fOutputAOD->GetStdContent();
266 AliWarning("No AOD Event Handler connected.") ;
268 UserCreateOutputObjects();
271 void AliAnalysisTaskSE::Exec(Option_t* option)
274 // Exec analysis of one event
275 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
277 if( fInputHandler ) {
278 fEntry = fInputHandler->GetReadEntry();
280 // Notify the change of run number
281 if (InputEvent()->GetRunNumber() != fCurrentRunNumber) {
282 fCurrentRunNumber = InputEvent()->GetRunNumber();
287 fEntry = fMCEvent->Header()->GetEvent();
288 if ( !((Entry()-1)%100) && fDebug > 0)
289 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
291 AliAODHandler* handler = (AliAODHandler*)
292 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
293 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
295 if (handler && aodH) {
296 fMCEvent = aodH->MCEvent();
297 Bool_t merging = aodH->GetMergeEvents();
299 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
300 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
302 // copy the contents by assigment
303 *fgAODHeader = *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
305 if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
307 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
308 new (fgAODTracks) TClonesArray(*tracks);
310 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
312 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
313 new (fgAODVertices) TClonesArray(*vertices);
315 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
317 TClonesArray* v0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
318 new (fgAODV0s) TClonesArray(*v0s);
320 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
322 *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
324 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
326 TClonesArray* pmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
327 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
329 if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
331 TClonesArray* jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
332 new (fgAODJets) TClonesArray(*jets);
334 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
336 TClonesArray* fmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
337 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
339 if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
341 TClonesArray* caloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
342 new (fgAODCaloClusters) TClonesArray(*caloClusters);
345 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
347 TClonesArray* mcParticles = (TClonesArray*) ((dynamic_cast<AliAODEvent*>(InputEvent()))->FindListObject("mcparticles"));
348 new (fgAODMCParticles) TClonesArray(*mcParticles);
351 // Additional merging if needed
354 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
355 Int_t npart = mcparticles->GetEntries();
356 Int_t nc = fgAODMCParticles->GetEntries();
359 for (Int_t i = 0; i < npart; i++) {
360 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
361 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
365 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
366 Int_t ntr = tracks->GetEntries();
367 nc = fgAODTracks->GetEntries();
368 for (Int_t i = 0; i < ntr; i++) {
369 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
370 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
372 newtrack->SetLabel(newtrack->GetLabel() + nc0);
375 for (Int_t i = 0; i < nc; i++)
377 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
378 track->ResetBit(kIsReferenced);
379 track->SetUniqueID(0);
384 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
385 Int_t ncl = clusters->GetEntries();
386 nc = fgAODCaloClusters->GetEntries();
387 for (Int_t i = 0; i < ncl; i++) {
388 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
389 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
392 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
393 Int_t ncells = cellsA->GetNumberOfCells();
394 nc = fgAODEmcalCells->GetNumberOfCells();
396 for (Int_t i = 0; i < ncells; i++) {
397 Int_t cn = cellsA->GetCellNumber(i);
398 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
400 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
401 fgAODEmcalCells->SetCell(pos, cn, amp);
403 Double_t amp = cellsA->GetAmplitude(i);
404 fgAODEmcalCells->SetCell(nc++, cn, amp);
405 fgAODEmcalCells->Sort();
412 handler->SetAODIsReplicated();
416 // Call the user analysis
418 // Added protection in case the derived task is not an AOD producer.
419 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
420 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
423 const char* AliAnalysisTaskSE::CurrentFileName()
425 // Returns the current file name
427 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
429 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
433 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
435 // Add a new branch to the aod tree
436 AliAODHandler* handler = (AliAODHandler*)
437 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
439 handler->AddBranch(cname, addobj, fname);
443 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
445 // Check if the output AOD handler is configured for standard or delta AOD.
446 // Users should first check that AODEvent() returns non-null.
447 AliAODHandler* handler = (AliAODHandler*)
448 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
450 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
453 return handler->IsStandard();
456 Bool_t AliAnalysisTaskSE::Notify()
458 return (UserNotify());