ATLAS Offline Software
Loading...
Searching...
No Matches
ScoreBasedAmbiguityResolutionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// Athena
10
11// ACTS
12#include <fstream>
13#include <iostream>
14#include <vector>
15
16#include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp"
17#include "Acts/Definitions/Units.hpp"
18#include "Acts/EventData/VectorMultiTrajectory.hpp"
19#include "Acts/EventData/VectorTrackContainer.hpp"
20#include "ActsPlugins/Json/AmbiguityConfigJsonConverter.hpp"
21#include "Acts/Utilities/Logger.hpp"
22#include "ActsInterop/Logger.h"
27
29
30
31namespace ActsTrk {
32
34 {
35 Acts::ScoreBasedAmbiguityResolution::Config cfg;
36 Acts::ConfigPair configPair;
37 nlohmann::json json_file;
38
39 std::string fileName = PathResolver::find_file(
40 "ActsConfig/ActsAmbiguityConfig.json", "DATAPATH");
41
42 std::ifstream file(fileName.c_str());
43 if (!file.is_open()) {
44 std::cerr << "Error opening file: " << fileName << std::endl;
45 return {};
46 }
47 file >> json_file;
48 file.close();
49
50 Acts::from_json(json_file, configPair);
51
52 cfg.volumeMap = configPair.first;
53 cfg.detectorConfigs = configPair.second;
54 cfg.minScore = m_minScore;
55 cfg.minScoreSharedTracks = m_minScoreSharedTracks;
56 cfg.maxSharedTracksPerMeasurement = m_maxSharedTracksPerMeasurement;
57 cfg.maxShared = m_maxShared;
58 cfg.minUnshared = m_minUnshared;
59 cfg.useAmbiguityScoring = m_useAmbiguityScoring;
60
61 m_ambi = std::make_unique<Acts::ScoreBasedAmbiguityResolution>(
62 std::move(cfg), makeActsAthenaLogger(this, "Acts"));
63 assert(m_ambi);
64 }
65
66 ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
67 ATH_CHECK(m_tracksKey.initialize());
68 ATH_CHECK(m_resolvedTracksKey.initialize());
69
70 return StatusCode::SUCCESS;
71}
72
74 ATH_MSG_INFO("Score-based Ambiguity Resolution statistics" << std::endl
75 << makeTable(m_stat,
76 std::array<std::string, kNStat>{
77 "Input tracks",
78 "Resolved tracks",
79 "Total shared hits"}).columnWidth(10));
80 return StatusCode::SUCCESS;
81}
82
84 const EventContext &ctx) const {
85 auto timer = Monitored::Timer<std::chrono::milliseconds>("TIME_execute");
86 auto mon = Monitored::Group(m_monTool, timer);
87
90 ATH_CHECK(trackHandle.isValid());
91 const ActsTrk::TrackContainer* trackContainer = trackHandle.cptr();
92 m_stat[kNInputTracks] += trackContainer->size();
93
94 // creates mutable tracks from the input tracks to add summary information
95 // NOTE: this operation likely needs to moved outside ambiguity resolution
96 auto updatedTracks =
98
99 // create the optional cuts for the ambiguity resolution
100 Acts::ScoreBasedAmbiguityResolution::Optionals<
101 typename decltype(updatedTracks)::ConstTrackProxy>
102 Optionals;
103
104 // Adding optional cuts
105 Optionals.cuts.push_back(ScoreBasedSolverCutsImpl::etaDependentCuts);
106
107 // Adding optional Score Modifiers
108 Optionals.scores.push_back(ScoreBasedSolverCutsImpl::doubleHolesScore);
109 Optionals.scores.push_back(ScoreBasedSolverCutsImpl::nSCTPixelHitsScore);
110 Optionals.scores.push_back(
112 Optionals.scores.push_back(ScoreBasedSolverCutsImpl::ContribPixelLayersScore);
113
114 // Call the ambiguity resolution algorithm with the optional cuts on the
115 // updated tracks
116 std::vector<int> goodTracks = m_ambi->solveAmbiguity(
117 updatedTracks, &detail::sourceLinkHash, &detail::sourceLinkEquality, Optionals);
118
119 ATH_MSG_DEBUG("Resolved to " << goodTracks.size() << " tracks from "
120 << updatedTracks.size());
121 m_stat[kNResolvedTracks] += goodTracks.size();
122
123
124 // we start shortlisting the container
125 Acts::VectorTrackContainer resolvedTrackBackend;
126 Acts::VectorMultiTrajectory resolvedTrackStateBackend;
127 detail::RecoTrackContainer resolvedTracksContainer(resolvedTrackBackend, resolvedTrackStateBackend);
128
129 resolvedTracksContainer.ensureDynamicColumns(updatedTracks);
130
131 detail::MeasurementIndex measurementIndex;
132 detail::SharedHitCounter sharedHits;
133
134 std::size_t totalShared = 0;
135 for (auto iTrack : goodTracks) {
136 auto destProxy = resolvedTracksContainer.getTrack(resolvedTracksContainer.addTrack());
137 destProxy.copyFrom(updatedTracks.getTrack(iTrack));
138
139 if (m_countSharedHits) {
140 auto [nShared, nBadTrackMeasurements] = sharedHits.computeSharedHitsDynamic(destProxy, resolvedTracksContainer, measurementIndex);
141 if (nBadTrackMeasurements > 0) {
142 ATH_MSG_ERROR("computeSharedHits: " << nBadTrackMeasurements << " track measurements not found in input track");
143 }
144 totalShared += nShared;
145 }
146 }
147
148 if (m_countSharedHits) {
149 ATH_MSG_DEBUG("total number of shared hits = " << totalShared);
150 m_stat[kNSharedHits] += totalShared;
151 }
152
153 // make const collection
154 Acts::ConstVectorTrackContainer storableTrackBackend( std::move(resolvedTrackBackend) );
155 Acts::ConstVectorMultiTrajectory storableTrackStateBackend( std::move(resolvedTrackStateBackend) );
156 std::unique_ptr< ActsTrk::TrackContainer > storableTracksContainer = std::make_unique< ActsTrk::TrackContainer >( std::move(storableTrackBackend),
157 std::move(storableTrackStateBackend) );
159 if (resolvedTrackHandle.record( std::move(storableTracksContainer)).isFailure()) {
160 ATH_MSG_ERROR("Failed to record resolved ACTS tracks with key " << m_resolvedTracksKey.key() );
161 return StatusCode::FAILURE;
162 }
163
164 return StatusCode::SUCCESS;
165}
166
167} // namespace ActsTrk
#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)
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:543
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
std::unique_ptr< Acts::ScoreBasedAmbiguityResolution > m_ambi
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_resolvedTracksKey
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
Group of local monitoring quantities and retain correlation when filling histograms
A monitored timer.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
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.
void innermostPixelLayerHitsScore(const trackProxy_t &track, double &score)
Score modifier for tracks based on innermost pixel layer hits.
bool etaDependentCuts(const trackProxy_t &track)
Filter for tracks based on eta dependent cuts.
void nSCTPixelHitsScore(const trackProxy_t &track, double &score)
Score modifier for tracks based on number of SCT and pixel hits.
void doubleHolesScore(const trackProxy_t &track, double &score)
Filter for tracks based on double holes.
void ContribPixelLayersScore(const trackProxy_t &track, double &score)
Score modifier for tracks based on number of contributing pixel layers.
trackContainer_t addSummaryInformation(const ActsTrk::TrackContainer &trackContainer)
Adds summary information to the track container.
bool sourceLinkEquality(const Acts::SourceLink &a, const Acts::SourceLink &b)
Returns whether two source links are equal.
std::size_t sourceLinkHash(const Acts::SourceLink &sl)
Calculates the source link hash which is evaluated to be the identifier of the underlying sourcelink.
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TFile * file