ATLAS Offline Software
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 
16 namespace CP {
17 
18 CalibratedEgammaProvider::CalibratedEgammaProvider( const std::string& name, ISvcLocator* svcLoc )
19  : AthAlgorithm( name, svcLoc ) { }
20 
22  ATH_MSG_INFO( "Initialising..." );
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 
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 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
CP::CalibratedEgammaProvider::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: CalibratedEgammaProvider.cxx:36
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
egamma
Definition: egamma.h:58
CP::CalibratedEgammaProvider::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition: CalibratedEgammaProvider.h:39
CP::CalibratedEgammaProvider::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: CalibratedEgammaProvider.cxx:21
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
CP::CalibratedEgammaProvider::m_outputKey
SG::WriteHandleKey< xAOD::EgammaContainer > m_outputKey
Definition: CalibratedEgammaProvider.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::CalibratedEgammaProvider::m_tool
ToolHandle< CP::IEgammaCalibrationAndSmearingTool > m_tool
Definition: CalibratedEgammaProvider.h:42
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::CalibratedEgammaProvider::CalibratedEgammaProvider
CalibratedEgammaProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: CalibratedEgammaProvider.cxx:18
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
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CP::CalibratedEgammaProvider::m_inputKey
SG::ReadHandleKey< xAOD::EgammaContainer > m_inputKey
Definition: CalibratedEgammaProvider.h:40
xAOD::setOriginalObjectLink
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...
Definition: IParticleHelpers.cxx:30
IParticleHelpers.h
CalibratedEgammaProvider.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
ServiceHandle< Gaudi::Interfaces::IOptionsSvc >