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"
20 #include "ActsInterop/TableUtils.h"
22 
25 #include "src/detail/Definitions.h"
26 
27 namespace {
28  static std::size_t sourceLinkHash(const Acts::SourceLink& slink) {
29  const ActsTrk::ATLASUncalibSourceLink &atlasSourceLink = slink.get<ActsTrk::ATLASUncalibSourceLink>();
30  const xAOD::UncalibratedMeasurement &uncalibMeas = ActsTrk::getUncalibratedMeasurement(atlasSourceLink);
31  return uncalibMeas.identifier();
32  }
33 
34  static bool sourceLinkEquality(const Acts::SourceLink& a, const Acts::SourceLink& b) {
37 
38  return uncalibMeas_a.identifier() == uncalibMeas_b.identifier();
39  }
40 }
41 
42 namespace ActsTrk
43 {
44 
46  ISvcLocator *pSvcLocator)
47  : AthReentrantAlgorithm(name, pSvcLocator)
48  {
49  }
50 
52  {
53  {
54  Acts::GreedyAmbiguityResolution::Config cfg;
55  cfg.maximumSharedHits = m_maximumSharedHits;
56  cfg.maximumIterations = m_maximumIterations;
57  cfg.nMeasurementsMin = m_nMeasurementsMin;
58  m_ambi = std::make_unique<Acts::GreedyAmbiguityResolution>(std::move(cfg), makeActsAthenaLogger(this, "Acts") ) ;
59  assert( m_ambi );
60  }
61 
62  ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
65  return StatusCode::SUCCESS;
66  }
67 
69  ATH_MSG_INFO("Ambiguity Resolution statistics" << std::endl
70  << makeTable(m_stat,
71  std::array<std::string, kNStat>{
72  "Input tracks",
73  "Resolved tracks",
74  "Total shared hits"}).columnWidth(10));
75  return StatusCode::SUCCESS;
76  }
77 
78  StatusCode AmbiguityResolutionAlg::execute(const EventContext &ctx) const
79  {
80  auto timer = Monitored::Timer<std::chrono::milliseconds>( "TIME_execute" );
82 
84  ATH_CHECK(trackHandle.isValid());
85  const ActsTrk::TrackContainer* trackContainer = trackHandle.cptr();
86  m_stat[kNInputTracks] += trackContainer->size();
87 
89  m_ambi->computeInitialState(*trackContainer, state, &sourceLinkHash,
90  &sourceLinkEquality);
91 
92  m_ambi->resolve(state);
93 
94  ATH_MSG_DEBUG("Resolved to " << state.selectedTracks.size() << " tracks from "
95  << trackContainer->size());
96  m_stat[kNResolvedTracks] += state.selectedTracks.size();
97 
98 
99  // we start shortlisting the container
100  Acts::VectorTrackContainer resolvedTrackBackend;
101  Acts::VectorMultiTrajectory resolvedTrackStateBackend;
102  detail::RecoTrackContainer resolvedTracksContainer(resolvedTrackBackend, resolvedTrackStateBackend);
103 
104  // need centralized function here
105  resolvedTracksContainer.ensureDynamicColumns(*trackContainer);
106 
107  detail::MeasurementIndex measurementIndex;
108  detail::SharedHitCounter sharedHits;
109 
110  std::size_t totalShared = 0;
111  for (auto iTrack : state.selectedTracks) {
112  auto destProxy = resolvedTracksContainer.getTrack(resolvedTracksContainer.addTrack());
113  destProxy.copyFrom(trackHandle->getTrack(state.trackTips.at(iTrack)));
114 
115  if (m_countSharedHits) {
116  auto [nShared, nBadTrackMeasurements] = sharedHits.computeSharedHitsDynamic(destProxy, resolvedTracksContainer, measurementIndex);
117  if (nBadTrackMeasurements > 0)
118  ATH_MSG_ERROR("computeSharedHits: " << nBadTrackMeasurements << " track measurements not found in input track");
119  totalShared += nShared;
120  }
121  }
122 
123  if (m_countSharedHits) {
124  ATH_MSG_DEBUG("total number of shared hits = " << totalShared);
125  m_stat[kNSharedHits] += totalShared;
126  }
127 
128  // make const collection
129  Acts::ConstVectorTrackContainer storableTrackBackend( std::move(resolvedTrackBackend) );
130  Acts::ConstVectorMultiTrajectory storableTrackStateBackend( std::move(resolvedTrackStateBackend) );
131  std::unique_ptr< ActsTrk::TrackContainer > storableTracksContainer = std::make_unique< ActsTrk::TrackContainer >( std::move(storableTrackBackend),
132  std::move(storableTrackStateBackend) );
134  if (resolvedTrackHandle.record( std::move(storableTracksContainer)).isFailure()) {
135  ATH_MSG_ERROR("Failed to record resolved ACTS tracks with key " << m_resolvedTracksKey.key() );
136  return StatusCode::FAILURE;
137  }
138 
139  return StatusCode::SUCCESS;
140  }
141 
142 } // namespace
xAOD::UncalibratedMeasurement_v1::identifier
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
ActsTrk::AmbiguityResolutionAlg::m_countSharedHits
Gaudi::Property< bool > m_countSharedHits
Definition: AmbiguityResolutionAlg.h:62
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
ActsTrk::TrackContainer
Definition: TrackContainer.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Definitions.h
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
ActsTrk::AmbiguityResolutionAlg::kNSharedHits
@ kNSharedHits
Definition: AmbiguityResolutionAlg.h:70
AmbiguityResolutionAlg.h
ActsTrk::AmbiguityResolutionAlg::m_maximumIterations
Gaudi::Property< unsigned int > m_maximumIterations
Definition: AmbiguityResolutionAlg.h:59
ActsTrk::detail::SharedHitCounter
Definition: SharedHitCounter.h:19
ActsTrk::AmbiguityResolutionAlg::finalize
virtual StatusCode finalize() override
Definition: AmbiguityResolutionAlg.cxx:68
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ActsTrk::detail::MeasurementIndex
Definition: MeasurementIndex.h:16
SharedHitCounter.h
ActsTrk::detail::RecoTrackContainer
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
Definition: Tracking/Acts/ActsTrackReconstruction/src/detail/Definitions.h:22
MeasurementIndex.h
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:85
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
ActsTrk::AmbiguityResolutionAlg::m_ambi
std::unique_ptr< Acts::GreedyAmbiguityResolution > m_ambi
Definition: AmbiguityResolutionAlg.h:64
ActsTrk::detail::SharedHitCounter::computeSharedHitsDynamic
auto computeSharedHitsDynamic(typename track_container_t::TrackProxy &track, track_container_t &tracks, MeasurementIndex &measurementIndex, bool removeSharedHits=false) -> ReturnSharedAndBad
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
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
makeTable
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition: TableUtils.h:523
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:33
ActsTrk::AmbiguityResolutionAlg::m_nMeasurementsMin
Gaudi::Property< unsigned int > m_nMeasurementsMin
Definition: AmbiguityResolutionAlg.h:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsTrk::AmbiguityResolutionAlg::initialize
virtual StatusCode initialize() override
Definition: AmbiguityResolutionAlg.cxx:51
python.TrackLeptonConfig.trackContainer
string trackContainer
Definition: TrackLeptonConfig.py:23
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:45
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:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
ActsTrk::AmbiguityResolutionAlg::m_maximumSharedHits
Gaudi::Property< unsigned int > m_maximumSharedHits
Definition: AmbiguityResolutionAlg.h:57
ActsTrk::getUncalibratedMeasurement
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
Definition: ATLASSourceLink.h:26
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
ActsTrk::AmbiguityResolutionAlg::m_resolvedTracksKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_resolvedTracksKey
Definition: AmbiguityResolutionAlg.h:54
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
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:66
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
TableUtils.h
ActsTrk::AmbiguityResolutionAlg::m_tracksKey
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
Definition: AmbiguityResolutionAlg.h:52
ActsTrk::AmbiguityResolutionAlg::kNInputTracks
@ kNInputTracks
Definition: AmbiguityResolutionAlg.h:68
Logger.h
ActsTrk::AmbiguityResolutionAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: AmbiguityResolutionAlg.cxx:78
ActsTrk::AmbiguityResolutionAlg::kNResolvedTracks
@ kNResolvedTracks
Definition: AmbiguityResolutionAlg.h:69
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32