ATLAS Offline Software
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"
19 #include "xAODRootAccess/TEvent.h"
20 #include "xAODRootAccess/TStore.h"
21 
22 // EDM include(s):
25 #include "xAODMuon/MuonContainer.h"
27 
28 #include <iostream>
29 #include <cmath>
30 #include <ctime>
31 
34 
35 ANA_MSG_HEADER(Test)
36 ANA_MSG_SOURCE(Test, "testIsolationSelectionTool")
37 using namespace Test;
38 
39 std::string MuonIso(""), ElectronIso(""), PhotonIso("");
40 
41 float MuonPt(0), ElectronPt(0), PhotonPt(0);
42 float MuonEta(0), ElectronEta(0), PhotonEta(0);
43 
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 
67 int main( int argc, char* argv[] ){
68  ANA_CHECK_SET_TYPE (int);
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 ];
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.
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 }
ElectronEta
float ElectronEta(0)
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
PhotonPt
float PhotonPt(0)
taskman.configFile
configFile
Definition: taskman.py:311
IsolationType.h
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
CP::IsolationLowPtPLVTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: IsolationLowPtPLVTool.cxx:32
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
PhotonIso
std::string PhotonIso("")
CP::IsolationLowPtPLVTool::augmentPLV
virtual StatusCode augmentPLV(const xAOD::IParticle &particle) override
This method adds the lowPT PLV score as decoration to the lepton.
Definition: IsolationLowPtPLVTool.cxx:70
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ANA_MSG_HEADER
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:113
python.ConfigurableDb.conf
def conf
Definition: ConfigurableDb.py:282
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
main
int main(int argc, char *argv[])
Definition: testIsolationSelectionTool.cxx:67
IsolationSelectionTool.h
IsolationLowPtPLVTool.h
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ElectronContainer.h
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
MessageCheck.h
macros for messaging and checking status codes
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
CP::IsolationSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::Photon &x) const override
Declare the interface that the class provides.
Definition: IsolationSelectionTool.cxx:401
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
MuonIso
std::string MuonIso("")
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
MuonEta
float MuonEta(0)
PhotonEta
float PhotonEta(0)
MuonContainer.h
setConfigWP
StatusCode setConfigWP(TString conf)
Definition: testIsolationSelectionTool.cxx:44
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
ElectronIso
std::string ElectronIso("")
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
CP::IsolationSelectionTool
Definition: IsolationSelectionTool.h:25
DEBUG
#define DEBUG
Definition: page_access.h:11
CP::IsolationSelectionTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: IsolationSelectionTool.cxx:27
entries
double entries
Definition: listroot.cxx:49
CP::IsolationLowPtPLVTool
Definition: IsolationLowPtPLVTool.h:17
MuonPt
float MuonPt(0)
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
PhotonContainer.h
ElectronPt
float ElectronPt(0)
TStore.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:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31