ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
10namespace CP {
11
12 CalibratedMuonsProvider::CalibratedMuonsProvider(const std::string& name, ISvcLocator* svcLoc) : AthAlgorithm(name, svcLoc) {}
13
15 ATH_CHECK(m_eventInfo.initialize());
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual StatusCode initialize() override
Function initialising the algorithm.
ToolHandle< IMuonCalibrationAndSmearingTool > m_tool
Muon calibration tool.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Gaudi::Property< bool > m_useRndNumber
SG::ReadHandleKey< xAOD::MuonContainer > m_inputKey
muon container
CalibratedMuonsProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
SG::WriteHandleKey< xAOD::MuonContainer > m_outputKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_rndNumKey
SG::WriteDecorHandleKeyArray< xAOD::MuonContainer > m_ptDecorKeys
Additionally declare the two decorations made by MCAST.
virtual StatusCode execute() override
Function executing the algorithm.
@ Error
Some error happened during the object correction.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
Select isolated Photons, Electrons and Muons.
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.
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...
Muon_v1 Muon
Reference the current persistent version: