ATLAS Offline Software
Loading...
Searching...
No Matches
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
10
11namespace CP {
12
13 CalibratedTracksProvider::CalibratedTracksProvider(const std::string& name, ISvcLocator* svcLoc) : AthAlgorithm(name, svcLoc) {}
14
16 ATH_CHECK(m_eventInfo.initialize());
17 ATH_CHECK(m_inputKey.initialize());
18 ATH_CHECK(m_outputKey.initialize());
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Property< bool > m_useRndNumber
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
ToolHandle< IMuonCalibrationAndSmearingTool > m_tool
Calibration tool handle.
SG::ReadDecorHandleKey< xAOD::EventInfo > m_rndNumKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputKey
track container
Gaudi::Property< int > m_detType
detector type of track (MS or ID)
virtual StatusCode initialize() override
Function initialising the algorithm.
CalibratedTracksProvider(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_outputKey
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.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
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...