ATLAS Offline Software
AmbiguityResolutionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 // Athena
9 
10 // ACTS
11 #include "Acts/Definitions/Units.hpp"
12 
13 #include "Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp"
14 #include "Acts/EventData/MultiTrajectoryHelpers.hpp"
15 #include "Acts/EventData/VectorMultiTrajectory.hpp"
16 #include "Acts/EventData/VectorTrackContainer.hpp"
17 #include "Acts/Utilities/Logger.hpp"
18 
19 #include "ActsInterop/Logger.h"
21 
22 namespace {
23  std::size_t sourceLinkHash(const Acts::SourceLink& slink) {
24  const ActsTrk::ATLASUncalibSourceLink &atlasSourceLink = slink.get<ActsTrk::ATLASUncalibSourceLink>();
25  const xAOD::UncalibratedMeasurement &uncalibMeas = ActsTrk::getUncalibratedMeasurement(atlasSourceLink);
26  return uncalibMeas.identifier();
27  }
28 
29  bool sourceLinkEquality(const Acts::SourceLink& a, const Acts::SourceLink& b) {
32 
33  return uncalibMeas_a.identifier() == uncalibMeas_b.identifier();
34  }
35 }
36 
37 namespace ActsTrk
38 {
39 
41  ISvcLocator *pSvcLocator)
42  : AthReentrantAlgorithm(name, pSvcLocator)
43  {
44  }
45 
47  {
48  {
49  Acts::GreedyAmbiguityResolution::Config cfg;
50  cfg.maximumSharedHits = m_maximumSharedHits;
51  cfg.maximumIterations = m_maximumIterations;
52  cfg.nMeasurementsMin = m_nMeasurementsMin;
53  m_ambi = std::make_unique<Acts::GreedyAmbiguityResolution>(std::move(cfg), makeActsAthenaLogger(this, "Acts") ) ;
54  assert( m_ambi );
55  }
56 
57  ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
61  ATH_CHECK(m_resolvedTracksBackendHandles.initialize(ActsTrk::prefixFromTrackContainerName(m_resolvedTracksKey.key()))); //TODO choose prefix related to the output tracks name
62  return StatusCode::SUCCESS;
63  }
64 
65  StatusCode AmbiguityResolutionAlg::execute(const EventContext &ctx) const
66  {
67  auto timer = Monitored::Timer<std::chrono::milliseconds>( "TIME_execute" );
69 
71  ATH_CHECK(trackHandle.isValid());
72 
74  m_ambi->computeInitialState(*trackHandle, state, &sourceLinkHash,
75  &sourceLinkEquality);
76 
77  m_ambi->resolve(state);
78 
79  ATH_MSG_DEBUG("Resolved to " << state.selectedTracks.size() << " tracks from "
80  << trackHandle->size());
81 
82  ActsTrk::MutableTrackContainer solvedTracks;
83  solvedTracks.ensureDynamicColumns(*trackHandle);
84 
85  for (auto iTrack : state.selectedTracks) {
86  auto destProxy = solvedTracks.getTrack(solvedTracks.addTrack());
87  destProxy.copyFrom(trackHandle->getTrack(state.trackTips.at(iTrack)));
88  }
89  std::unique_ptr<ActsTrk::TrackContainer> outputTracks = m_resolvedTracksBackendHandles.moveToConst(std::move(solvedTracks),
90  m_trackingGeometryTool->getGeometryContext(ctx).context(), ctx);
92 
93  if (resolvedTrackHandle.record( std::move(outputTracks)).isFailure()) {
94  ATH_MSG_ERROR("Failed to record resolved ACTS tracks with key " << m_resolvedTracksKey.key() );
95  return StatusCode::FAILURE;
96  }
97 
98  return StatusCode::SUCCESS;
99  }
100 
101 } // namespace
xAOD::UncalibratedMeasurement_v1::identifier
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
ActsTrk::MutableTrackContainerHandlesHelper::moveToConst
std::unique_ptr< ActsTrk::TrackContainer > moveToConst(ActsTrk::MutableTrackContainer &&tc, const Acts::GeometryContext &geoContext, const EventContext &evtContext) const
produces ActsTrk::ConstTrackContainer with all backends stored in SG
Definition: TrackContainerHandlesHelper.cxx:130
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AmbiguityResolutionAlg.h
ActsTrk::AmbiguityResolutionAlg::m_maximumIterations
Gaudi::Property< unsigned int > m_maximumIterations
Definition: AmbiguityResolutionAlg.h:60
ActsTrk::prefixFromTrackContainerName
std::string prefixFromTrackContainerName(const std::string &tracks)
Parse TrackContainer name to get the prefix for backends The name has to contain XYZTracks,...
Definition: TrackContainerHandlesHelper.cxx:18
ActsTrk::AmbiguityResolutionAlg::m_resolvedTracksBackendHandles
ActsTrk::MutableTrackContainerHandlesHelper m_resolvedTracksBackendHandles
Definition: AmbiguityResolutionAlg.h:53
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ActsTrk::MutableTrackContainerHandlesHelper::initialize
StatusCode initialize(const std::string &prefix)
Sets up the handles.
Definition: TrackContainerHandlesHelper.cxx:51
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ActsTrk::AmbiguityResolutionAlg::m_ambi
std::unique_ptr< Acts::GreedyAmbiguityResolution > m_ambi
Definition: AmbiguityResolutionAlg.h:64
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
makeActsAthenaLogger
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:64
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonR4::State
CalibratedSpacePoint::State State
Definition: SpacePointCalibrator.cxx:24
ActsTrk::AmbiguityResolutionAlg::m_nMeasurementsMin
Gaudi::Property< unsigned int > m_nMeasurementsMin
Definition: AmbiguityResolutionAlg.h:62
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsTrk::AmbiguityResolutionAlg::initialize
virtual StatusCode initialize() override
Definition: AmbiguityResolutionAlg.cxx:46
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
ActsTrk::AmbiguityResolutionAlg::AmbiguityResolutionAlg
AmbiguityResolutionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AmbiguityResolutionAlg.cxx:40
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ActsTrk::AmbiguityResolutionAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: AmbiguityResolutionAlg.h:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ActsTrk::AmbiguityResolutionAlg::m_maximumSharedHits
Gaudi::Property< unsigned int > m_maximumSharedHits
Definition: AmbiguityResolutionAlg.h:58
ActsTrk::getUncalibratedMeasurement
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
Definition: ATLASSourceLink.h:26
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
ActsTrk::AmbiguityResolutionAlg::m_trackingGeometryTool
ToolHandle< IActsTrackingGeometryTool > m_trackingGeometryTool
Definition: AmbiguityResolutionAlg.h:49
ActsTrk::AmbiguityResolutionAlg::m_resolvedTracksKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_resolvedTracksKey
Definition: AmbiguityResolutionAlg.h:55
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
a
TList * a
Definition: liststreamerinfos.cxx:10
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
ActsTrk::AmbiguityResolutionAlg::m_tracksKey
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
Definition: AmbiguityResolutionAlg.h:52
Logger.h
ActsTrk::AmbiguityResolutionAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: AmbiguityResolutionAlg.cxx:65
ActsTrk::MutableTrackContainer
Definition: TrackContainer.h:122
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32