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"
31 #include "AliESDfriend.h"
33 #include "AliAODEvent.h"
34 #include "AliAODHeader.h"
35 #include "AliAODTracklets.h"
36 #include "AliAODCaloCells.h"
37 #include "AliAODMCParticle.h"
38 #include "AliVEvent.h"
39 #include "AliAODHandler.h"
40 #include "AliAODInputHandler.h"
41 #include "AliMCEventHandler.h"
42 #include "AliInputEventHandler.h"
43 #include "AliESDInputHandler.h"
44 #include "AliMCEvent.h"
47 #include "AliAODDimuon.h"
50 ClassImp(AliAnalysisTaskSE)
52 ////////////////////////////////////////////////////////////////////////
53 AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
54 TClonesArray* AliAnalysisTaskSE::fgAODTracks = NULL;
55 TClonesArray* AliAnalysisTaskSE::fgAODVertices = NULL;
56 TClonesArray* AliAnalysisTaskSE::fgAODV0s = NULL;
57 TClonesArray* AliAnalysisTaskSE::fgAODPMDClusters = NULL;
58 TClonesArray* AliAnalysisTaskSE::fgAODJets = NULL;
59 TClonesArray* AliAnalysisTaskSE::fgAODFMDClusters = NULL;
60 TClonesArray* AliAnalysisTaskSE::fgAODCaloClusters = NULL;
61 TClonesArray* AliAnalysisTaskSE::fgAODMCParticles = NULL;
62 AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets = NULL;
63 AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells = NULL;
64 AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells = NULL;
65 TClonesArray* AliAnalysisTaskSE::fgAODDimuons = NULL;
67 AliAnalysisTaskSE::AliAnalysisTaskSE():
77 fCurrentRunNumber(-1),
79 fOfflineTriggerMask(0)
81 // Default constructor
84 AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
85 AliAnalysisTask(name, "AnalysisTaskSE"),
94 fCurrentRunNumber(-1),
96 fOfflineTriggerMask(0)
98 // Default constructor
99 DefineInput (0, TChain::Class());
100 DefineOutput(0, TTree::Class());
103 AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
104 AliAnalysisTask(obj),
113 fCurrentRunNumber(-1),
115 fOfflineTriggerMask(0)
120 fInputEvent = obj.fInputEvent;
121 fESDfriend = obj.fESDfriend;
122 fInputHandler = obj.fInputHandler;
123 fOutputAOD = obj.fOutputAOD;
124 fMCEvent = obj.fMCEvent;
126 fCurrentRunNumber = obj.fCurrentRunNumber;
127 fHistosQA = obj.fHistosQA;
132 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
135 AliAnalysisTask::operator=(other);
136 fDebug = other.fDebug;
137 fEntry = other.fEntry;
138 fInputEvent = other.fInputEvent;
139 fESDfriend = other.fESDfriend;
140 fInputHandler = other.fInputHandler;
141 fOutputAOD = other.fOutputAOD;
142 fMCEvent = other.fMCEvent;
143 fTreeA = other.fTreeA;
144 fCurrentRunNumber = other.fCurrentRunNumber;
145 fHistosQA = other.fHistosQA;
146 fOfflineTriggerMask = other.fOfflineTriggerMask;
151 void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
153 // Connect the input data
154 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
158 fInputHandler = (AliInputEventHandler*)
159 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
163 AliMCEventHandler* mcH = 0;
164 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
166 fMCEvent = mcH->MCEvent();
170 if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
171 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
173 fInputEvent = fInputHandler->GetEvent();
174 } else if( fMCEvent ) {
175 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
177 AliError("No Input Event Handler connected") ;
182 void AliAnalysisTaskSE::CreateOutputObjects()
184 // Create the output container
187 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
189 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
190 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
192 Bool_t merging = kFALSE;
193 AliAODInputHandler* aodIH = static_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
195 if (aodIH->GetMergeEvents()) merging = kTRUE;
199 // Check if AOD replication has been required
202 fOutputAOD = handler->GetAOD();
203 fTreeA = handler->GetTree();
204 if (fOutputAOD && !(handler->IsStandard())) {
205 if ((handler->NeedsHeaderReplication()) && !(fgAODHeader))
207 if (fDebug > 1) AliInfo("Replicating header");
208 fgAODHeader = new AliAODHeader;
209 handler->AddBranch("AliAODHeader", &fgAODHeader);
211 if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))
213 if (fDebug > 1) AliInfo("Replicating track branch\n");
214 fgAODTracks = new TClonesArray("AliAODTrack",500);
215 fgAODTracks->SetName("tracks");
216 handler->AddBranch("TClonesArray", &fgAODTracks);
218 if ((handler->NeedsVerticesBranchReplication() || merging) && !(fgAODVertices))
220 if (fDebug > 1) AliInfo("Replicating vertices branch\n");
221 fgAODVertices = new TClonesArray("AliAODVertex",500);
222 fgAODVertices->SetName("vertices");
223 handler->AddBranch("TClonesArray", &fgAODVertices);
225 if ((handler->NeedsV0sBranchReplication()) && !(fgAODV0s))
227 if (fDebug > 1) AliInfo("Replicating V0s branch\n");
228 fgAODV0s = new TClonesArray("AliAODv0",500);
229 fgAODV0s->SetName("v0s");
230 handler->AddBranch("TClonesArray", &fgAODV0s);
232 if ((handler->NeedsTrackletsBranchReplication()) && !(fgAODTracklets))
234 if (fDebug > 1) AliInfo("Replicating Tracklets branch\n");
235 fgAODTracklets = new AliAODTracklets("tracklets","tracklets");
236 handler->AddBranch("AliAODTracklets", &fgAODTracklets);
238 if ((handler->NeedsPMDClustersBranchReplication()) && !(fgAODPMDClusters))
240 if (fDebug > 1) AliInfo("Replicating PMDClusters branch\n");
241 fgAODPMDClusters = new TClonesArray("AliAODPmdCluster",500);
242 fgAODPMDClusters->SetName("pmdClusters");
243 handler->AddBranch("TClonesArray", &fgAODPMDClusters);
245 if ((handler->NeedsJetsBranchReplication() || merging) && !(fgAODJets))
247 if (fDebug > 1) AliInfo("Replicating Jets branch\n");
248 fgAODJets = new TClonesArray("AliAODJet",500);
249 fgAODJets->SetName("jets");
250 handler->AddBranch("TClonesArray", &fgAODJets);
252 if ((handler->NeedsFMDClustersBranchReplication()) && !(fgAODFMDClusters))
254 AliInfo("Replicating FMDClusters branch\n");
255 fgAODFMDClusters = new TClonesArray("AliAODFmdCluster",500);
256 fgAODFMDClusters->SetName("fmdClusters");
257 handler->AddBranch("TClonesArray", &fgAODFMDClusters);
259 if ((handler->NeedsCaloClustersBranchReplication() || merging) && !(fgAODCaloClusters))
261 if (fDebug > 1) AliInfo("Replicating CaloClusters branch\n");
262 fgAODCaloClusters = new TClonesArray("AliAODCaloCluster",500);
263 fgAODCaloClusters->SetName("caloClusters");
264 handler->AddBranch("TClonesArray", &fgAODCaloClusters);
266 fgAODEmcalCells = new AliAODCaloCells();
267 fgAODEmcalCells->SetName("emcalCells");
268 handler->AddBranch("AliAODCaloCells", &fgAODEmcalCells);
270 fgAODPhosCells = new AliAODCaloCells();
271 fgAODPhosCells->SetName("phosCells");
272 handler->AddBranch("AliAODCaloCells", &fgAODPhosCells);
274 if ((handler->NeedsMCParticlesBranchReplication() || merging) && !(fgAODMCParticles))
276 if (fDebug > 1) AliInfo("Replicating MCParticles branch\n");
277 fgAODMCParticles = new TClonesArray("AliAODMCParticle",500);
278 fgAODMCParticles->SetName("mcparticles");
279 handler->AddBranch("TClonesArray", &fgAODMCParticles);
281 if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))
283 if (fDebug > 1) AliInfo("Replicating dimuon branch\n");
284 fgAODDimuons = new TClonesArray("AliAODDimuon",0);
285 fgAODDimuons->SetName("dimuons");
286 handler->AddBranch("TClonesArray", &fgAODDimuons);
289 // cache the pointerd in the AODEvent
290 fOutputAOD->GetStdContent();
293 UserCreateOutputObjects();
296 void AliAnalysisTaskSE::Exec(Option_t* option)
299 // Exec analysis of one event
301 printf("Task is active %5d\n", IsActive());
303 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
305 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
306 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
308 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
310 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
311 UInt_t isSelected = AliVEvent::kAny;
312 if( fInputHandler && fInputHandler->GetEventSelection()) {
313 // Get the actual offline trigger mask for the event and AND it with the
314 // requested mask. If no mask requested select by default the event.
315 if (fOfflineTriggerMask)
316 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
318 // Functionality below moved in the filter tasks (AG)
319 // if (handler) handler->SetFillAOD(isSelected);
321 if( fInputHandler ) {
322 fEntry = fInputHandler->GetReadEntry();
323 fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
327 // Notify the change of run number
328 if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
329 fCurrentRunNumber = InputEvent()->GetRunNumber();
334 fEntry = fMCEvent->Header()->GetEvent();
335 if ( !((Entry()-1)%100) && fDebug > 0)
336 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
341 if (handler && aodH) {
342 fMCEvent = aodH->MCEvent();
343 Bool_t merging = aodH->GetMergeEvents();
345 if (!(handler->IsStandard()) && !(handler->AODIsReplicated())) {
346 if ((handler->NeedsHeaderReplication()) && (fgAODHeader))
348 // copy the contents by assigment
349 *fgAODHeader = *(dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader()));
351 if ((handler->NeedsTracksBranchReplication() || merging) && (fgAODTracks))
353 TClonesArray* tracks = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracks();
354 new (fgAODTracks) TClonesArray(*tracks);
356 if ((handler->NeedsVerticesBranchReplication() || merging) && (fgAODVertices))
358 TClonesArray* vertices = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetVertices();
359 new (fgAODVertices) TClonesArray(*vertices);
361 if ((handler->NeedsV0sBranchReplication()) && (fgAODV0s))
363 TClonesArray* v0s = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetV0s();
364 new (fgAODV0s) TClonesArray(*v0s);
366 if ((handler->NeedsTrackletsBranchReplication()) && (fgAODTracklets))
368 *fgAODTracklets = *(dynamic_cast<AliAODEvent*>(InputEvent()))->GetTracklets();
370 if ((handler->NeedsPMDClustersBranchReplication()) && (fgAODPMDClusters))
372 TClonesArray* pmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetPmdClusters();
373 new (fgAODPMDClusters) TClonesArray(*pmdClusters);
375 if ((handler->NeedsJetsBranchReplication() || merging) && (fgAODJets))
377 TClonesArray* jets = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetJets();
378 new (fgAODJets) TClonesArray(*jets);
380 if ((handler->NeedsFMDClustersBranchReplication()) && (fgAODFMDClusters))
382 TClonesArray* fmdClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetFmdClusters();
383 new (fgAODFMDClusters) TClonesArray(*fmdClusters);
385 if ((handler->NeedsCaloClustersBranchReplication() || merging) && (fgAODCaloClusters))
387 TClonesArray* caloClusters = (dynamic_cast<AliAODEvent*>(InputEvent()))->GetCaloClusters();
388 new (fgAODCaloClusters) TClonesArray(*caloClusters);
391 if ((handler->NeedsMCParticlesBranchReplication() || merging) && (fgAODMCParticles))
393 TClonesArray* mcParticles = (TClonesArray*) ((dynamic_cast<AliAODEvent*>(InputEvent()))->FindListObject("mcparticles"));
394 new (fgAODMCParticles) TClonesArray(*mcParticles);
397 if ((handler->NeedsDimuonsBranchReplication() || merging) && (fgAODDimuons))
399 fgAODDimuons->Clear();
400 TClonesArray& dimuons = *fgAODDimuons;
401 TClonesArray& tracksnew = *fgAODTracks;
403 Int_t nMuonTrack[10];
404 for(Int_t imuon = 0; imuon < 10; imuon++) nMuonTrack[imuon] = 0;
406 for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
407 AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
408 if(track->IsMuonTrack()) {
409 nMuonTrack[nMuons]= ii;
415 for(Int_t i = 0; i < nMuons; i++){
416 Int_t index0 = nMuonTrack[i];
417 for(Int_t j = i+1; j < nMuons; j++){
418 Int_t index1 = nMuonTrack[j];
419 tracksnew.At(index0)->ResetBit(kIsReferenced);
420 tracksnew.At(index0)->SetUniqueID(0);
421 tracksnew.At(index1)->ResetBit(kIsReferenced);
422 tracksnew.At(index1)->SetUniqueID(0);
423 new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
429 // Additional merging if needed
432 TClonesArray* mcparticles = (TClonesArray*) ((aodH->GetEventToMerge())->FindListObject("mcparticles"));
433 Int_t npart = mcparticles->GetEntries();
434 Int_t nc = fgAODMCParticles->GetEntries();
437 for (Int_t i = 0; i < npart; i++) {
438 AliAODMCParticle* particle = (AliAODMCParticle*) mcparticles->At(i);
439 new((*fgAODMCParticles)[nc++]) AliAODMCParticle(*particle);
443 TClonesArray* tracks = aodH->GetEventToMerge()->GetTracks();
444 Int_t ntr = tracks->GetEntries();
445 nc = fgAODTracks->GetEntries();
446 for (Int_t i = 0; i < ntr; i++) {
447 AliAODTrack* track = (AliAODTrack*) tracks->At(i);
448 AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
449 newtrack->SetLabel(newtrack->GetLabel() + nc0);
452 for (Int_t i = 0; i < nc; i++)
454 AliAODTrack* track = (AliAODTrack*) fgAODTracks->At(i);
455 track->ResetBit(kIsReferenced);
456 track->SetUniqueID(0);
461 TClonesArray* clusters = aodH->GetEventToMerge()->GetCaloClusters();
462 Int_t ncl = clusters->GetEntries();
463 nc = fgAODCaloClusters->GetEntries();
464 for (Int_t i = 0; i < ncl; i++) {
465 AliAODCaloCluster* cluster = (AliAODCaloCluster*) clusters->At(i);
466 new((*fgAODCaloClusters)[nc++]) AliAODCaloCluster(*cluster);
469 AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
470 Int_t ncells = cellsA->GetNumberOfCells();
471 nc = fgAODEmcalCells->GetNumberOfCells();
473 for (Int_t i = 0; i < ncells; i++) {
474 Int_t cn = cellsA->GetCellNumber(i);
475 Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
477 Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
478 fgAODEmcalCells->SetCell(pos, cn, amp);
480 Double_t amp = cellsA->GetAmplitude(i);
481 fgAODEmcalCells->SetCell(nc++, cn, amp);
482 fgAODEmcalCells->Sort();
489 handler->SetAODIsReplicated();
493 // Call the user analysis
494 AliMCEventHandler* mcH = 0;
495 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
501 if (isSelected && (mcH->InitOk()))
505 // Added protection in case the derived task is not an AOD producer.
506 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
507 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
510 const char* AliAnalysisTaskSE::CurrentFileName()
512 // Returns the current file name
514 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
516 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
520 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
522 // Add a new branch to the aod tree
523 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
524 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
526 handler->AddBranch(cname, addobj, fname);
530 Bool_t AliAnalysisTaskSE::IsStandardAOD() const
532 // Check if the output AOD handler is configured for standard or delta AOD.
533 // Users should first check that AODEvent() returns non-null.
534 AliAODHandler* handler = dynamic_cast<AliAODHandler*>
535 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
537 Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
540 return handler->IsStandard();
543 Bool_t AliAnalysisTaskSE::Notify()
545 return (UserNotify());