ATLAS Offline Software
Loading...
Searching...
No Matches
testEgammaCalibTool.cxx File Reference

Go to the source code of this file.

Macros

#define CHECK(ARG)

Functions

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

Variables

const double MIN_PT = 20E3

Macro Definition Documentation

◆ CHECK

#define CHECK ( ARG)
Value:
do { \
const bool result = ARG; \
if( ! result ) { \
::Error( APP_NAME, "Failed to execute: \"%s\"", \
#ARG ); \
return 1; \
} \
} while( false )
#define APP_NAME

Definition at line 44 of file testEgammaCalibTool.cxx.

44#define CHECK( ARG ) \
45do { \
46 const bool result = ARG; \
47 if( ! result ) { \
48 ::Error( APP_NAME, "Failed to execute: \"%s\"", \
49#ARG ); \
50 return 1; \
51 } \
52 } while( false )

Function Documentation

◆ main()

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

Definition at line 57 of file testEgammaCalibTool.cxx.

57 {
58
59 // The application's name:
60 const char* APP_NAME = argv[0];
61
62 // Check if we received a file name:
63 if (argc < 2) {
64 Error( APP_NAME, "No file name received!" );
65 Error( APP_NAME, " Usage: %s (xAOD file name)", APP_NAME );
66 return 1;
67 }
68
69 // Initialise the application:
71
72 // Open the input file:
73 const TString fileName = argv[1];
74 Info( APP_NAME, "Opening file: %s", fileName.Data() );
75 std::unique_ptr<TFile> ifile(TFile::Open( fileName, "READ"));
76 CHECK( ifile.get() );
77 if ((!ifile.get() ) || ifile->IsZombie()) {
78 Error(APP_NAME, "Couldn't open file: %s", argv[1]);
79 return 1;
80 }
81
82 // Create a TEvent object:
84 CHECK( event.readFrom( ifile.get() ) );
85 Info( APP_NAME, "Number of events in the file: %i",
86 static_cast< int >( event.getEntries() ) );
87
88 // Decide how many events to run over:
89 Long64_t entries = event.getEntries();
90 if( argc > 2 ) {
91 const Long64_t e = atoll( argv[ 2 ] );
92 if( e < entries ) {
93 entries = e;
94 }
95 }
96
97 // Create the tool
98 std::unique_ptr<CP::IEgammaCalibrationAndSmearingTool> tool(new CP::EgammaCalibrationAndSmearingTool("EgammaCalibrationAndSmearingTool"));
99 RETURN_CHECK(APP_NAME, asg::setProperty(tool.get(), "ESModel", "es2017_R21_PRE"));
100 RETURN_CHECK(APP_NAME, asg::setProperty(tool.get(), "randomRunNumber", 123456));
101 RETURN_CHECK(APP_NAME, tool->initialize());
102
103
104 //===========SYSTEMATICS
106 const CP::SystematicSet& recommendedSystematics = registry.recommendedSystematics();
107 std::vector<CP::SystematicSet> sysList;
108
109 std::cout << "SIZE of the systematics set:" << recommendedSystematics.size() << std::endl;
110
111 for (auto sys : recommendedSystematics) { sysList.push_back(CP::SystematicSet({sys})); }
112
113
114 // Loop over the events:
115 for (Long64_t entry = 0; entry < entries; ++entry) {
116
117 // Tell the object which entry to look at:
118 event.getEntry(entry);
119
120 std::cout << "=================NEXT EVENT==========================" << std::endl;
121
122 const xAOD::EventInfo* event_info = 0;
123 CHECK( event.retrieve( event_info, "EventInfo" ) );
124
125
126 const xAOD::PhotonContainer* photons = nullptr;
127 CHECK( event.retrieve(photons, "Photons") );
128
129 //Clone
130 std::pair<xAOD::PhotonContainer*, xAOD::ShallowAuxContainer* > photons_shallowCopy = xAOD::shallowCopyContainer(*photons);
131
132 //Iterate over the shallow copy
133 for (xAOD::Photon* ph : *photons_shallowCopy.first) {
134 if (ph->pt() < MIN_PT) { continue; }
135 std::cout << std::string(80, '-') << std::endl;
136 std::cout << "eta|phi|pt|xAOD e = " << ph->eta() << "|" << ph->phi() << "|" << ph->pt() << "|" << ph->e() << std::endl;
137 if (not ph->caloCluster()) {
138 std::cout << "ERROR: particle has no calocluster" << std::endl;
139 continue;
140 }
141 std::cout << "raw E = " << ph->caloCluster()->energyBE(1) + ph->caloCluster()->energyBE(2) + ph->caloCluster()->energyBE(3) << std::endl;
143 std::cout << "particle is not electron of photon" << std::endl;
144 continue;
145 }
146
147 CHECK(tool->applyCorrection(*ph));
148 std::cout << "Calibrated e = " << ph->e() << std::endl;
149
150 //systematics
151 std::cout << "\n=============SYSTEMATICS CHECK NOW";
152 for (auto sys : sysList) {
153 // Tell the calibration tool which variation to apply
154 if (tool->applySystematicVariation(sys) != StatusCode::SUCCESS) {
155 Error(APP_NAME, "Cannot configure calibration tool for systematics");
156 }
157
158 CHECK(tool->applyCorrection(*ph));
159 std::cout << "\nCalibrated pt with systematic " << sys.name() << " = " << ph->pt();
160 }
161 std::cout << "\n=============END SYSTEMATICS " << std::endl;
162 }
163
164
165
166 const xAOD::ElectronContainer* electrons = nullptr;
167 CHECK( event.retrieve(electrons, "Electrons") );
168
169 //Clone
170 std::pair< xAOD::ElectronContainer*, xAOD::ShallowAuxContainer* > electrons_shallowCopy = xAOD::shallowCopyContainer( *electrons );
171
172 //Iterate over the shallow copy
173 for (xAOD::Electron* el : *electrons_shallowCopy.first) {
174 if (el->pt() < MIN_PT) { continue; }
175 std::cout << std::string(80, '-') << std::endl;
176 std::cout << "eta|phi|pt|xAOD e = " << el->eta() << "|" << el->phi() << "|" << el->pt() << "|" << el->e() << std::endl;
177 if (not el->caloCluster()) {
178 std::cout << "ERROR: particle has no calocluster" << std::endl;
179 continue;
180 }
181 std::cout << "raw E = " << el->caloCluster()->energyBE(1) + el->caloCluster()->energyBE(2) + el->caloCluster()->energyBE(3) << std::endl;
183 std::cout << "particle is not electron of photon" << std::endl;
184 continue;
185 }
186
187 CHECK (tool->applyCorrection(*el));
188 std::cout << "Calibrated e = " << el->e() << std::endl;
189
190 //systematics
191 std::cout << "\n=============SYSTEMATICS CHECK NOW";
192 for (auto sys : sysList) {
193 // Tell the calibration tool which variation to apply
194 if (tool->applySystematicVariation(sys) != StatusCode::SUCCESS) {
195 Error(APP_NAME, "Cannot configure calibration tool for systematics");
196 }
197
198 CHECK(tool->applyCorrection(*el));
199 std::cout << "\nCalibrated pt with systematic " << sys.name() << " = " << el->pt();
200 }
201 std::cout << "\n=============END SYSTEMATICS " << std::endl;
202 }
203
204 Info( APP_NAME,
205 "===>>> done processing event #%i, "
206 "run #%i %i events processed so far <<<===",
207 static_cast< int >( event_info->eventNumber() ),
208 static_cast< int >( event_info->runNumber() ),
209 static_cast< int >( entry + 1 ) );
210
211 }
212
214
215 return 0;
216}
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
This module implements the central registry for handling systematic uncertainties with CP tools.
const SystematicSet & recommendedSystematics() const
returns: the recommended set of systematics
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Class to wrap a set of SystematicVariations.
size_t size() const
returns: size of the set
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
Definition Egamma_v1.cxx:76
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
virtual double e() const override final
The total energy of the particle.
Definition Photon_v1.cxx:46
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
double entries
Definition listroot.cxx:49
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16
@ Info
Definition ZDCMsg.h:20
static StatusCode setProperty(IAsgTool *tool, const std::string &property, W &&value)
Helper method for calling setProperty on an interface class Usage: asg::setProperty( myTool ,...
Definition SetProperty.h:19
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".
#define CHECK(ARG)
const double MIN_PT

Variable Documentation

◆ MIN_PT

const double MIN_PT = 20E3

Definition at line 55 of file testEgammaCalibTool.cxx.