ATLAS Offline Software
Functions
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 "IsolationSelection/IsolationSelectionTool.h"
#include "IsolationSelection/IsolationLowPtPLVTool.h"

Go to the source code of this file.

Functions

std::string MuonIso ("")
 
std::string ElectronIso ("")
 
std::string PhotonIso ("")
 
float MuonPt (0)
 
float ElectronPt (0)
 
float PhotonPt (0)
 
float MuonEta (0)
 
float ElectronEta (0)
 
float PhotonEta (0)
 
StatusCode setConfigWP (TString conf)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ ElectronEta()

float ElectronEta ( )

◆ ElectronIso()

std::string ElectronIso ( ""  )

◆ ElectronPt()

float ElectronPt ( )

◆ main()

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

Definition at line 67 of file testIsolationSelectionTool.cxx.

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

◆ MuonEta()

float MuonEta ( )

◆ MuonIso()

std::string MuonIso ( ""  )

◆ MuonPt()

float MuonPt ( )

◆ PhotonEta()

float PhotonEta ( )

◆ PhotonIso()

std::string PhotonIso ( ""  )

◆ PhotonPt()

float PhotonPt ( )

◆ setConfigWP()

StatusCode setConfigWP ( TString  conf)

Definition at line 44 of file testIsolationSelectionTool.cxx.

44  {
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 }
ElectronEta
float ElectronEta(0)
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
SGTest::store
TestStore store
Definition: TestStore.cxx:23
PhotonPt
float PhotonPt(0)
taskman.configFile
configFile
Definition: taskman.py:311
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
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
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
PhotonIso
std::string PhotonIso("")
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.ConfigurableDb.conf
def conf
Definition: ConfigurableDb.py:282
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:124
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonIso
std::string MuonIso("")
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
MuonEta
float MuonEta(0)
PhotonEta
float PhotonEta(0)
setConfigWP
StatusCode setConfigWP(TString conf)
Definition: testIsolationSelectionTool.cxx:44
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:74
CP::IsolationSelectionTool
Definition: IsolationSelectionTool.h:25
DEBUG
#define DEBUG
Definition: page_access.h:11
entries
double entries
Definition: listroot.cxx:49
CP::IsolationLowPtPLVTool
Definition: IsolationLowPtPLVTool.h:17
MuonPt
float MuonPt(0)
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
ElectronPt
float ElectronPt(0)
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::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31