ATLAS Offline Software
Loading...
Searching...
No Matches
testIsolationSelectionTool.cxx File Reference
#include <memory>
#include <cstdlib>
#include <utility>
#include <TFile.h>
#include <TError.h>
#include <TString.h>
#include <TEnv.h>
#include "AsgMessaging/MessageCheck.h"
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/TEvent.h"
#include "xAODRootAccess/TStore.h"
#include "xAODEgamma/PhotonContainer.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODMuon/MuonContainer.h"
#include "xAODPrimitives/IsolationType.h"
#include <iostream>
#include <cmath>
#include <ctime>
#include "CxxUtils/checker_macros.h"
#include "IsolationSelection/IsolationSelectionTool.h"
#include "IsolationSelection/IsolationLowPtPLVTool.h"

Go to the source code of this file.

Functions

StatusCode setConfigWP (TString conf) ATLAS_NOT_THREAD_SAFE
int main (int argc, char *argv[]) ATLAS_NOT_THREAD_SAFE

Variables

std::string MuonIso ATLAS_THREAD_SAFE = ""

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 74 of file testIsolationSelectionTool.cxx.

74 {
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.
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
#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_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
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
double entries
Definition listroot.cxx:49
TestStore store
Definition TestStore.cxx:23
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

◆ setConfigWP()

StatusCode setConfigWP ( TString conf)

Definition at line 51 of file testIsolationSelectionTool.cxx.

51 {
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}

Variable Documentation

◆ ATLAS_THREAD_SAFE

float PhotonEta ATLAS_THREAD_SAFE = ""

Definition at line 40 of file testIsolationSelectionTool.cxx.