ATLAS Offline Software
Loading...
Searching...
No Matches
EGammaFudgeAlgorithm.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// local include
11
15
16namespace DerivationFramework {
17
19 ATH_CHECK(m_inputKey.initialize());
20 ATH_CHECK(m_outputKey.initialize());
21 ATH_CHECK(m_fudgeTool.retrieve());
22 return StatusCode::SUCCESS;
23 }
24
25 StatusCode EGammaFudgeAlgorithm::execute(const EventContext& ctx) const{
26
28 if (!readHandle.isValid()) {
29 ATH_MSG_FATAL("No EGamma container found");
30 return StatusCode::FAILURE;
31 }
32 const xAOD::EgammaContainer* egammas{readHandle.cptr()};
33 const xAOD::ElectronContainer* electrons = dynamic_cast<const xAOD::ElectronContainer*>(egammas);
34 const xAOD::PhotonContainer* photons = dynamic_cast<const xAOD::PhotonContainer*>(egammas);
35
36 xAOD::EgammaContainer* outcontainer{nullptr};
37 if (electrons) {
39 if (!output.first || !output.second) {
40 ATH_MSG_FATAL("Creation of shallow copy failed");
41 return StatusCode::FAILURE;
42 }
43 outcontainer = output.first.get();
45 ATH_CHECK(writeHandle.recordNonConst(std::move(output.first), std::move(output.second)));
46
47 } else if (photons) {
49 if (!output.first || !output.second) {
50 ATH_MSG_FATAL("Creation of shallow copy failed");
51 return StatusCode::FAILURE;
52 }
53 outcontainer = output.first.get();
55 ATH_CHECK(writeHandle.recordNonConst(std::move(output.first), std::move(output.second)));
56 } else {
57 ATH_MSG_FATAL("Unknown Egamma container "<<m_inputKey.fullKey());
58 return StatusCode::FAILURE;
59 }
60
61 if (!setOriginalObjectLink(*egammas, *outcontainer)) {
62 ATH_MSG_ERROR("Failed to add original object links to shallow copy of " << m_inputKey);
63 return StatusCode::FAILURE;
64 }
65
66 for(xAOD::Egamma* iParticle : *outcontainer) {
67 if (electrons) {
68 auto* electron = static_cast<xAOD::Electron*>(iParticle);
69 if(m_fudgeTool->applyCorrection(*electron)==CP::CorrectionCode::Error)
70 return StatusCode::FAILURE;
71 } else {
72 auto* photon = static_cast<xAOD::Photon*>(iParticle);
73 if (m_fudgeTool->applyCorrection(*photon) == CP::CorrectionCode::Error)
74 return StatusCode::FAILURE;
75 }
76 }
77
78 return StatusCode::SUCCESS;
79 }
80
81}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
@ Error
Some error happened during the object correction.
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeTool
virtual StatusCode initialize() override
Function initialising the algorithm.
SG::WriteHandleKey< xAOD::EgammaContainer > m_outputKey
SG::ReadHandleKey< xAOD::EgammaContainer > m_inputKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
THE reconstruction tool.
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition ShallowCopy.h:68
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
Electron_v1 Electron
Definition of the current "egamma version".