ATLAS Offline Software
ScoreBasedAmbiguityResolutionAlg.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 
8 
9 // Athena
12 
13 // ACTS
14 #include <fstream>
15 #include <iostream>
16 #include <vector>
17 
18 #include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp"
19 #include "Acts/Definitions/Units.hpp"
20 #include "Acts/EventData/VectorMultiTrajectory.hpp"
21 #include "Acts/EventData/VectorTrackContainer.hpp"
22 #include "Acts/Plugins/Json/AmbiguityConfigJsonConverter.hpp"
23 #include "Acts/Utilities/Logger.hpp"
25 #include "ActsInterop/Logger.h"
26 
27 namespace {
28 std::size_t sourceLinkHash(const Acts::SourceLink &slink) {
29  const ActsTrk::ATLASUncalibSourceLink &atlasSourceLink =
31  const xAOD::UncalibratedMeasurement &uncalibMeas =
32  ActsTrk::getUncalibratedMeasurement(atlasSourceLink);
33  return uncalibMeas.identifier();
34 }
35 
36 bool sourceLinkEquality(const Acts::SourceLink &a, const Acts::SourceLink &b) {
37  const xAOD::UncalibratedMeasurement &uncalibMeas_a =
40  const xAOD::UncalibratedMeasurement &uncalibMeas_b =
43 
44  return uncalibMeas_a.identifier() == uncalibMeas_b.identifier();
45 }
46 
47 } // namespace
48 
49 namespace ActsTrk {
50 
52  const std::string &name, ISvcLocator *pSvcLocator)
53  : AthReentrantAlgorithm(name, pSvcLocator) {}
54 
56  {
57  Acts::ScoreBasedAmbiguityResolution::Config cfg;
58  Acts::ConfigPair configPair;
59  nlohmann::json json_file;
60 
61  std::string fileName = PathResolver::find_file(
62  "ActsConfig/ActsAmbiguityConfig.json", "DATAPATH");
63 
64  std::ifstream file(fileName.c_str());
65  if (!file.is_open()) {
66  std::cerr << "Error opening file: " << fileName << std::endl;
67  return {};
68  }
69  file >> json_file;
70  file.close();
71 
72  Acts::from_json(json_file, configPair);
73 
74  cfg.volumeMap = configPair.first;
75  cfg.detectorConfigs = configPair.second;
76  cfg.minScore = m_minScore;
77  cfg.minScoreSharedTracks = m_minScoreSharedTracks;
78  cfg.maxSharedTracksPerMeasurement = m_maxSharedTracksPerMeasurement;
79  cfg.maxShared = m_maxShared;
80  cfg.pTMin = m_pTMin;
81  cfg.pTMax = m_pTMax;
82  cfg.phiMin = m_phiMin;
83  cfg.phiMax = m_phiMax;
84  cfg.etaMin = m_etaMin;
85  cfg.etaMax = m_etaMax;
86  cfg.useAmbiguityFunction = m_useAmbiguityFunction;
87 
88  m_ambi = std::make_unique<Acts::ScoreBasedAmbiguityResolution>(
89  std::move(cfg), makeActsAthenaLogger(this, "Acts"));
90  assert(m_ambi);
91  }
92 
93  ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
99  m_resolvedTracksKey.key()))); // TODO choose prefix related to the
100  // output tracks name
101  return StatusCode::SUCCESS;
102 }
103 
105  const EventContext &ctx) const {
106  auto timer = Monitored::Timer<std::chrono::milliseconds>("TIME_execute");
108 
111  ATH_CHECK(trackHandle.isValid());
112 
113  // creates mutable tracks from the input tracks to add summary information
114  // NOTE: this operation likely needs to moved outside ambiguity resolution
115  ActsTrk::MutableTrackContainer updatedTracks =
117 
118  // create the optional cuts for the ambiguity resolution
119  Acts::ScoreBasedAmbiguityResolution::OptionalCuts<
120  ActsTrk::MutableTrackContainer::ConstTrackProxy>
121  optionalCuts;
122 
123  using TrackProxyType = Acts::TrackProxy<ActsTrk::MutableTrackSummaryContainer,
125  Acts::detail::ValueHolder, true>;
126 
127  // Eta based optional cuts is added as a lambda function inorder to access the
128  // m_etaDependentCutsSvc private variable
129  optionalCuts.cuts.push_back([this](const TrackProxyType &track) {
130  // Access m_etaDependentCutsSvc through this
133  });
134 
135  // Add other optional cuts and scores
136  optionalCuts.cuts.push_back(ScoreBasedSolverCutsImpl::doubleHolesFilter);
137  optionalCuts.scores.push_back(
139  optionalCuts.scores.push_back(
141  optionalCuts.hitSelections.push_back(
143 
144  // Call the ambiguity resolution algorithm with the optional cuts on the
145  // updated tracks
146  std::vector<int> goodTracks = m_ambi->solveAmbiguity(
147  updatedTracks, &sourceLinkHash, &sourceLinkEquality, optionalCuts);
148 
149  ATH_MSG_DEBUG("Resolved to " << goodTracks.size() << " tracks from "
150  << updatedTracks.size());
151 
152  ActsTrk::MutableTrackContainer solvedTracks;
153  solvedTracks.ensureDynamicColumns(updatedTracks);
154 
155  for (auto iTrack : goodTracks) {
156  auto destProxy = solvedTracks.getTrack(solvedTracks.addTrack());
157  destProxy.copyFrom(updatedTracks.getTrack(iTrack));
158  }
159  std::unique_ptr<ActsTrk::TrackContainer> outputTracks =
161  std::move(solvedTracks),
162  m_trackingGeometryTool->getGeometryContext(ctx).context(), ctx);
163  SG::WriteHandle<ActsTrk::TrackContainer> resolvedTrackHandle(
164  m_resolvedTracksKey, ctx);
165 
166  if (resolvedTrackHandle.record(std::move(outputTracks)).isFailure()) {
167  ATH_MSG_ERROR("Failed to record resolved ACTS tracks with key "
168  << m_resolvedTracksKey.key());
169  return StatusCode::FAILURE;
170  }
171 
172  return StatusCode::SUCCESS;
173 }
174 
175 } // namespace ActsTrk
xAOD::UncalibratedMeasurement_v1::identifier
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: ScoreBasedAmbiguityResolutionAlg.h:49
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
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_etaMax
Gaudi::Property< double > m_etaMax
Definition: ScoreBasedAmbiguityResolutionAlg.h:86
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_phiMax
Gaudi::Property< double > m_phiMax
Definition: ScoreBasedAmbiguityResolutionAlg.h:80
json
nlohmann::json json
Definition: HistogramDef.cxx:9
ActsTrk::ScoreBasedSolverCutsImpl::innermostPixelLayerHitsScore
void innermostPixelLayerHitsScore(const trackProxy_t &track, double &score)
Score modifier for tracks based on innermost pixel layer hits.
Definition: ScoreBasedSolverCutsImpl.cxx:114
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_phiMin
Gaudi::Property< double > m_phiMin
Definition: ScoreBasedAmbiguityResolutionAlg.h:77
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_useAmbiguityFunction
Gaudi::Property< bool > m_useAmbiguityFunction
Definition: ScoreBasedAmbiguityResolutionAlg.h:89
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ActsTrk::ScoreBasedAmbiguityResolutionAlg::ScoreBasedAmbiguityResolutionAlg
ScoreBasedAmbiguityResolutionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ScoreBasedAmbiguityResolutionAlg.cxx:51
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_resolvedTracksBackendHandles
ActsTrk::MutableTrackContainerHandlesHelper m_resolvedTracksBackendHandles
Definition: ScoreBasedAmbiguityResolutionAlg.h:56
ActsTrk::ScoreBasedAmbiguityResolutionAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: ScoreBasedAmbiguityResolutionAlg.cxx:104
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
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_tracksKey
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
Definition: ScoreBasedAmbiguityResolutionAlg.h:54
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::ScoreBasedAmbiguityResolutionAlg::m_ambi
std::unique_ptr< Acts::ScoreBasedAmbiguityResolution > m_ambi
Definition: ScoreBasedAmbiguityResolutionAlg.h:97
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
ActsTrk::MutableMultiTrajectory
Athena implementation of ACTS::MultiTrajectory (ReadWrite version) The data is stored in 4 external b...
Definition: MultiTrajectory.h:81
ActsTrk::ScoreBasedSolverCutsImpl::doubleHolesFilter
bool doubleHolesFilter(const trackProxy_t &track)
Filter for tracks based on double holes.
Definition: ScoreBasedSolverCutsImpl.cxx:96
ScoreBasedSolverCutsImpl.h
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_minScore
Gaudi::Property< double > m_minScore
Definition: ScoreBasedAmbiguityResolutionAlg.h:61
ActsTrk::MutableTrackSummaryContainer
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:118
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
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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::ScoreBasedAmbiguityResolutionAlg::m_etaDependentCutsSvc
ServiceHandle< InDet::IInDetEtaDependentCutsSvc > m_etaDependentCutsSvc
ITk eta-dependent cuts.
Definition: ScoreBasedAmbiguityResolutionAlg.h:100
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?
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::ScoreBasedSolverCutsImpl::etaDependentCuts
bool etaDependentCuts(const trackProxy_t &track, ServiceHandle< InDet::IInDetEtaDependentCutsSvc > etaDependentCutsSvc)
Filter for tracks based on eta dependent cuts.
Definition: ScoreBasedSolverCutsImpl.cxx:184
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_trackingGeometryTool
ToolHandle< IActsTrackingGeometryTool > m_trackingGeometryTool
Definition: ScoreBasedAmbiguityResolutionAlg.h:51
ActsTrk::getUncalibratedMeasurement
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
Definition: ATLASSourceLink.h:26
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_pTMin
Gaudi::Property< double > m_pTMin
Definition: ScoreBasedAmbiguityResolutionAlg.h:72
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_minScoreSharedTracks
Gaudi::Property< double > m_minScoreSharedTracks
Definition: ScoreBasedAmbiguityResolutionAlg.h:63
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_maxShared
Gaudi::Property< std::size_t > m_maxShared
Definition: ScoreBasedAmbiguityResolutionAlg.h:69
a
TList * a
Definition: liststreamerinfos.cxx:10
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ActsTrk::ScoreBasedSolverCutsImpl::addSummaryInformation
ActsTrk::MutableTrackContainer addSummaryInformation(ActsTrk::TrackContainer trackContainer)
Adds summary information to the track container.
Definition: ScoreBasedSolverCutsImpl.cxx:31
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_etaMin
Gaudi::Property< double > m_etaMin
Definition: ScoreBasedAmbiguityResolutionAlg.h:84
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
ScoreBasedAmbiguityResolutionAlg.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_maxSharedTracksPerMeasurement
Gaudi::Property< std::size_t > m_maxSharedTracksPerMeasurement
Definition: ScoreBasedAmbiguityResolutionAlg.h:66
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_resolvedTracksKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_resolvedTracksKey
Definition: ScoreBasedAmbiguityResolutionAlg.h:57
Logger.h
JetPileupTag::from_json
void from_json(const nlohmann::json &j, NNJvtBinning &binning)
Definition: NNJvtBinning.cxx:24
ActsTrk::MutableTrackContainer
Definition: TrackContainer.h:122
ActsTrk::ScoreBasedSolverCutsImpl::ContribPixelLayersScore
void ContribPixelLayersScore(const trackProxy_t &track, double &score)
Score modifier for tracks based on contributing pixel layers.
Definition: ScoreBasedSolverCutsImpl.cxx:143
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
ActsTrk::ScoreBasedAmbiguityResolutionAlg::initialize
virtual StatusCode initialize() override
Definition: ScoreBasedAmbiguityResolutionAlg.cxx:55
ActsTrk::ScoreBasedAmbiguityResolutionAlg::m_pTMax
Gaudi::Property< double > m_pTMax
Definition: ScoreBasedAmbiguityResolutionAlg.h:74
ActsTrk::ScoreBasedSolverCutsImpl::patternTrackHitSelection
void patternTrackHitSelection(const trackProxy_t &track, const trackProxy_t::ConstTrackStateProxy &ts, Acts::ScoreBasedAmbiguityResolution::TrackStateTypes &trackStateType)
Hit selection for tracks based on pattern track hits.
Definition: ScoreBasedSolverCutsImpl.cxx:209