ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
ElectronPhotonFourMomentumCorrection
src
CalibratedEgammaProvider.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
8
9
// local include
10
#include "
CalibratedEgammaProvider.h
"
11
12
#include "
xAODBase/IParticleHelpers.h
"
13
14
#include "Gaudi/Interfaces/IOptionsSvc.h"
15
16
namespace
CP
{
17
18
CalibratedEgammaProvider::CalibratedEgammaProvider
(
const
std::string&
name
, ISvcLocator* svcLoc )
19
:
AthAlgorithm
(
name
, svcLoc ) { }
20
21
StatusCode
CalibratedEgammaProvider::initialize
() {
22
ATH_MSG_INFO
(
"Initialising..."
);
23
ATH_CHECK
(
m_evtInfoKey
.initialize());
24
ATH_CHECK
(
m_inputKey
.initialize());
25
ATH_CHECK
(
m_outputKey
.initialize());
26
if
(
m_tool
.empty()) {
//set up a default tool with the es2012c calibration
27
m_tool
.setTypeAndName(
"CP::EgammaCalibrationAndSmearingTool/AutoConfiguredEgammaCalibTool"
);
28
ServiceHandle<Gaudi::Interfaces::IOptionsSvc>
josvc(
"JobOptionsSvc"
,
name
());
29
josvc->set(
"ToolSvc.AutoConfiguredEgammaCalibTool.esModel"
,
"es2012c"
);
30
}
31
ATH_CHECK
(
m_tool
.retrieve());
32
33
return
StatusCode::SUCCESS;
34
}
35
36
StatusCode
CalibratedEgammaProvider::execute
(
const
EventContext& ctx) {
37
38
SG::ReadHandle<xAOD::EventInfo>
event_info{
m_evtInfoKey
,ctx};
39
if
(!event_info.
isValid
()) {
40
ATH_MSG_FATAL
(
"Failed to retrieve the event info "
<<
m_evtInfoKey
.fullKey());
41
}
42
43
SG::ReadHandle<xAOD::EgammaContainer>
readHandle{
m_inputKey
, ctx};
44
if
(!readHandle.
isValid
()) {
45
ATH_MSG_FATAL
(
"No Egamma container found"
);
46
return
StatusCode::FAILURE;
47
}
48
const
xAOD::EgammaContainer
*
egamma
{readHandle.
cptr
()};
49
const
xAOD::ElectronContainer
* electrons =
dynamic_cast<
const
xAOD::ElectronContainer
*
>
(
egamma
);
50
const
xAOD::PhotonContainer
* photons =
dynamic_cast<
const
xAOD::PhotonContainer
*
>
(
egamma
);
51
xAOD::EgammaContainer
* outcontainer{
nullptr
};
52
if
(electrons) {
53
xAOD::ShallowCopyResult_t<xAOD::ElectronContainer>
output =
xAOD::shallowCopy
(*electrons, ctx);
54
if
(!output.first || !output.second) {
55
ATH_MSG_FATAL
(
"Creation of shallow copy failed"
);
56
return
StatusCode::FAILURE;
57
}
58
outcontainer = output.first.get();
59
SG::WriteHandle<xAOD::EgammaContainer>
writeHandle{
m_outputKey
, ctx};
60
ATH_CHECK
(writeHandle.
recordNonConst
(std::move(output.first), std::move(output.second)));
61
62
}
else
if
(photons) {
63
xAOD::ShallowCopyResult_t<xAOD::PhotonContainer>
output =
xAOD::shallowCopy
(*photons, ctx);
64
if
(!output.first || !output.second) {
65
ATH_MSG_FATAL
(
"Creation of shallow copy failed"
);
66
return
StatusCode::FAILURE;
67
}
68
outcontainer = output.first.get();
69
SG::WriteHandle<xAOD::EgammaContainer>
writeHandle{
m_outputKey
, ctx};
70
ATH_CHECK
(writeHandle.
recordNonConst
(std::move(output.first), std::move(output.second)));
71
}
else
{
72
ATH_MSG_FATAL
(
"Unknown Egamma container "
<<
m_inputKey
.fullKey());
73
return
StatusCode::FAILURE;
74
}
75
if
(!
setOriginalObjectLink
(*
egamma
, *outcontainer)) {
76
ATH_MSG_ERROR
(
"Failed to add original object links to shallow copy of "
<<
m_inputKey
);
77
return
StatusCode::FAILURE;
78
}
79
80
for
(
xAOD::Egamma
* iParticle : *outcontainer) {
81
ATH_MSG_VERBOSE
(
" Old pt="
<< iParticle->pt());
82
if
(
m_tool
->applyCorrection(*iParticle).code()==
CorrectionCode::Error
)
return
StatusCode::FAILURE;
83
ATH_MSG_VERBOSE
(
" New pt="
<< iParticle->pt());
84
}
85
return
StatusCode::SUCCESS;
86
}
87
88
}
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_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
CalibratedEgammaProvider.h
IParticleHelpers.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
CP::CalibratedEgammaProvider::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition
CalibratedEgammaProvider.cxx:21
CP::CalibratedEgammaProvider::CalibratedEgammaProvider
CalibratedEgammaProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition
CalibratedEgammaProvider.cxx:18
CP::CalibratedEgammaProvider::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition
CalibratedEgammaProvider.h:39
CP::CalibratedEgammaProvider::m_inputKey
SG::ReadHandleKey< xAOD::EgammaContainer > m_inputKey
Definition
CalibratedEgammaProvider.h:40
CP::CalibratedEgammaProvider::m_tool
ToolHandle< CP::IEgammaCalibrationAndSmearingTool > m_tool
Definition
CalibratedEgammaProvider.h:42
CP::CalibratedEgammaProvider::execute
virtual StatusCode execute(const EventContext &ctx)
Function executing the algorithm.
Definition
CalibratedEgammaProvider.cxx:36
CP::CalibratedEgammaProvider::m_outputKey
SG::WriteHandleKey< xAOD::EgammaContainer > m_outputKey
Definition
CalibratedEgammaProvider.h:41
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition
CorrectionCode.h:36
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::recordNonConst
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
ServiceHandle
Definition
ClusterMakerTool.h:36
egamma
elec/gamma data class.
Definition
egamma.h:59
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
xAOD::ShallowCopyResult_t
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition
ShallowCopy.h:68
xAOD::name
name
Definition
TriggerMenuJson_v1.cxx:29
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::shallowCopy
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
xAOD::Egamma
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition
Egamma.h:17
xAOD::setOriginalObjectLink
bool setOriginalObjectLink(const IParticle &original, IParticle ©)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Definition
IParticleHelpers.cxx:30
xAOD::EgammaContainer
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
Definition
EgammaContainer.h:17
Generated on
for ATLAS Offline Software by
1.17.0