ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
ElectronEfficiencyCorrection
util
testEgEfficiencyCorrFwd.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// package includes
6
#include "
ElectronEfficiencyCorrection/AsgElectronEfficiencyCorrectionTool.h
"
7
#include "
SFHelpers.h
"
8
// System include(s):
9
#include <memory>
10
// ROOT include(s):
11
#include <TFile.h>
12
// Infrastructure include(s):
13
#include "
xAODRootAccess/Init.h
"
14
#include "
xAODRootAccess/TEvent.h
"
15
#include "
xAODRootAccess/TStore.h
"
16
17
// EDM include(s):
18
#include "
xAODEgamma/Electron.h
"
19
#include "
xAODEgamma/ElectronContainer.h
"
20
21
#include "
AsgMessaging/MessageCheck.h
"
22
#include "
AsgMessaging/MsgStream.h
"
23
#include "
AsgTools/StandaloneToolHandle.h
"
24
// To disable sending data
25
#include "
xAODRootAccess/tools/TFileAccessTracer.h
"
26
27
namespace
asg
{
28
ANA_MSG_HEADER
(testEgEfficiencyCorrFwd)
29
ANA_MSG_SOURCE
(testEgEfficiencyCorrFwd,
""
)
30
}
31
32
int
33
test1
(
int
argc,
char
* argv[])
34
{
35
36
xAOD::TFileAccessTracer::instance
().
enableDataSubmission
(
false
);
37
// The application's name:
38
const
char
*
APP_NAME
= argv[0];
39
using namespace
asg::testEgEfficiencyCorrFwd;
40
ANA_CHECK_SET_TYPE
(
int
);
41
MSG::Level mylevel = MSG::INFO;
42
setMsgLevel(mylevel);
43
msg
().setName(
APP_NAME
);
44
45
// Check if we received a file name:
46
if
(argc < 2) {
47
ANA_MSG_ERROR
(
APP_NAME
<<
"No file name received!"
);
48
ANA_MSG_ERROR
(
49
APP_NAME
50
<<
" Usage: <<APP_NAME << [xAOD file name] [Num of events to use]"
);
51
return
1;
52
}
53
54
// Initialise the application:
55
ANA_CHECK
(
xAOD::Init
(
APP_NAME
));
56
57
// Open the input file:
58
const
TString fileName = argv[1];
59
ANA_MSG_INFO
(
"Opening file: "
<< fileName.Data());
60
std::unique_ptr<TFile> ifile(TFile::Open(fileName,
"READ"
));
61
ANA_CHECK
(ifile.get());
62
63
// Create a TEvent object:
64
xAOD::TEvent
event;
65
66
// Then the tools
67
std::vector<std::string> id_configFiles{
68
"ElectronEfficiencyCorrection/2012/offline/"
69
"efficiencySF.offline.FwdTight.2012.8TeV.rel17p2.GEO21.v02.root"
70
};
// we don't support keys for fwd electrons, yet. Our latest file is 2012,
71
// still
72
asg::StandaloneToolHandle<IAsgElectronEfficiencyCorrectionTool>
ElEffCorrectionTool(
73
"AsgElectronEfficiencyCorrectionTool/ElEffCorrectionTool"
);
74
ANA_CHECK
(
75
ElEffCorrectionTool.
setProperty
(
"CorrectionFileNameList"
, id_configFiles));
76
ANA_CHECK
(ElEffCorrectionTool.
setProperty
(
"ForceDataType"
, 1));
77
ANA_CHECK
(ElEffCorrectionTool.
setProperty
(
"OutputLevel"
, mylevel));
78
ANA_CHECK
(ElEffCorrectionTool.
setProperty
(
"CorrelationModel"
,
"FULL"
));
79
ANA_CHECK
(ElEffCorrectionTool.
setProperty
(
"UseRandomRunNumber"
,
false
));
80
ANA_CHECK
(ElEffCorrectionTool.
initialize
());
81
82
// Then open the file(s)
83
ANA_CHECK
(event.readFrom(ifile.get()));
84
ANA_MSG_INFO
(
"Number of available events to read in: "
85
<<
static_cast<
long
long
int
>
(event.getEntries()));
86
87
// Decide how many events to run over:
88
long
long
int
entries
=
event
.getEntries();
89
if
(argc > 2) {
90
const
long
long
int
e = atoll(argv[2]);
91
if
(e <
entries
) {
92
entries
= e;
93
}
94
}
95
ANA_MSG_INFO
(
"Number actual events to read in: "
<<
entries
);
96
97
// Loop over the events:
98
for
(
long
long
int
entry = 0; entry <
entries
; ++entry) {
99
event
.getEntry(entry);
100
ANA_MSG_INFO
(
" \n ==> Event "
<< entry);
101
102
const
xAOD::ElectronContainer
* electrons =
nullptr
;
103
ANA_CHECK
(event.retrieve(electrons,
"ForwardElectrons"
));
104
105
for
(
const
xAOD::Electron
* el : *electrons) {
106
if
(el->pt() < 20000)
107
continue
;
// skip electrons outside of recommendations
108
if
(fabs(el->caloCluster()->eta()) < 2.5)
109
continue
;
// skip electrons outside of recommendations
110
int
index
= ElEffCorrectionTool->systUncorrVariationIndex(*el);
111
/*
112
* Set up the systematic variations
113
*/
114
bool
isToys =
false
;
115
double
nominalSF{};
116
double
totalNeg{};
117
double
totalPos{};
118
ANA_CHECK
(
119
SFHelpers::result
(
120
ElEffCorrectionTool, *el, nominalSF, totalPos, totalNeg, isToys) ==
121
0);
122
123
ANA_MSG_INFO
(
"===> electron : Pt = "
124
<< el->pt() <<
" : eta = "
<< el->eta()
125
<<
" : Bin index = "
<<
index
<<
" : SF = "
<< nominalSF
126
<<
" + "
<< totalPos <<
" - "
<< totalNeg <<
" <==="
);
127
}
128
}
129
130
ANA_MSG_INFO
(
"===> DONE <===\n"
);
131
return
0;
132
}
133
134
135
int
main
(
int
argc,
char
*argv[])
136
{
137
try
{
138
return
test1
(argc, argv);
139
}
catch
(
const
std::exception& e) {
140
std::cerr <<
"exception: "
<< e.what() <<
"\n"
;
141
return
1;
142
}
143
}
AsgElectronEfficiencyCorrectionTool.h
APP_NAME
#define APP_NAME
Definition
BoostedXbbTag.cxx:25
MessageCheck.h
macros for messaging and checking status codes
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
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
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
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
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
MsgStream.h
TEvent.h
ElectronContainer.h
Electron.h
Init.h
SFHelpers.h
StandaloneToolHandle.h
TFileAccessTracer.h
TStore.h
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition
StandaloneToolHandle.h:44
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition
StandaloneToolHandle.h:105
asg::StandaloneToolHandle::initialize
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
Definition
StandaloneToolHandle.h:158
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:59
xAOD::TFileAccessTracer::enableDataSubmission
void enableDataSubmission(bool value)
Function for turning data submission on/off.
Definition
TFileAccessTracer.cxx:322
xAOD::TFileAccessTracer::instance
static TFileAccessTracer & instance()
Access the singleton instance of this class.
Definition
TFileAccessTracer.cxx:263
main
int main()
Definition
hello.cxx:18
entries
double entries
Definition
listroot.cxx:49
SFHelpers::result
int result(asg::StandaloneToolHandle< IAsgElectronEfficiencyCorrectionTool > &tool, const xAOD::Electron &el, double &nominalSF, double &totalPos, double &totalNeg, const bool isToys)
Definition
SFHelpers.cxx:20
asg
Definition
DataHandleTestTool.h:28
index
Definition
index.py:1
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition
Init.cxx:31
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
test1
int test1(int argc, char *argv[])
Definition
testEgEfficiencyCorrFwd.cxx:33
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0