ATLAS Offline Software
Loading...
Searching...
No Matches
testIsolationSelectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// System include(s):
6#include <memory>
7#include <cstdlib>
8#include <utility>
9
10// ROOT include(s):
11#include <TFile.h>
12#include <TError.h>
13#include <TString.h>
14#include <TEnv.h>
15
16// Infrastructure include(s):
18#include "xAODRootAccess/Init.h"
21
22// EDM include(s):
27
28#include <iostream>
29#include <cmath>
30#include <ctime>
31
34
36ANA_MSG_SOURCE(Test, "testIsolationSelectionTool")
37using namespace Test;
38
39std::string MuonIso(""), ElectronIso(""), PhotonIso("");
40
41float MuonPt(0), ElectronPt(0), PhotonPt(0);
42float MuonEta(0), ElectronEta(0), PhotonEta(0);
43
44StatusCode setConfigWP(TString conf){
45 TEnv env;
46 if(env.ReadFile(conf, kEnvAll) != 0){
47 ANA_MSG_INFO("Cannot read config file " << conf);
48 return StatusCode::FAILURE;
49 }
50 ANA_MSG_INFO("Reading config file " << conf);
51 MuonIso = env.GetValue("MuonIso", "PflowTight_FixedRad");
52 MuonPt = env.GetValue("MuonPt", 7000.);
53 MuonEta = env.GetValue("MuonEta", 2.5);
54
55 ElectronIso = env.GetValue("ElectronIso", "PLImprovedTight");
56 ElectronPt = env.GetValue("ElectronPt", 7000.);
57 ElectronEta = env.GetValue("ElectronEta", 2.47);
58
59 PhotonIso = env.GetValue("PhotonIso", "FixedCutTight");
60 PhotonPt = env.GetValue("PhotonPt", 7000.);
61 PhotonEta = env.GetValue("PhotonEta", 2.47);
62
63 env.PrintEnv();
64 return StatusCode::SUCCESS;
65}
66
67int main( int argc, char* argv[] ){
69
70 // The application's name:
71 const char* APP_NAME = argv[ 0 ];
72
73 // Check if we received a file name:
74 if( argc < 3 ) {
75 ANA_MSG_ERROR("No input file name or WP config specified!");
76 ANA_MSG_ERROR("Usage: %s <WPconfig> <xAOD file> <NEvents>");
77 return EXIT_FAILURE;
78 }
79 // Initialize the application:
81 auto start = std::time(nullptr);
82 ANA_MSG_INFO("Initialized " << std::ctime(&start));
83
84 // Open the input file:
85 const TString fileName = argv[ 2 ];
86 ANA_MSG_INFO("Opening file: " << fileName.Data());
87 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
88 if( !ifile.get() ) return EXIT_FAILURE;
89
90 const TString configFile = argv[ 1 ];
91 ANA_CHECK( setConfigWP(configFile) );
92
93 // Create a TEvent object:
95 ANA_CHECK( event.readFrom( ifile.get() ) );
96 ANA_MSG_INFO("Number of events in the file" << static_cast<int>(event.getEntries()));
97
98 // Create a transient object store. Needed for the tools.
99 xAOD::TStore store;
100
101 // Decide how many events to run over:
102 Long64_t entries = event.getEntries();
103 if( argc > 3 ) {
104 const Long64_t e = atoll( argv[ 3 ] );
105 if( e < entries ) entries = e;
106 }
107
108 // This is a testing file, lets fail whenever we can
109#ifdef XAOD_STANDALONE
110 StatusCode::enableFailure();
111#endif
112
113 ANA_MSG_INFO("Initialize the standard instance of the tool");
114 CP::IsolationSelectionTool IsoSelectionTool("IsoSelectionTool");
115 ANA_CHECK( IsoSelectionTool.setProperty("MuonWP", MuonIso) );
116 ANA_CHECK( IsoSelectionTool.setProperty("ElectronWP", ElectronIso) );
117 ANA_CHECK( IsoSelectionTool.setProperty("PhotonWP", PhotonIso) );
118
119 ANA_CHECK( IsoSelectionTool.setProperty("OutputLevel", MSG::DEBUG) );
120 ANA_CHECK( IsoSelectionTool.initialize() );
121
122 ANA_MSG_INFO("Initialize the low-Pt augmentation (PLV-only)");
123 CP::IsolationLowPtPLVTool IsoSelectionTool_lowPt("IsoSelectionTool_lowPt");
124 ANA_CHECK( IsoSelectionTool_lowPt.setProperty("OutputLevel", MSG::DEBUG) );
125 ANA_CHECK( IsoSelectionTool_lowPt.initialize() );
126
127 std::string m_sgKeyPhotons("Photons");
128 std::string m_sgKeyElectrons("Electrons");
129 std::string m_sgKeyMuons("Muons");
130
131 // Loop over the events:
132 for( Long64_t entry(0); entry<entries; entry++ ) {
133 ANA_MSG_INFO("Entry " << (int)entry);
134 event.getEntry( entry );
135
136 const xAOD::PhotonContainer* photons(nullptr);
137 ANA_CHECK( event.retrieve(photons,m_sgKeyPhotons) );
138 ANA_MSG_INFO(" Number of pre-selected photons: " << (int)photons->size());
139
140 for (auto ph : *photons) {
141 if (ph->caloCluster() == nullptr) continue;
142 if (ph->pt() < PhotonPt || std::abs(ph->caloCluster()->eta()) > PhotonEta) continue;
143
144 if (IsoSelectionTool.accept( *ph ))
145 ANA_MSG_INFO(Form(" --> Photon (pt=%.1f, eta=%.3f, phi=%.3f) PASSES Isolation %s",ph->pt(),ph->eta(),ph->phi(),PhotonIso.c_str()));
146 else
147 ANA_MSG_INFO(Form(" --> Photon (pt=%.1f, eta=%.3f, phi=%.3f) FAILS Isolation %s",ph->pt(),ph->eta(),ph->phi(),PhotonIso.c_str()));
148 continue;
149 }
150
151 const xAOD::ElectronContainer* electrons(nullptr);
152 ANA_CHECK( event.retrieve(electrons,m_sgKeyElectrons) );
153 ANA_MSG_INFO(" Number of pre-selected electrons: " << (int)electrons->size());
154
155 for (auto el : *electrons) {
156 if (el->caloCluster() == nullptr) continue;
157 if (el->pt() < ElectronPt || std::abs(el->caloCluster()->eta()) > ElectronEta) continue;
158 if(ElectronIso.find("PLV") != std::string::npos) ANA_CHECK( IsoSelectionTool_lowPt.augmentPLV(*el) );
159
160 if (IsoSelectionTool.accept( *el ))
161 ANA_MSG_INFO(Form(" --> Electron (pt=%.1f, eta=%.3f, phi=%.3f) PASSES Isolation %s",el->pt(),el->eta(),el->phi(), ElectronIso.c_str()));
162 else
163 ANA_MSG_INFO(Form(" --> Electron (pt=%.1f, eta=%.3f, phi=%.3f) FAILS Isolation %s",el->pt(),el->eta(),el->phi(), ElectronIso.c_str()));
164 continue;
165 }
166
167 const xAOD::MuonContainer* muons(nullptr);
168 ANA_CHECK( event.retrieve(muons,m_sgKeyMuons) );
169 ANA_MSG_INFO(" Number of pre-selected muons: " << (int)muons->size());
170
171 for (auto mu : *muons) {
172 if (mu->pt() < MuonPt || std::abs(mu->eta()) > MuonEta) continue;
173 if(MuonIso.find("PLV") != std::string::npos) ANA_CHECK( IsoSelectionTool_lowPt.augmentPLV(*mu) );
174
175 if (IsoSelectionTool.accept( *mu ))
176 ANA_MSG_INFO(Form(" --> Muon (pt=%.1f, eta=%.3f, phi=%.3f) PASSES Isolation %s",mu->pt(),mu->eta(),mu->phi(), MuonIso.c_str()));
177 else
178 ANA_MSG_INFO(Form(" --> Muon (pt=%.1f, eta=%.3f, phi=%.3f) FAILS Isolation %s",mu->pt(),mu->eta(),mu->phi(), MuonIso.c_str()));
179 continue;
180 }
181
182 continue;
183 } // end loop over events
184
185 auto end = std::time(nullptr);
186 ANA_MSG_INFO(Form("Ran on %i event for testing %s",(int)entries, std::ctime(&end)));
187
188 return EXIT_SUCCESS;
189}
#define APP_NAME
macros for messaging and checking status codes
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual StatusCode augmentPLV(const xAOD::IParticle &particle) override
This method adds the lowPT PLV score as decoration to the lepton.
virtual StatusCode initialize() override
Function initialising the tool.
virtual asg::AcceptData accept(const xAOD::Photon &x) const override
Declare the interface that the class provides.
size_type size() const noexcept
Returns the number of elements in the collection.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
STL namespace.
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".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
float ElectronEta(0)
StatusCode setConfigWP(TString conf)
std::string ElectronIso("")
std::string PhotonIso("")
std::string MuonIso("")
float ElectronPt(0)
float MuonEta(0)
float MuonPt(0)
float PhotonPt(0)
float PhotonEta(0)
StatusCode setConfigWP(TString conf)