ATLAS Offline Software
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"
35 #include "xAODRootAccess/TEvent.h"
37 #endif // ROOTCORE
38 
39 // EDM include(s):
41 #include "xAODJet/JetContainer.h"
44 #include "xAODMuon/MuonContainer.h"
45 #include "xAODMuon/Muon.h"
46 
52 
54 #include "xAODCore/tools/IOStats.h"
56 
57 using namespace std;
58 
59 const float GeV = 1000.;
60 const float iGeV = 0.001;
61 const float PI = 3.1416;
62 
63 int main(int argc, char** argv ){
64 
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
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 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
CHECK
#define CHECK(ARG)
Definition: test_isolaitonTool.cxx:9
xAOD::Iso::topoetcone20
@ topoetcone20
Topo-cluster ET-sum.
Definition: IsolationType.h:48
iGeV
const float iGeV
Definition: test_isolaitonTool.cxx:60
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::Iso::neflowisol20
@ neflowisol20
Neutral eflow isolation.
Definition: IsolationType.h:64
xAOD::TrackCorrection
Definition: IsolationCommon.h:18
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
CaloIsolationTool.h
xAOD::CaloIsolationTool::caloTopoClusterIsolation
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:
Definition: CaloIsolationTool.cxx:201
Muon.h
xAOD::Iso::coreTrackPtr
@ coreTrackPtr
tracks pointer
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:66
CP::IsolationHelper::isolation
bool isolation(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type) const
Definition: IsolationHelper.cxx:37
xAOD::TrackCorrection::trackbitset
Iso::IsolationTrackCorrectionBitset trackbitset
Definition: IsolationCommon.h:19
xAOD::Iso::ptcone30
@ ptcone30
Definition: IsolationType.h:41
xAOD::Iso::neflowisol30
@ neflowisol30
Definition: IsolationType.h:65
xAOD::Iso::ptcone20
@ ptcone20
Track isolation.
Definition: IsolationType.h:40
InDet::InDetTrackSelectionTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: InDetTrackSelectionTool.cxx:103
xAOD::Iso::topoetcone30
@ topoetcone30
Definition: IsolationType.h:49
PI
const float PI
Definition: test_isolaitonTool.cxx:61
IsolationHelper.h
IOStats.h
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
xAOD::TrackIsolationTool
Definition: TrackIsolationTool.h:39
ReturnCheck.h
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
xAOD::Iso::neflowisol40
@ neflowisol40
Definition: IsolationType.h:66
xAOD::TrackIsolationTool::trackIsolation
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:
Definition: TrackIsolationTool.cxx:104
xAOD::CaloIsolation
Definition: IsolationCommon.h:22
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ReadStats.h
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ElectronContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
main
int main(int argc, char **argv)
Definition: test_isolaitonTool.cxx:63
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
InDetTrackSelectionTool.h
CP::IsolationHelper
Definition: IsolationHelper.h:21
xAOD::CaloIsolationTool
Definition: CaloIsolationTool.h:53
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
xAOD::TrackIsolationTool::initialize
virtual StatusCode initialize() override
initialize
Definition: TrackIsolationTool.cxx:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TrackIsolation
Definition: IsolationCommon.h:33
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::CaloIsolation::etcones
std::vector< float > etcones
Definition: IsolationCommon.h:30
xAOD::Iso::coreCone
@ coreCone
core energy (in dR<0.1).
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:29
gErrorIgnoreLevel
int gErrorIgnoreLevel
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
MuonContainer.h
xAOD::Iso::ptcone40
@ ptcone40
Definition: IsolationType.h:42
xAOD::CaloIsolationTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: CaloIsolationTool.cxx:67
xAOD::CaloIsolationTool::neutralEflowIsolation
virtual bool neutralEflowIsolation(CaloIsolation &result, const IParticle &tp, const std::vector< Iso::IsolationType > &cones, const CaloCorrection &corrections) const override
INeutralEFlowIsolationTool interface:
Definition: CaloIsolationTool.cxx:239
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
JetContainer.h
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
xAOD::CaloCorrection
Definition: IsolationCommon.h:14
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
InDet::InDetTrackSelectionTool
Implementation of the track selector tool.
Definition: InDetTrackSelectionTool.h:52
entries
double entries
Definition: listroot.cxx:49
TrackIsolationTool.h
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
xAOD::Iso::topoetcone40
@ topoetcone40
Definition: IsolationType.h:50
GeV
const float GeV
Definition: test_isolaitonTool.cxx:59
PhotonContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
xAOD::CaloCorrection::calobitset
Iso::IsolationCaloCorrectionBitset calobitset
Definition: IsolationCommon.h:15
xAOD::Iso::pileupCorrection
@ pileupCorrection
fully corrected
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:35
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31