ATLAS Offline Software
Loading...
Searching...
No Matches
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"
22
26
27namespace {
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
42namespace 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()}));
63 ATH_CHECK(m_tracksKey.initialize());
64 ATH_CHECK(m_resolvedTracksKey.initialize());
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" );
81 auto mon = Monitored::Group( m_monTool, timer );
82
84 ATH_CHECK(trackHandle.isValid());
85 const ActsTrk::TrackContainer* trackContainer = trackHandle.cptr();
86 m_stat[kNInputTracks] += trackContainer->size();
87
88 Acts::GreedyAmbiguityResolution::State state;
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t a
Header file to be included by clients of the Monitored infrastructure.
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition TableUtils.h:523
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
ToolHandle< GenericMonitoringTool > m_monTool
Gaudi::Property< unsigned int > m_maximumSharedHits
virtual StatusCode finalize() override
std::unique_ptr< Acts::GreedyAmbiguityResolution > m_ambi
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_resolvedTracksKey
Gaudi::Property< bool > m_countSharedHits
virtual StatusCode initialize() override
Gaudi::Property< unsigned int > m_maximumIterations
AmbiguityResolutionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< unsigned int > m_nMeasurementsMin
virtual StatusCode execute(const EventContext &ctx) const override
auto computeSharedHitsDynamic(typename track_container_t::TrackProxy &track, track_container_t &tracks, MeasurementIndex &measurementIndex, bool removeSharedHits=false) -> ReturnSharedAndBad
An algorithm that can be simultaneously executed in multiple threads.
Group of local monitoring quantities and retain correlation when filling histograms
A monitored timer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
const xAOD::UncalibratedMeasurement * ATLASUncalibSourceLink
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.