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>
32
35
37ANA_MSG_SOURCE(Test, "testIsolationSelectionTool")
38using namespace Test;
39
40std::string MuonIso ATLAS_THREAD_SAFE = "";
41std::string ElectronIso ATLAS_THREAD_SAFE = "";
42std::string PhotonIso ATLAS_THREAD_SAFE = "";
43
44float MuonPt ATLAS_THREAD_SAFE = 0;
45float ElectronPt ATLAS_THREAD_SAFE = 0;
46float PhotonPt ATLAS_THREAD_SAFE = 0;
47float MuonEta ATLAS_THREAD_SAFE = 0;
48float ElectronEta ATLAS_THREAD_SAFE = 0;
49float PhotonEta ATLAS_THREAD_SAFE = 0;
50
51StatusCode setConfigWP(TString conf) ATLAS_NOT_THREAD_SAFE {
52 TEnv env;
53 if(env.ReadFile(conf, kEnvAll) != 0){
54 ANA_MSG_INFO("Cannot read config file " << conf);
55 return StatusCode::FAILURE;
56 }
57 ANA_MSG_INFO("Reading config file " << conf);
58 MuonIso = env.GetValue("MuonIso", "PflowTight_FixedRad");
59 MuonPt = env.GetValue("MuonPt", 7000.);
60 MuonEta = env.GetValue("MuonEta", 2.5);
61
62 ElectronIso = env.GetValue("ElectronIso", "PLImprovedTight");
63 ElectronPt = env.GetValue("ElectronPt", 7000.);
64 ElectronEta = env.GetValue("ElectronEta", 2.47);
65
66 PhotonIso = env.GetValue("PhotonIso", "FixedCutTight");
67 PhotonPt = env.GetValue("PhotonPt", 7000.);
68 PhotonEta = env.GetValue("PhotonEta", 2.47);
69
70 env.PrintEnv();
71 return StatusCode::SUCCESS;
72}
73
74int main( int argc, char* argv[] ) ATLAS_NOT_THREAD_SAFE {
76
77 // The application's name:
78 const char* APP_NAME = argv[ 0 ];
79
80 // Check if we received a file name:
81 if( argc < 3 ) {
82 ANA_MSG_ERROR("No input file name or WP config specified!");
83 ANA_MSG_ERROR("Usage: %s <WPconfig> <xAOD file> <NEvents>");
84 return EXIT_FAILURE;
85 }
86 // Initialize the application:
88 auto start = std::time(nullptr);
89 char tbuf_start[26]; ::ctime_r(&start, tbuf_start);
90 ANA_MSG_INFO("Initialized " << tbuf_start);
91
92 // Open the input file:
93 const TString fileName = argv[ 2 ];
94 ANA_MSG_INFO("Opening file: " << fileName.Data());
95 std::unique_ptr< TFile > ifile( TFile::Open( fileName, "READ" ) );
96 if( !ifile.get() ) return EXIT_FAILURE;
97
98 const TString configFile = argv[ 1 ];
100
101 // Create a TEvent object:
103 ANA_CHECK( event.readFrom( ifile.get() ) );
104 ANA_MSG_INFO("Number of events in the file" << static_cast<int>(event.getEntries()));
105
106 // Create a transient object store. Needed for the tools.
107 xAOD::TStore store;
108
109 // Decide how many events to run over:
110 Long64_t entries = event.getEntries();
111 if( argc > 3 ) {
112 const Long64_t e = atoll( argv[ 3 ] );
113 if( e < entries ) entries = e;
114 }
115
116 // This is a testing file, lets fail whenever we can
117#ifdef XAOD_STANDALONE
118 StatusCode::enableFailure();
119#endif
120
121 ANA_MSG_INFO("Initialize the standard instance of the tool");
122 CP::IsolationSelectionTool IsoSelectionTool("IsoSelectionTool");
123 ANA_CHECK( IsoSelectionTool.setProperty("MuonWP", MuonIso) );
124 ANA_CHECK( IsoSelectionTool.setProperty("ElectronWP", ElectronIso) );
125 ANA_CHECK( IsoSelectionTool.setProperty("PhotonWP", PhotonIso) );
126
127 ANA_CHECK( IsoSelectionTool.setProperty("OutputLevel", MSG::DEBUG) );
128 ANA_CHECK( IsoSelectionTool.initialize() );
129
130 ANA_MSG_INFO("Initialize the low-Pt augmentation (PLV-only)");
131 CP::IsolationLowPtPLVTool IsoSelectionTool_lowPt("IsoSelectionTool_lowPt");
132 ANA_CHECK( IsoSelectionTool_lowPt.setProperty("OutputLevel", MSG::DEBUG) );
133 ANA_CHECK( IsoSelectionTool_lowPt.initialize() );
134
135 std::string sgKeyPhotons("Photons");
136 std::string sgKeyElectrons("Electrons");
137 std::string sgKeyMuons("Muons");
138
139 // Loop over the events:
140 for( Long64_t entry(0); entry<entries; entry++ ) {
141 ANA_MSG_INFO("Entry " << (int)entry);
142 event.getEntry( entry );
143
144 const xAOD::PhotonContainer* photons(nullptr);
145 ANA_CHECK( event.retrieve(photons,sgKeyPhotons) );
146 ANA_MSG_INFO(" Number of pre-selected photons: " << (int)photons->size());
147
148 for (auto ph : *photons) {
149 if (ph->caloCluster() == nullptr) continue;
150 if (ph->pt() < PhotonPt || std::abs(ph->caloCluster()->eta()) > PhotonEta) continue;
151
152 if (IsoSelectionTool.accept( *ph ))
153 ANA_MSG_INFO(Form(" --> Photon (pt=%.1f, eta=%.3f, phi=%.3f) PASSES Isolation %s",ph->pt(),ph->eta(),ph->phi(),PhotonIso.c_str()));
154 else
155 ANA_MSG_INFO(Form(" --> Photon (pt=%.1f, eta=%.3f, phi=%.3f) FAILS Isolation %s",ph->pt(),ph->eta(),ph->phi(),PhotonIso.c_str()));
156 continue;
157 }
158
159 const xAOD::ElectronContainer* electrons(nullptr);
160 ANA_CHECK( event.retrieve(electrons,sgKeyElectrons) );
161 ANA_MSG_INFO(" Number of pre-selected electrons: " << (int)electrons->size());
162
163 for (auto el : *electrons) {
164 if (el->caloCluster() == nullptr) continue;
165 if (el->pt() < ElectronPt || std::abs(el->caloCluster()->eta()) > ElectronEta) continue;
166 if(ElectronIso.find("PLV") != std::string::npos) ANA_CHECK( IsoSelectionTool_lowPt.augmentPLV(*el) );
167
168 if (IsoSelectionTool.accept( *el ))
169 ANA_MSG_INFO(Form(" --> Electron (pt=%.1f, eta=%.3f, phi=%.3f) PASSES Isolation %s",el->pt(),el->eta(),el->phi(), ElectronIso.c_str()));
170 else
171 ANA_MSG_INFO(Form(" --> Electron (pt=%.1f, eta=%.3f, phi=%.3f) FAILS Isolation %s",el->pt(),el->eta(),el->phi(), ElectronIso.c_str()));
172 continue;
173 }
174
175 const xAOD::MuonContainer* muons(nullptr);
176 ANA_CHECK( event.retrieve(muons,sgKeyMuons) );
177 ANA_MSG_INFO(" Number of pre-selected muons: " << (int)muons->size());
178
179 for (auto mu : *muons) {
180 if (mu->pt() < MuonPt || std::abs(mu->eta()) > MuonEta) continue;
181 if(MuonIso.find("PLV") != std::string::npos) ANA_CHECK( IsoSelectionTool_lowPt.augmentPLV(*mu) );
182
183 if (IsoSelectionTool.accept( *mu ))
184 ANA_MSG_INFO(Form(" --> Muon (pt=%.1f, eta=%.3f, phi=%.3f) PASSES Isolation %s",mu->pt(),mu->eta(),mu->phi(), MuonIso.c_str()));
185 else
186 ANA_MSG_INFO(Form(" --> Muon (pt=%.1f, eta=%.3f, phi=%.3f) FAILS Isolation %s",mu->pt(),mu->eta(),mu->phi(), MuonIso.c_str()));
187 continue;
188 }
189
190 continue;
191 } // end loop over events
192
193 auto end = std::time(nullptr);
194 char tbuf_end[26]; ::ctime_r(&end, tbuf_end);
195 ANA_MSG_INFO(Form("Ran on %i event for testing %s",(int)entries, tbuf_end));
196
197 return EXIT_SUCCESS;
198}
#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
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
#define ATLAS_THREAD_SAFE
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".
StatusCode setConfigWP(TString conf) ATLAS_NOT_THREAD_SAFE