ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
EGammaVariableCorrection
util
testElectronPhotonVariableCorrectionTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
10
11
// ROOT includes
12
#include "TFile.h"
13
#include "TString.h"
14
15
//EDM includes
16
#include "
xAODEgamma/ElectronContainer.h
"
17
#include "
xAODEgamma/PhotonContainer.h
"
18
#include "
xAODEgamma/PhotonAuxContainer.h
"
19
#include "
xAODEgamma/Electron.h
"
20
#include "
xAODEgamma/Photon.h
"
21
22
#include "
AsgTools/StandaloneToolHandle.h
"
23
#include "
EgammaAnalysisInterfaces/IElectronPhotonShowerShapeFudgeTool.h
"
24
25
#include "
AsgMessaging/AsgMessaging.h
"
26
28
#ifdef ROOTCORE
29
#include "
xAODRootAccess/TEvent.h
"
30
#include "
xAODRootAccess/TStore.h
"
31
#endif
//ROOTCORE
32
33
// main test code
34
35
int
main
(
int
argc,
char
* argv[])
36
{
37
using namespace
asg::msgUserCode;
38
39
// The application's name:
40
const
char
*
APP_NAME
= argv[0];
41
42
// Check if we received a file name:
43
if
(argc < 2)
44
{
45
ANA_MSG_ERROR
(
"No file name received!"
);
46
ANA_MSG_ERROR
(
" Usage: %s [xAOD file name] %d Num of events to process %d (0 photons , 1 electrons)"
);
47
return
EXIT_FAILURE;
48
}
49
50
//open input file
51
const
TString fileName = argv[1];
52
ANA_MSG_INFO
(
APP_NAME
<<
" Opening file: "
<< fileName.Data());
53
std::unique_ptr<TFile> inputFile(TFile::Open(fileName,
"READ"
));
//probably rather "READ"?
54
ANA_CHECK
(inputFile.get());
55
56
// Create a TEvent object (persistent store)
57
xAOD::TEvent
pers(
xAOD::TEvent::kClassAccess
);
58
// Create a TStore object (transient store)
59
xAOD::TStore
trans;
60
ANA_CHECK
(pers.
readFrom
(inputFile.get()));
61
//
62
ANA_MSG_INFO
(
"Number of events in the file: "
<< pers.
getEntries
());
63
64
// Decide how many events to run over:
65
Long64_t
entries
= pers.
getEntries
();
66
if
(argc > 2)
67
{
68
const
Long64_t userInputEntries = atoll(argv[2]);
69
if
(userInputEntries <
entries
)
70
{
71
entries
= userInputEntries;
72
}
73
}
74
ANA_MSG_INFO
(
"Running over "
<<
entries
<<
" events."
);
75
76
// initialize the tool
77
asg::StandaloneToolHandle<IElectronPhotonShowerShapeFudgeTool>
myTool(
"ElectronPhotonVariableCorrectionTool/myTestTool"
);
78
std::string
configFile
=
"EGammaVariableCorrection/EGammaVariableCorrectionTool_ExampleConf.conf"
;
79
ANA_CHECK
(myTool.
setProperty
(
"ConfigFile"
,
configFile
));
80
ANA_CHECK
(myTool.
initialize
());
81
82
// loop over the events
83
for
(Long64_t entry = 0; entry <
entries
; entry++)
84
{
85
//get entry
86
pers.
getEntry
(entry);
87
88
// ====================================
89
// Photons
90
// ====================================
91
92
//get photon container
93
const
xAOD::PhotonContainer
* photons;
94
ANA_CHECK
(pers.
retrieve
(photons,
"Photons"
));
95
96
// Make a deep copy of the photon container
97
// Create the new container and its auxiliary store.
98
auto
photons_copy = std::make_unique<xAOD::PhotonContainer>();
99
auto
photons_copy_aux = std::make_unique<xAOD::AuxContainerBase>();
100
photons_copy->setStore (photons_copy_aux.get());
//< Connect the two
101
102
//copy photons over
103
for
(
auto
photon : *photons) {
104
// Copy this photon to the output container:
105
xAOD::Photon
* photon_copy =
new
xAOD::Photon
();
106
photons_copy->push_back (photon_copy);
// photon acquires the photon_copy auxstore
107
*photon_copy = *photon;
// copies auxdata from one auxstore to the other
108
}
109
// end make deep copy
110
111
//loop over deep copy of photon container
112
for
(
unsigned
int
photon_itr = 0; photon_itr < photons_copy->size(); photon_itr++)
113
{
114
xAOD::Photon
* photon = photons_copy->at(photon_itr);
115
116
//apply correction
117
ANA_CHECK
(myTool->applyCorrection(*photon));
118
119
}
// loop over deep copy of photon container
120
121
// ====================================
122
// Electrons
123
// ====================================
124
125
//get electron container
126
const
xAOD::ElectronContainer
* electrons;
127
ANA_CHECK
(pers.
retrieve
(electrons,
"Electrons"
));
128
129
// Make a deep copy of the electron container
130
// Create the new container and its auxiliary store.
131
auto
electrons_copy = std::make_unique<xAOD::ElectronContainer>();
132
auto
electrons_copy_aux = std::make_unique<xAOD::AuxContainerBase>();
133
electrons_copy->setStore (electrons_copy_aux.get());
//< Connect the two
134
135
//copy electrons over
136
for
(
auto
electron : *electrons) {
137
// Copy this electron to the output container:
138
xAOD::Electron
* electron_copy =
new
xAOD::Electron
();
139
electrons_copy->push_back (electron_copy);
// electron acquires the electron_copy auxstore
140
*electron_copy = *electron;
// copies auxdata from one auxstore to the other
141
}
142
// end make deep copy
143
144
//loop over deep copy of electron container
145
for
(
unsigned
int
electron_itr = 0; electron_itr < electrons_copy->size(); electron_itr++)
146
{
147
xAOD::Electron
* electron = electrons_copy->at(electron_itr);
148
149
//apply correction
150
ANA_CHECK
(myTool->applyCorrection(*electron));
151
152
}
// loop over deep copy of electrone container
153
154
}
// loop over events
155
156
return
0;
157
}
AsgMessaging.h
APP_NAME
#define APP_NAME
Definition
BoostedXbbTag.cxx:25
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
TEvent.h
ElectronContainer.h
Electron.h
PhotonContainer.h
Photon.h
IElectronPhotonShowerShapeFudgeTool.h
PhotonAuxContainer.h
StandaloneToolHandle.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::Event::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:59
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:73
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
configFile
Definition
configFile.py:1
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
Generated on
for ATLAS Offline Software by
1.17.0