ATLAS Offline Software
Loading...
Searching...
No Matches
test_isolaitonTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Mindlessly copied from CPAnalysisExamples
6#ifndef CPANALYSISEXAMPLES_ERRORCHECK_H
7#define CPANALYSISEXAMPLES_ERRORCHECK_H
8
9#define CHECK( ARG ) \
10 do { \
11 const bool result = ARG; \
12 if( ! result ) { \
13 ::Error( APP_NAME, "Failed to execute: \"%s\"", \
14 #ARG ); \
15 return 1; \
16 } \
17 } while( false )
18
19#endif // CPANALYSISEXAMPLES_ERRORCHECK_H
20
21#include <iostream>
22#include <memory>
23#include <cstdlib>
24
25// ROOT include(s):
26#include <TFile.h>
27#include <TTree.h>
28#include <TError.h>
29#include <TString.h>
30#include <TH1F.h>
31
32// Infrastructure include(s):
33#ifdef ROOTCORE
34#include "xAODRootAccess/Init.h"
37#endif // ROOTCORE
38
39// EDM include(s):
45#include "xAODMuon/Muon.h"
46
52
56
57using namespace std;
58
59const float GeV = 1000.;
60const float iGeV = 0.001;
61const float PI = 3.1416;
62
63int main(int argc, char** argv ){
64
65 gErrorIgnoreLevel=0;
66 const char* APP_NAME = "ISOTEST";
67 CHECK( xAOD::Init());
68
69 TString fileName = "root://eosatlas.cern.ch//eos/atlas/atlastier0/tzero/prod/valid1/PowhegPythia8_AU2CT10_Zmumu/147807/valid1.147807.PowhegPythia8_AU2CT10_Zmumu.recon.AOD.e2658_s1967_s1964_r5787_v114/valid1.147807.PowhegPythia8_AU2CT10_Zmumu.recon.AOD.e2658_s1967_s1964_r5787_v114._000187.1";
70// TString fileName = "root://eosatlas.cern.ch//eos/atlas/atlastier0/tzero/prod/valid1/PowhegPythia_P2011C_ttbar/117050/valid1.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e2658_s1967_s1964_r5787_v111/valid1.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e2658_s1967_s1964_r5787_v111._000001.4";
71// TString fileName = "root://eosatlas.cern.ch//eos/atlas/atlastier0/tzero/prod/valid1/PowhegPythia8_AU2CT10_Zee/147806/valid1.147806.PowhegPythia8_AU2CT10_Zee.recon.AOD.e2658_s1967_s1964_r5787_v114/valid1.147806.PowhegPythia8_AU2CT10_Zee.recon.AOD.e2658_s1967_s1964_r5787_v114._000001.1";
72// TString fileName = "root://eosatlas.cern.ch//eos/atlas/atlastier0/tzero/prod/valid1/PowhegPythia8_AU2CT10_ggH125_gamgam/160009/valid1.160009.PowhegPythia8_AU2CT10_ggH125_gamgam.recon.AOD.e2658_s1967_s1964_r5787_v114/valid1.160009.PowhegPythia8_AU2CT10_ggH125_gamgam.recon.AOD.e2658_s1967_s1964_r5787_v114._000001.1";
73 if(argc>1) {
74 fileName = argv[1];
75 }
76
77 const TString tag = "t2_";
78 Info( APP_NAME, "Opening file: %s", fileName.Data() );
79 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
80
81 CP::IsolationHelper *m_helperTool = new CP::IsolationHelper("helperTool");
82
83 xAOD::CaloIsolationTool m_caloIsoTool("CaloIsolationTool");
84// m_caloIsoTool.msg().setLevel( MSG::DEBUG );
85// m_caloIsoTool.msg().setLevel( MSG::INFO );
86 InDet::InDetTrackSelectionTool selTool( "TrackSelection" );
87 selTool.setProperty("maxZ0SinTheta", 3.);
88 selTool.setProperty("minPt", 1000.);
89 selTool.setProperty("CutLevel", "Loose");
90
91
92 xAOD::TrackIsolationTool m_trkIsoTool("TrackIsolationTool");
93// m_trkIsoTool.msg().setLevel( MSG::INFO );
94// m_trkIsoTool.msg().setLevel( MSG::DEBUG );
95 m_trkIsoTool.setProperty( "TrackSelectionTool", ToolHandle< InDet::IInDetTrackSelectionTool >(selTool.name()) );
96
97 if(!m_caloIsoTool.initialize().isSuccess()){
98 Info( APP_NAME, "m_caloIsoTool.initialize() failed");
99 }
100
101 if(!selTool.initialize().isSuccess()){
102 Info( APP_NAME, "selTool.initialize() failed");
103 }
104
105 if(!m_trkIsoTool.initialize().isSuccess()){
106 Info( APP_NAME, "m_trkIsoTool.initialize() failed");
107 }
108
109 vector<xAOD::Iso::IsolationType> isoTypes;
110 isoTypes.push_back(xAOD::Iso::ptcone40);
111 isoTypes.push_back(xAOD::Iso::ptcone30);
112 isoTypes.push_back(xAOD::Iso::ptcone20);
113 xAOD::TrackCorrection corrlist;
114 corrlist.trackbitset.set(static_cast<unsigned int>(xAOD::Iso::coreTrackPtr));
115
116 vector<xAOD::Iso::IsolationType> isoTypesCalo;
117 isoTypesCalo.push_back(xAOD::Iso::topoetcone40);
118 isoTypesCalo.push_back(xAOD::Iso::topoetcone30);
119 isoTypesCalo.push_back(xAOD::Iso::topoetcone20);
120 xAOD::CaloCorrection corrlist2;
121 corrlist2.calobitset.set(static_cast<unsigned int>(xAOD::Iso::coreCone));
122 corrlist2.calobitset.set(static_cast<unsigned int>(xAOD::Iso::pileupCorrection));
123
124 vector<xAOD::Iso::IsolationType> isoTypesPFlow;
125 isoTypesPFlow.push_back(xAOD::Iso::neflowisol40);
126 isoTypesPFlow.push_back(xAOD::Iso::neflowisol30);
127 isoTypesPFlow.push_back(xAOD::Iso::neflowisol20);
128 xAOD::CaloCorrection corrlist3;
129 corrlist3.calobitset.set(static_cast<unsigned int>(xAOD::Iso::coreCone));
130 corrlist3.calobitset.set(static_cast<unsigned int>(xAOD::Iso::pileupCorrection));
131
132 // Create a TEvent object:
134 CHECK(event.readFrom(ifile.get()));
135
136
137// Long64_t maxEVT = 10;
138 Long64_t maxEVT = -1;
139 Long64_t entries = event.getEntries();
140 if((entries < maxEVT) || (maxEVT <= 0)) {
141 maxEVT = entries;
142 }
143 Info( APP_NAME, "%lld events found, %lld events will be processed.", entries, maxEVT);
144 const int INTERVAL = maxEVT > 20000? 10000: maxEVT/10;
145 for( Long64_t entry = 0; entry < maxEVT; ++entry ) {
146 event.getEntry( entry );
147 const xAOD::EventInfo* ei = 0;
148 CHECK( event.retrieve( ei, "EventInfo" ) );
149
150 // Print some event information for fun:
151 if(entry%INTERVAL==0){
152 Info( APP_NAME, "%lld events processed, on event %llu of run %u", entry, ei->eventNumber(), ei->runNumber() );
153 }
154
155
156 // get muon container of interest
157 const xAOD::MuonContainer* muons = 0;
158 CHECK( event.retrieve( muons, "Muons" ) );
159
160 // get electron container of interest
161 const xAOD::ElectronContainer* electrons = 0;
162 CHECK( event.retrieve( electrons, "Electrons" ) );
163
164 // get photon container of interest
165 const xAOD::PhotonContainer* photons = 0;
166 CHECK( event.retrieve( photons, "Photons" ) );
167
168 for(auto muon: *muons){
169 Info(APP_NAME, "---------NEW MUON -------");
171 if(m_trkIsoTool.trackIsolation(result, *muon, isoTypes, corrlist)){
172 for(unsigned int i=0; i<isoTypes.size(); i++){
173 float iso = result.ptcones[i];
174 float isoV = result.ptvarcones_10GeVDivPt[i];
175 float value0 = -999;
176 if(!m_helperTool->isolation(value0, *muon, isoTypes[i])) Info(APP_NAME, "Muon default track iso not got.");
177 Info(APP_NAME, "Muon track isolation %d is %f and %f (=%f?)", i, iso, isoV, value0);
178 }
179 }
180 xAOD::CaloIsolation result2;
181 if(m_caloIsoTool.caloTopoClusterIsolation(result2, *muon, isoTypesCalo, corrlist2)){
182 for(unsigned int i=0; i<isoTypesCalo.size(); i++){
183 float value0 = -999;
184 if(!m_helperTool->isolation(value0, *muon, isoTypesCalo[i], corrlist2.calobitset)) Info(APP_NAME, "Muon coreCone Calo iso not got.");
185 Info(APP_NAME, "Muon topo isolation %d is %f (=%f?)", i, result2.etcones[i], value0);
186 }
187 }
188 xAOD::CaloIsolation result3;
189 if(m_caloIsoTool.neutralEflowIsolation(result3, *muon, isoTypesPFlow, corrlist3)){
190 for(unsigned int i=0; i<isoTypesPFlow.size(); i++){
191 float value0 = -999;
192 if(!m_helperTool->isolation(value0, *muon, isoTypesPFlow[i])) Info(APP_NAME, "Muon default pflow iso not got.");
193 Info(APP_NAME, "Muon neflow isolation %d is %f (=%f?)", i, result3.etcones[i], value0);
194 }
195 }
196 }
197
198 for(auto electron: *electrons){
199 Info(APP_NAME, "---------NEW ELECTRON -------");
201 if(m_trkIsoTool.trackIsolation(result, *electron, isoTypes, corrlist)){
202 for(unsigned int i=0; i<isoTypes.size(); i++){
203 float iso = result.ptcones[i];
204 float isoV = result.ptvarcones_10GeVDivPt[i];
205 float value0 = -999;
206 if(!m_helperTool->isolation(value0, *electron, isoTypes[i])) Info(APP_NAME, "Electron default track iso not got.");
207 Info(APP_NAME, "Electron track isolation %d is %f and %f (=%f?)", i, iso, isoV, value0);
208 }
209 }
210 xAOD::CaloIsolation result2;
211 if(m_caloIsoTool.caloTopoClusterIsolation(result2, *electron, isoTypesCalo, corrlist2)){
212 for(unsigned int i=0; i<isoTypesCalo.size(); i++){
213 float value0 = -999;
214 if(!m_helperTool->isolation(value0, *electron, isoTypesCalo[i], corrlist2.calobitset)) Info(APP_NAME, "Electron coreCone Calo iso not got.");
215 Info(APP_NAME, "Electron topo isolation %d is %f (=%f?)", i, result2.etcones[i], value0);
216 }
217 }
218 xAOD::CaloIsolation result3;
219 }
220
221 for(auto photon: *photons){
222 Info(APP_NAME, "---------NEW photon -------");
224 if(m_trkIsoTool.trackIsolation(result, *photon, isoTypes, corrlist)){
225 for(unsigned int i=0; i<isoTypes.size(); i++){
226 float iso = result.ptcones[i];
227 float isoV = result.ptvarcones_10GeVDivPt[i];
228 float value0 = -999;
229 if(!m_helperTool->isolation(value0, *photon, isoTypes[i])) Info(APP_NAME, "photon default track iso not got.");
230 Info(APP_NAME, "Photon track isolation %d is %f and %f (=%f?)", i, iso, isoV, value0);
231 }
232 }
233 xAOD::CaloIsolation result2;
234 if(m_caloIsoTool.caloTopoClusterIsolation(result2, *photon, isoTypesCalo, corrlist2)){
235 for(unsigned int i=0; i<isoTypesCalo.size(); i++){
236 float value0 = -999;
237 if(!m_helperTool->isolation(value0, *photon, isoTypesCalo[i], corrlist2.calobitset)) Info(APP_NAME, "photon coreCone Calo iso not got.");
238 Info(APP_NAME, "Photon topo isolation %d is %f (=%f?)", i, result2.etcones[i], value0);
239 }
240 }
241 xAOD::CaloIsolation result3;
242
243 }
244 }
245
246 Info(APP_NAME, "Finished successfully!");
247
248// xAOD::IOStats::instance().stats().printSmartSlimmingBranchList();
249
250 delete m_helperTool;
251
252 return 0;
253
254}
#define APP_NAME
bool isolation(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type) const
Implementation of the track selector tool.
virtual StatusCode initialize() override
Function initialising the tool.
virtual bool caloTopoClusterIsolation(CaloIsolation &result, const IParticle &tp, const std::vector< Iso::IsolationType > &cones, const CaloCorrection &corrections, const CaloClusterContainer *container=0) const override
ICaloTopoClusterIsolationTool interface:
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual bool neutralEflowIsolation(CaloIsolation &result, const IParticle &tp, const std::vector< Iso::IsolationType > &cones, const CaloCorrection &corrections) const override
INeutralEFlowIsolationTool interface:
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
virtual StatusCode initialize() override
initialize
virtual bool trackIsolation(TrackIsolation &result, const IParticle &tp, const std::vector< Iso::IsolationType > &cones, TrackCorrection corrections, const Vertex *vertex=0, const std::set< const TrackParticle * > *exclusionSet=0, const TrackParticleContainer *indetTrackParticles=0) const override
ITrackIsolationTool interface:
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
STL namespace.
@ neflowisol20
Neutral eflow isolation.
@ topoetcone20
Topo-cluster ET-sum.
@ ptcone20
Track isolation.
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Iso::IsolationCaloCorrectionBitset calobitset
std::vector< float > etcones
Iso::IsolationTrackCorrectionBitset trackbitset
const float iGeV
#define CHECK(ARG)
const float PI