ATLAS Offline Software
Macros | Functions | Variables
testEgammaCalibTool.cxx File Reference
#include <memory>
#include <cstdlib>
#include <TFile.h>
#include <TError.h>
#include <TString.h>
#include "xAODEventInfo/EventInfo.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEgamma/PhotonContainer.h"
#include "xAODEgamma/Egamma.h"
#include "xAODEgamma/EgammaxAODHelpers.h"
#include "xAODCaloEvent/CaloCluster.h"
#include "xAODCore/ShallowCopy.h"
#include "PATInterfaces/SystematicVariation.h"
#include "PATInterfaces/SystematicRegistry.h"
#include "AsgMessaging/StatusCode.h"
#include "xAODCore/tools/IOStats.h"
#include "xAODCore/tools/ReadStats.h"
#include "ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h"

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 )

Definition at line 45 of file testEgammaCalibTool.cxx.

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 }

Variable Documentation

◆ MIN_PT

const double MIN_PT = 20E3

Definition at line 55 of file testEgammaCalibTool.cxx.

python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
RETURN_CHECK
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition: ReturnCheck.h:26
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
CP::SystematicSet::size
size_t size() const
returns: size of the set
Definition: SystematicSet.h:71
xAOD::Egamma_v1::e
virtual double e() const override final
The total energy of the particle.
Definition: Egamma_v1.cxx:90
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
CHECK
#define CHECK(ARG)
Definition: testEgammaCalibTool.cxx:44
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
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:123
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:13
xAOD::Egamma_v1::caloCluster
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
Definition: Egamma_v1.cxx:388
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
xAOD::Egamma_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
Definition: Egamma_v1.cxx:75
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
MIN_PT
const double MIN_PT
Definition: testEgammaCalibTool.cxx:55
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::EgammaCalibrationAndSmearingTool
Definition: EgammaCalibrationAndSmearingTool.h:81
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::Photon_v1
Definition: Photon_v1.h:37
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:22
xAOD::CaloCluster_v1::energyBE
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
Definition: CaloCluster_v1.cxx:630
entries
double entries
Definition: listroot.cxx:49
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31