ATLAS Offline Software
CalibratedTracksProvider.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Local include(s):
7 
9 #include "xAODCore/ShallowCopy.h"
10 
11 namespace CP {
12 
13  CalibratedTracksProvider::CalibratedTracksProvider(const std::string& name, ISvcLocator* svcLoc) : AthAlgorithm(name, svcLoc) {}
14 
20  ATH_CHECK(m_tool.retrieve());
21  return StatusCode::SUCCESS;
22  }
23 
25  const EventContext& ctx = Gaudi::Hive::currentContext();
27  if (!tracks.isValid()) {
28  ATH_MSG_FATAL("No muon container found");
29  return StatusCode::FAILURE;
30  }
31 
32  std::pair<std::unique_ptr<xAOD::TrackParticleContainer>, std::unique_ptr<xAOD::ShallowAuxContainer>> output =
33  xAOD::shallowCopyContainer(*tracks, ctx);
34 
35  if (!output.first || !output.second) {
36  ATH_MSG_FATAL("Creation of shallow copy failed");
37  return StatusCode::FAILURE;
38  }
39 
40  if (!setOriginalObjectLink(*tracks, *output.first)) {
41  ATH_MSG_ERROR("Failed to add original object links to shallow copy of " << m_inputKey);
42  return StatusCode::FAILURE;
43  }
44 
45  for (xAOD::TrackParticle* iParticle : *(output.first)) {
46  ATH_MSG_VERBOSE("Old pt=" << iParticle->pt());
47  if (m_tool->applyCorrectionTrkOnly(*iParticle, m_detType).code() == CorrectionCode::Error) return StatusCode::FAILURE;
48  ATH_MSG_VERBOSE("New pt=" << iParticle->pt());
49  }
51  ATH_CHECK(writeHandle.recordNonConst(std::move(output.first), std::move(output.second)));
52 
53  // Return gracefully:
54  return StatusCode::SUCCESS;
55  }
56 
57 } // namespace CP
ShallowCopy.h
CP::CalibratedTracksProvider::m_tool
ToolHandle< IMuonCalibrationAndSmearingTool > m_tool
Calibration tool handle.
Definition: CalibratedTracksProvider.h:43
CP::CalibratedTracksProvider::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: CalibratedTracksProvider.cxx:15
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CalibratedTracksProvider.h
CP::CalibratedTracksProvider::CalibratedTracksProvider
CalibratedTracksProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: CalibratedTracksProvider.cxx:13
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CP::CalibratedTracksProvider::m_inputKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputKey
track container
Definition: CalibratedTracksProvider.h:36
CP::CalibratedTracksProvider::m_useRndNumber
Gaudi::Property< bool > m_useRndNumber
Definition: CalibratedTracksProvider.h:49
CP::CalibratedTracksProvider::m_outputKey
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_outputKey
Definition: CalibratedTracksProvider.h:39
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::CalibratedTracksProvider::m_detType
Gaudi::Property< int > m_detType
detector type of track (MS or ID)
Definition: CalibratedTracksProvider.h:46
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
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
CP::CalibratedTracksProvider::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition: CalibratedTracksProvider.h:33
CP::CalibratedTracksProvider::execute
virtual StatusCode execute() override
Function executing the algorithm.
Definition: CalibratedTracksProvider.cxx:24
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
IParticleHelpers.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
CP::CalibratedTracksProvider::m_rndNumKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_rndNumKey
Definition: CalibratedTracksProvider.h:50