ATLAS Offline Software
Loading...
Searching...
No Matches
CalibratedEgammaProvider.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5// EDM include(s):
6
7
8
9// local include
11
13
14#include "Gaudi/Interfaces/IOptionsSvc.h"
15
16namespace CP {
17
18CalibratedEgammaProvider::CalibratedEgammaProvider( const std::string& name, ISvcLocator* svcLoc )
19 : AthAlgorithm( name, svcLoc ) { }
20
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");
29 josvc->set("ToolSvc.AutoConfiguredEgammaCalibTool.esModel", "es2012c");
30 }
31 ATH_CHECK(m_tool.retrieve());
32
33 return StatusCode::SUCCESS;
34}
35
37 const EventContext& ctx = Gaudi::Hive::currentContext();
38
40 if (!event_info.isValid()) {
41 ATH_MSG_FATAL("Failed to retrieve the event info "<<m_evtInfoKey.fullKey());
42 }
43
45 if (!readHandle.isValid()) {
46 ATH_MSG_FATAL("No Egamma container found");
47 return StatusCode::FAILURE;
48 }
49 const xAOD::EgammaContainer* egamma{readHandle.cptr()};
50 const xAOD::ElectronContainer* electrons = dynamic_cast<const xAOD::ElectronContainer*>(egamma);
51 const xAOD::PhotonContainer* photons = dynamic_cast<const xAOD::PhotonContainer*>(egamma);
52 xAOD::EgammaContainer* outcontainer{nullptr};
53 if (electrons) {
54 std::pair<std::unique_ptr<xAOD::ElectronContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> output = xAOD::shallowCopyContainer(*electrons, ctx);
55 if (!output.first || !output.second) {
56 ATH_MSG_FATAL("Creation of shallow copy failed");
57 return StatusCode::FAILURE;
58 }
59 outcontainer = output.first.get();
61 ATH_CHECK(writeHandle.recordNonConst(std::move(output.first), std::move(output.second)));
62
63 } else if (photons) {
64 std::pair<std::unique_ptr<xAOD::PhotonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> output = xAOD::shallowCopyContainer(*photons, ctx);
65 if (!output.first || !output.second) {
66 ATH_MSG_FATAL("Creation of shallow copy failed");
67 return StatusCode::FAILURE;
68 }
69 outcontainer = output.first.get();
71 ATH_CHECK(writeHandle.recordNonConst(std::move(output.first), std::move(output.second)));
72 } else {
73 ATH_MSG_FATAL("Unknown Egamma container "<<m_inputKey.fullKey());
74 return StatusCode::FAILURE;
75 }
76 if (!setOriginalObjectLink(*egamma, *outcontainer)) {
77 ATH_MSG_ERROR("Failed to add original object links to shallow copy of " << m_inputKey);
78 return StatusCode::FAILURE;
79 }
80
81 for(xAOD::Egamma* iParticle : *outcontainer) {
82 ATH_MSG_VERBOSE(" Old pt=" << iParticle->pt());
83 if(m_tool->applyCorrection(*iParticle).code()==CorrectionCode::Error) return StatusCode::FAILURE;
84 ATH_MSG_VERBOSE(" New pt=" << iParticle->pt());
85 }
86 return StatusCode::SUCCESS;
87}
88
89}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual StatusCode initialize()
Function initialising the algorithm.
CalibratedEgammaProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
virtual StatusCode execute()
Function executing the algorithm.
SG::ReadHandleKey< xAOD::EgammaContainer > m_inputKey
ToolHandle< CP::IEgammaCalibrationAndSmearingTool > m_tool
SG::WriteHandleKey< xAOD::EgammaContainer > m_outputKey
@ Error
Some error happened during the object correction.
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.
elec/gamma data class.
Definition egamma.h:58
Select isolated Photons, Electrons and Muons.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container 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.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".