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 **************************************************************************/
18 // Generic task to produce nanoAOD
19 // Author: Michele Floris, michele.floris@cern.ch
21 #include "AliAnalysisTaskNanoAODFilter.h"
23 #include "Riostream.h"
31 #include "AliAnalysisTaskSE.h"
32 #include "AliAnalysisManager.h"
34 #include "AliESDtrackCuts.h"
35 #include "AliESDEvent.h"
36 #include "AliESDInputHandler.h"
37 #include "AliAODEvent.h"
38 #include "AliAODTrack.h"
39 #include "AliMCEvent.h"
40 #include "AliESDtrack.h"
41 #include "AliAODHandler.h"
42 #include "AliNanoAODReplicator.h"
43 #include "AliNanoAODTrackMapping.h"
45 ClassImp(AliAnalysisTaskNanoAODFilter)
48 //________________________________________________________________________
49 AliAnalysisTaskNanoAODFilter::AliAnalysisTaskNanoAODFilter() // All data members should be initialised here
59 // Dummy constructor ALWAYS needed for I/O.
62 //________________________________________________________________________
63 AliAnalysisTaskNanoAODFilter::AliAnalysisTaskNanoAODFilter(const char *name, Bool_t saveCutsFlag) // All data members should be initialised here
64 :AliAnalysisTaskSE(name),
71 fSaveCutsFlag(saveCutsFlag)
76 DefineOutput(1, AliAnalysisCuts::Class());
77 DefineOutput(2, AliAnalysisCuts::Class());
83 //________________________________________________________________________
84 AliAnalysisTaskNanoAODFilter::~AliAnalysisTaskNanoAODFilter()
86 // Destructor. Clean-up the output list, but not the histograms that are put inside
87 // (the list is owner and will clean-up these histograms). Protect in PROOF case.
90 //________________________________________________________________________
91 void AliAnalysisTaskNanoAODFilter::UserCreateOutputObjects()
94 // Called once (on the worker node)
97 PostData(1, fEvtCuts);
98 PostData(2, fTrkCuts);
102 void AliAnalysisTaskNanoAODFilter::AddFilteredAOD(const char* aodfilename, const char* title)
104 // The replicator is added to the extension
106 AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
107 if (!aodH) AliFatal("No AOD handler");
108 AliAODExtension* ext = aodH->AddFilteredAOD(aodfilename,title);
111 AliFatal("Cannot get extension");
115 AliNanoAODReplicator * rep = new AliNanoAODReplicator("NanoAODReplicator",
116 "remove non interesting tracks, "
117 "writes special tracks array tracks",
123 cout<<"rep: "<<rep<<endl;
124 rep->SetCustomSetter(fSetter);
125 std::cout << "SETTER: " << fSetter << " " << rep->GetCustomSetter() << std::endl;
127 ext->DropUnspecifiedBranches(); // all branches not part of a FilterBranch call (below) will be dropped
129 ext->FilterBranch("tracks",rep);
130 ext->FilterBranch("vertices",rep);
131 ext->FilterBranch("header",rep);
135 // MC branches will be copied (if present), as they are, but only
136 // for events with at least one muon.
137 // For events w/o muon, mcparticles array will be empty and mcheader will be dummy
138 // (e.g. strlen(GetGeneratorName())==0)
140 ext->FilterBranch("mcparticles",rep);
141 ext->FilterBranch("mcHeader",rep);
145 void AliAnalysisTaskNanoAODFilter::Init()
149 AddFilteredAOD("AliAOD.NanoAOD.root", "NanoAODTracksEvents");
155 //________________________________________________________________________
156 void AliAnalysisTaskNanoAODFilter::UserExec(Option_t *)
159 Long64_t ientry = Entry();
160 if(fDebug)printf("Nano AOD Filter: Analysing event # %5d\n", (Int_t) ientry);
162 AliAODEvent *lAODevent=(AliAODEvent*)InputEvent();
165 AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
167 if(fEvtCuts && !fEvtCuts->IsSelected(lAODevent)) return;// FIXME: should event cuts be called here or in the branch replicator? Do we get duplicated events if we skip here (arrays not reset in the branch replicator?)
170 AliAODExtension *extNanoAOD = handler->GetFilteredAOD("AliAOD.NanoAOD.root");
172 extNanoAOD->SetEvent(lAODevent);
173 extNanoAOD->SelectEvent();
174 extNanoAOD->FinishEvent();
180 PostData(1, fEvtCuts);
181 PostData(2, fTrkCuts);
186 //________________________________________________________________________
187 void AliAnalysisTaskNanoAODFilter::Terminate(Option_t *)
189 // print some debug info
193 void AliAnalysisTaskNanoAODFilter::FinishTaskOutput() {
195 // We save here the user info //
197 AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
198 AliAODExtension *extNanoAOD = handler->GetFilteredAOD("AliAOD.NanoAOD.root");
199 extNanoAOD->GetTree()->GetUserInfo()->Add(AliNanoAODTrackMapping::GetInstance());