ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
ElectronPhotonSelectorTools
util
testEGChargeIDSelector.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// System include(s):
6
#include <memory>
7
#include <cstdlib>
8
9
// ROOT include(s):
10
#include <TFile.h>
11
#include <TError.h>
12
#include <TString.h>
13
14
// EDM include(s):
15
#include "
xAODEgamma/ElectronContainer.h
"
16
#include "
xAODEgamma/PhotonContainer.h
"
17
#include "
xAODEgamma/Electron.h
"
18
#include "
xAODEgamma/Photon.h
"
19
20
#include "
ElectronPhotonSelectorTools/AsgPhotonIsEMSelector.h
"
21
#include "
ElectronPhotonSelectorTools/AsgForwardElectronIsEMSelector.h
"
22
#include "
ElectronPhotonSelectorTools/AsgElectronIsEMSelector.h
"
23
#include "
ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h
"
24
#include "
ElectronPhotonSelectorTools/AsgElectronChargeIDSelectorTool.h
"
25
#include "
AsgMessaging/AsgMessaging.h
"
26
27
// Derivation include
28
#include "
xAODCore/tools/IOStats.h
"
29
#include "
xAODCore/tools/ReadStats.h
"
30
31
32
33
// Infrastructure include(s):
34
#ifdef ROOTCORE
35
# include "
xAODRootAccess/Init.h
"
36
# include "
xAODRootAccess/TEvent.h
"
37
# include "
xAODRootAccess/TStore.h
"
38
#endif
// ROOTCORE
39
40
//Define msg functionality using AsgMessaging
41
//---------------------------------------------------
42
namespace
{
43
asg::AsgMessaging
dummymsg(
""
);
44
}
45
#define DUMMY_MSG( lvl, ARG ) {dummymsg.msg(lvl)<<ARG<<endmsg ;}
46
#define MSG_DEBUG( ARG ) {DUMMY_MSG(MSG::DEBUG, ARG);}
47
#define MSG_INFO( ARG ) {DUMMY_MSG(MSG::INFO, ARG);}
48
#define MSG_WARNING( ARG ) {DUMMY_MSG(MSG::WARNING, ARG);}
49
#define MSG_ERROR( ARG ) {DUMMY_MSG(MSG::ERROR, ARG);}
50
#define MSG_FATAL( ARG ) {DUMMY_MSG(MSG::FATAL, ARG);}
51
#define MSG_ABORT( ARG ) {DUMMY_MSG(MSG::FATAL, ARG); std::abort();}
52
#define CHECK( ARG ) \
53
do { \
54
const bool result = ARG; \
55
if( ! result ) { \
56
MSG_ERROR("FAILED to execute" <<#ARG); \
57
return EXIT_FAILURE; \
58
} \
59
} while( false )
60
//---------------------------------------------------
61
62
//main test code
63
int
main
(
int
argc,
char
* argv[] ) {
64
65
// The application's name:
66
const
char
*
APP_NAME
= argv[ 0 ];
67
68
MSG::Level mylevel=MSG::DEBUG;
69
dummymsg.msg().setLevel(mylevel);
70
dummymsg.msg().setName(
APP_NAME
);
71
// Check if we received a file name:
72
if
( argc < 2 ) {
73
MSG_ERROR
(
"No file name received!"
);
74
MSG_ERROR
(
" Usage: %s [xAOD file name]"
);
75
return
EXIT_FAILURE;
76
}
77
78
// Initialise the application:
79
CHECK
(
xAOD::Init
(
APP_NAME
) );
80
81
// Open the input file:
82
const
TString fileName = argv[ 1 ];
83
Info(
APP_NAME
,
"Opening file: %s"
, fileName.Data() );
84
std::unique_ptr< TFile > ifile( TFile::Open( fileName,
"READ"
) );
85
CHECK
( ifile.get() );
86
87
// Check if we want to process Electron or Photon
88
bool
isElectron
=
true
;
89
if
( argc < 4 ) {
90
Info (
APP_NAME
,
"By default looking to Electron"
);
91
}
else
{
92
int
argv1 = atoi(argv[ 3 ]);
93
if
(argv1 == 0)
isElectron
=
false
;
94
if
(
isElectron
) Info(
APP_NAME
,
"We are lookign to Electron-ID: %i"
,
isElectron
);
95
else
Info(
APP_NAME
,
"We are looking to Photon-ID"
);
96
}
97
// Create a TEvent object (persistent store)
98
99
//For 2.4.5 testing
100
xAOD::TEvent
pers(
xAOD::TEvent::kAthenaAccess
);
101
//For 2.3
102
//xAOD::TEvent pers( xAOD::TEvent::kBranchAccess );
103
104
// Create a TStore object (transient store)
105
xAOD::TStore
trans;
106
CHECK
( pers.
readFrom
( ifile.get() ) );
107
//
108
MSG_INFO
(
"Number of events in the file: "
<< pers.
getEntries
());
109
110
// Decide how many events to run over:
111
Long64_t
entries
= pers.
getEntries
();
112
if
( argc > 2 ) {
113
const
Long64_t e = atoll( argv[ 2 ] );
114
if
( e <
entries
) {
115
entries
= e;
116
}
117
}
118
119
120
if
(
isElectron
) {
121
//tight ECIDS
122
std::unique_ptr<AsgElectronChargeIDSelectorTool> m_electronECIDS = std::make_unique<AsgElectronChargeIDSelectorTool> (
"tightECIDS"
);
123
std::string trainingfile = std::string(std::getenv(
"ROOTCOREBIN"
)) +
"/data/ElectronPhotonSelectorTools/ECIDS_20161125for2017Moriond.root"
;
124
CHECK
(m_electronECIDS->setProperty(
"TrainingFile"
, trainingfile));
125
CHECK
(m_electronECIDS->setProperty(
"CutOnBDT"
, 0));
126
m_electronECIDS->msg().setLevel(mylevel);
127
CHECK
(m_electronECIDS->initialize());
128
129
//Tight Likelihood electron
130
std::unique_ptr<AsgElectronLikelihoodTool> m_TightLH = std::make_unique<AsgElectronLikelihoodTool> (
"TightLH"
);
131
CHECK
(m_TightLH->setProperty(
"WorkingPoint"
,
"TightLHElectron"
));
132
m_TightLH->msg().setLevel(mylevel);
133
CHECK
(m_TightLH->initialize());
134
135
// Loop over the events:
136
for
( Long64_t entry = 0; entry <
entries
; ++entry ) {
137
138
// Tell the object which entry to look at:
139
pers.
getEntry
( entry );
140
MSG_INFO
(
"============================"
);
141
MSG_INFO
(
"Event: "
<<entry);
142
143
const
xAOD::ElectronContainer
* electrons;
144
CHECK
(pers.
retrieve
(electrons,
"Electrons"
));
145
146
unsigned
int
counter=0;
147
for
(
const
xAOD::Electron
* el : *electrons) {
148
MSG_INFO
(
"---------------------------"
);
149
MSG_INFO
(
"Electron: "
<< counter);
150
MSG_INFO
(
"Electron LH Tight accept result: "
<<m_TightLH->accept(el));
151
// MSG_INFO("Electron stored LH Tight: " << el->passSelection("LHTight") );
152
MSG_INFO
(
"Electron Cut ECIDS accept result: "
<<m_electronECIDS->accept(el));
153
MSG_INFO
(
"Electron stored Tight: "
<< el->passSelection(
"Tight"
) );
154
++counter;
155
}
156
}
// loop entries
157
158
}
// is electron
159
else
{
160
//Tight cut based photon
161
std::unique_ptr<AsgPhotonIsEMSelector> m_photonTightIsEMSelector = std::make_unique<AsgPhotonIsEMSelector> (
"photonTightIsEMSelector"
);
162
CHECK
(m_photonTightIsEMSelector->setProperty(
"WorkingPoint"
,
"TightPhoton"
));
163
m_photonTightIsEMSelector->msg().setLevel(mylevel);
164
CHECK
(m_photonTightIsEMSelector->initialize());
165
166
// Loop over the events:
167
for
( Long64_t entry = 0; entry <
entries
; ++entry ) {
168
169
// Tell the object which entry to look at:
170
pers.
getEntry
( entry );
171
MSG_INFO
(
"============================"
);
172
MSG_INFO
(
"Event: "
<<entry);
173
174
const
xAOD::PhotonContainer
* photons;
175
CHECK
(pers.
retrieve
(photons,
"Photons"
));
176
unsigned
int
counter=0;
177
for
(
const
xAOD::Photon
* ph : *photons) {
178
if
(ph->author() !=
xAOD::EgammaParameters::AuthorCaloTopo35
){
179
MSG_INFO
(
"---------------------------"
);
180
MSG_INFO
(
"Photon: "
<< counter);
181
MSG_INFO
(
"Photon Tight accept result: "
<<m_photonTightIsEMSelector->accept(ph));
182
++counter;
183
}
184
}
185
}
// loop entries
186
}
187
188
189
xAOD::IOStats::instance
().
stats
().
printSmartSlimmingBranchList
();
190
return
0;
191
}
192
193
194
AsgElectronChargeIDSelectorTool.h
AsgElectronIsEMSelector.h
AsgElectronLikelihoodTool.h
AsgForwardElectronIsEMSelector.h
AsgMessaging.h
AsgPhotonIsEMSelector.h
isElectron
bool isElectron(const T &p)
Definition
AtlasPID.h:208
APP_NAME
#define APP_NAME
Definition
BoostedXbbTag.cxx:25
TEvent.h
ElectronContainer.h
Electron.h
PhotonContainer.h
Photon.h
IOStats.h
Init.h
ReadStats.h
TStore.h
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition
AsgMessaging.h:40
xAOD::Event::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition
IOStats.cxx:17
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition
IOStats.cxx:11
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:59
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:74
xAOD::TEvent::getEntry
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0) override
Function loading a given entry of the input TTree.
Definition
Control/xAODRootAccess/Root/TEvent.cxx:680
xAOD::TEvent::readFrom
StatusCode readFrom(::TFile &inFile) override
Set up the reading of an input file from TFile This method implements the interface from Event.
Definition
Control/xAODRootAccess/Root/TEvent.cxx:111
xAOD::TEvent::getEntries
::Long64_t getEntries() const override
Get how many entries are available from the current input file(s).
Definition
Control/xAODRootAccess/Root/TEvent.cxx:651
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition
TStore.h:45
main
int main()
Definition
hello.cxx:18
entries
double entries
Definition
listroot.cxx:49
xAOD::EgammaParameters::AuthorCaloTopo35
const uint16_t AuthorCaloTopo35
Photon reconstructed by SW CaloTopo35 seeded clusters.
Definition
EgammaDefs.h:38
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition
Init.cxx:31
xAOD::PhotonContainer
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/PhotonContainer.h:17
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
MSG_INFO
#define MSG_INFO(ARG)
Definition
testEGChargeIDSelector.cxx:47
CHECK
#define CHECK(ARG)
Definition
testEGChargeIDSelector.cxx:52
MSG_ERROR
#define MSG_ERROR(ARG)
Definition
testEGChargeIDSelector.cxx:49
Generated on
for ATLAS Offline Software by
1.17.0