ATLAS Offline Software
CalibratedMuonsProvider.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 // Local include(s):
6 
8 #include "xAODCore/ShallowCopy.h"
9 
10 namespace CP {
11 
12  CalibratedMuonsProvider::CalibratedMuonsProvider(const std::string& name, ISvcLocator* svcLoc) : AthAlgorithm(name, svcLoc) {}
13 
16  ATH_CHECK(m_inputKey.initialize());
17  ATH_CHECK(m_outputKey.initialize());
19  m_ptDecorKeys.emplace_back(m_outputKey.key() + ".InnerDetectorPt");
20  m_ptDecorKeys.emplace_back(m_outputKey.key() + ".MuonSpectrometerPt");
21  ATH_CHECK(m_ptDecorKeys.initialize());
23  ATH_CHECK(m_tool.retrieve());
24  return StatusCode::SUCCESS;
25  }
26 
28  const EventContext& ctx = Gaudi::Hive::currentContext();
30  if (!muons.isValid()) {
31  ATH_MSG_FATAL("No muon container found");
32  return StatusCode::FAILURE;
33  }
34 
35  std::pair<std::unique_ptr<xAOD::MuonContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> output =
36  xAOD::shallowCopyContainer(*muons, ctx);
37 
38  if (!output.first || !output.second) {
39  ATH_MSG_FATAL("Creation of shallow copy failed");
40  return StatusCode::FAILURE;
41  }
42 
43  if (!setOriginalObjectLink(*muons, *output.first)) {
44  ATH_MSG_ERROR("Failed to add original object links to shallow copy of " << m_inputKey);
45  return StatusCode::FAILURE;
46  }
47  for (xAOD::Muon* iParticle : *(output.first)) {
48  ATH_MSG_DEBUG(" Old pt=" << iParticle->pt());
49  if (m_tool->applyCorrection(*iParticle).code() == CorrectionCode::Error) return StatusCode::FAILURE;
50  ATH_MSG_DEBUG(" New pt=" << iParticle->pt());
51  }
53  ATH_CHECK(writeHandle.recordNonConst(std::move(output.first), std::move(output.second)));
54  // Return gracefully:
55  return StatusCode::SUCCESS;
56  }
57 
58 } // namespace CP
ShallowCopy.h
CP::CalibratedMuonsProvider::m_tool
ToolHandle< IMuonCalibrationAndSmearingTool > m_tool
Muon calibration tool.
Definition: CalibratedMuonsProvider.h:41
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CP::CalibratedMuonsProvider::CalibratedMuonsProvider
CalibratedMuonsProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: CalibratedMuonsProvider.cxx:12
CP::CalibratedMuonsProvider::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition: CalibratedMuonsProvider.h:32
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CP::CalibratedMuonsProvider::m_ptDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::MuonContainer > m_ptDecorKeys
Additionally declare the two decorations made by MCAST.
Definition: CalibratedMuonsProvider.h:38
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::CalibratedMuonsProvider::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: CalibratedMuonsProvider.cxx:14
CP::CalibratedMuonsProvider::m_rndNumKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_rndNumKey
Definition: CalibratedMuonsProvider.h:43
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::CalibratedMuonsProvider::m_outputKey
SG::WriteHandleKey< xAOD::MuonContainer > m_outputKey
Definition: CalibratedMuonsProvider.h:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CalibratedMuonsProvider.h
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
AthAlgorithm
Definition: AthAlgorithm.h:47
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::CalibratedMuonsProvider::m_useRndNumber
Gaudi::Property< bool > m_useRndNumber
Definition: CalibratedMuonsProvider.h:42
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
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
CP::CalibratedMuonsProvider::execute
virtual StatusCode execute() override
Function executing the algorithm.
Definition: CalibratedMuonsProvider.cxx:27
IParticleHelpers.h
CP::CalibratedMuonsProvider::m_inputKey
SG::ReadHandleKey< xAOD::MuonContainer > m_inputKey
muon container
Definition: CalibratedMuonsProvider.h:34