ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
ElectronPhotonFourMomentumCorrection
src
testAthenaEgammaCalibTool.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
// EDM include(s):
6
7
#include "
xAODEgamma/ElectronContainer.h
"
8
#include "
xAODEgamma/PhotonContainer.h
"
9
#include "
xAODEgamma/Egamma.h
"
10
#include "
xAODCaloEvent/CaloCluster.h
"
11
#include "
xAODEventInfo/EventInfo.h
"
12
#include "
xAODCore/ShallowCopy.h
"
13
#include "
PATInterfaces/SystematicVariation.h
"
14
#include "
PATInterfaces/SystematicRegistry.h
"
15
#include "
AsgMessaging/StatusCode.h
"
16
#include "
ElectronPhotonFourMomentumCorrection/EgammaCalibrationAndSmearingTool.h
"
17
#include "TString.h"
18
// local include
19
#include "
testAthenaEgammaCalibTool.h
"
20
21
testAthenaEgammaCalibTool::testAthenaEgammaCalibTool
(
const
std::string& name, ISvcLocator* svcLoc )
22
:
AthAlgorithm
( name, svcLoc ),
23
m_EgammaCalibrationAndSmearingTool
(
"CP::EgammaCalibrationAndSmearingTool/EgammaCalibrationAndSmearingTool"
, this)
24
{
25
declareProperty
(
"SG_Electrons"
,
m_sg_electrons
=
"Electrons"
);
26
declareProperty
(
"EgammaCalibrationAndSmearingTool"
,
m_EgammaCalibrationAndSmearingTool
);
27
}
28
29
30
StatusCode
testAthenaEgammaCalibTool::initialize
()
31
{
32
// Greet the user:
33
ATH_MSG_INFO
(
"Initialising..."
);
34
35
// Retrieve the tools:
36
ATH_CHECK
(
m_EgammaCalibrationAndSmearingTool
.retrieve());
37
38
return
StatusCode::SUCCESS;
39
}
40
41
42
StatusCode
testAthenaEgammaCalibTool::execute
(
const
EventContext&
/*ctx*/
)
43
{
44
const
xAOD::EventInfo
* event_info =
nullptr
;
45
ATH_CHECK
(
evtStore
()->retrieve( event_info) );
46
47
const
xAOD::ElectronContainer
* electrons;
48
ATH_CHECK
(
evtStore
()->retrieve(electrons,
m_sg_electrons
) );
49
50
//Clone
51
xAOD::ShallowCopyResult_t<xAOD::ElectronContainer>
electrons_shallowCopy =
xAOD::shallowCopy
( *electrons );
52
xAOD::ElectronContainer
* elsCorr = electrons_shallowCopy.first.get();
53
//Record in StoreGate
54
CHECK
(
evtStore
()->record( std::move(electrons_shallowCopy.first),
"ElectronCollectionCorr"
) );
55
CHECK
(
evtStore
()->record( std::move(electrons_shallowCopy.second),
"ElectronCollectionCorrAux."
) );
56
57
//===========SYSTEMATICS
58
const
CP::SystematicRegistry
& registry =
CP::SystematicRegistry::getInstance
();
59
const
CP::SystematicSet
& recommendedSystematics = registry.recommendedSystematics();
60
std::vector<CP::SystematicSet> sysList;
61
// this is the nominal set
62
sysList.emplace_back();
63
64
ATH_MSG_INFO
(
"SIZE of the systematics set:"
<< recommendedSystematics.
size
());
65
66
for
(
const
auto
& recommendedSystematic : recommendedSystematics)
67
{
68
sysList.emplace_back();
69
sysList.back().insert(recommendedSystematic);
70
}
71
72
std::vector<CP::SystematicSet>::const_iterator sysListItr;
73
74
//Iterate over the shallow copy
75
xAOD::ElectronContainer::iterator
el_it = elsCorr->
begin
();
76
xAOD::ElectronContainer::iterator
el_it_last = elsCorr->
end
();
77
unsigned
int
i = 0;
78
for
(; el_it != el_it_last; ++el_it, ++i) {
79
xAOD::Electron
* el = *el_it;
80
ATH_MSG_INFO
(
"Electron "
<< i);
81
ATH_MSG_INFO
(
"xAOD/raw pt, eta, phi = "
<< el->pt() <<
", "
<< el->eta() <<
", "
<< el->phi());
82
83
if
(
m_EgammaCalibrationAndSmearingTool
->applyCorrection(*el) !=
CP::CorrectionCode::Ok
){
84
ATH_MSG_WARNING
(
"Cannot calibrate electron"
);
85
}
86
ATH_MSG_INFO
(
"Calibrated pt = "
<< el->pt());
87
88
//systematics
89
ATH_MSG_INFO
(
"=============SYSTEMATICS CHECK NOW"
);
90
for
(sysListItr = sysList.begin(); sysListItr != sysList.end(); ++sysListItr)
91
{
92
// Tell the calibration tool which variation to apply
93
if
(
m_EgammaCalibrationAndSmearingTool
->applySystematicVariation(*sysListItr) != StatusCode::SUCCESS)
94
{
95
ATH_MSG_ERROR
(
"Cannot configure calibration tool for systematics"
);
96
}
97
//For now remove by hand the photon ones
98
TString syst_name = TString(sysListItr->name());
99
if
(!syst_name.BeginsWith(
"EL"
) && !syst_name.BeginsWith(
"EG"
))
continue
;
100
101
if
(
m_EgammaCalibrationAndSmearingTool
->applyCorrection(*el) !=
CP::CorrectionCode::Ok
){
102
ATH_MSG_WARNING
(
"Cannot calibrate electron"
);
103
}
104
105
ATH_MSG_INFO
(
"Calibrated pt with systematic "
<< syst_name <<
" = "
<< el->pt());
106
}
107
ATH_MSG_INFO
(
"=============END SYSTEMATICS "
);
108
}
109
110
//test the correctedCopy method
111
for
(; el_it != el_it_last; ++el_it) {
112
xAOD::Electron
*copy_el =
nullptr
;
// new object
113
if
(
m_EgammaCalibrationAndSmearingTool
->correctedCopy( **el_it, copy_el) !=
CP::CorrectionCode::Ok
){
114
ATH_MSG_WARNING
(
"Could not apply correction to new electron object"
);
115
continue
;
116
}
117
}
118
119
return
StatusCode::SUCCESS;
120
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
StatusCode.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
EgammaCalibrationAndSmearingTool.h
Egamma.h
CaloCluster.h
ElectronContainer.h
PhotonContainer.h
ShallowCopy.h
SystematicRegistry.h
SystematicVariation.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition
CorrectionCode.h:38
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition
SystematicRegistry.h:25
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition
SystematicRegistry.cxx:25
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition
SystematicSet.h:31
CP::SystematicSet::size
size_t size() const
returns: size of the set
Definition
SystematicSet.h:71
DataVector< xAOD::Electron_v1 >::iterator
DataModel_detail::iterator< DataVector > iterator
Definition
DataVector.h:842
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
testAthenaEgammaCalibTool::m_sg_electrons
std::string m_sg_electrons
Definition
testAthenaEgammaCalibTool.h:29
testAthenaEgammaCalibTool::m_EgammaCalibrationAndSmearingTool
ToolHandle< CP::IEgammaCalibrationAndSmearingTool > m_EgammaCalibrationAndSmearingTool
Definition
testAthenaEgammaCalibTool.h:31
testAthenaEgammaCalibTool::execute
virtual StatusCode execute(const EventContext &ctx)
Function executing the algorithm.
Definition
testAthenaEgammaCalibTool.cxx:42
testAthenaEgammaCalibTool::testAthenaEgammaCalibTool
testAthenaEgammaCalibTool(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition
testAthenaEgammaCalibTool.cxx:21
testAthenaEgammaCalibTool::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition
testAthenaEgammaCalibTool.cxx:30
xAOD::ShallowCopyResult_t
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition
ShallowCopy.h:68
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
xAOD::shallowCopy
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
testAthenaEgammaCalibTool.h
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0