File indexing completed on 2025-01-18 09:10:44
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/AmbiguityResolution/AmbiguityNetworkConcept.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/EventData/TrackContainer.hpp"
0014 #include "Acts/Utilities/Delegate.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016
0017 #include <cstddef>
0018 #include <map>
0019 #include <memory>
0020 #include <string>
0021 #include <tuple>
0022 #include <vector>
0023
0024 namespace Acts {
0025
0026
0027
0028 template <AmbiguityNetworkConcept AmbiguityNetwork>
0029 class AmbiguityResolutionML {
0030 public:
0031 struct Config {
0032
0033 std::string inputDuplicateNN = "";
0034
0035 std::size_t nMeasurementsMin = 7;
0036 };
0037
0038
0039
0040
0041 AmbiguityResolutionML(const Config& cfg,
0042 std::unique_ptr<const Logger> logger = getDefaultLogger(
0043 "AmbiguityResolutionML", Logging::INFO))
0044 : m_cfg{cfg},
0045 m_duplicateClassifier(m_cfg.inputDuplicateNN.c_str()),
0046 m_logger{std::move(logger)} {}
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 template <TrackContainerFrontend track_container_t,
0060 typename source_link_hash_t, typename source_link_equality_t>
0061 std::multimap<int, std::pair<std::size_t, std::vector<std::size_t>>>
0062 mapTrackHits(const track_container_t& tracks,
0063 const source_link_hash_t& sourceLinkHash,
0064 const source_link_equality_t& sourceLinkEquality) const {
0065
0066 auto measurementIndexMap =
0067 std::unordered_map<SourceLink, std::size_t, source_link_hash_t,
0068 source_link_equality_t>(0, sourceLinkHash,
0069 sourceLinkEquality);
0070
0071
0072
0073
0074 std::multimap<int, std::pair<std::size_t, std::vector<std::size_t>>>
0075 trackMap;
0076 std::size_t trackIndex = 0;
0077 std::vector<std::size_t> measurements;
0078
0079 for (const auto& track : tracks) {
0080
0081 if (track.nMeasurements() < m_cfg.nMeasurementsMin) {
0082 continue;
0083 }
0084 measurements.clear();
0085 for (auto ts : track.trackStatesReversed()) {
0086 if (ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
0087 SourceLink sourceLink = ts.getUncalibratedSourceLink();
0088
0089 auto emplace = measurementIndexMap.try_emplace(
0090 sourceLink, measurementIndexMap.size());
0091 measurements.push_back(emplace.first->second);
0092 }
0093 }
0094 trackMap.emplace(track.nMeasurements(),
0095 std::make_pair(trackIndex, measurements));
0096 ++trackIndex;
0097 }
0098 return trackMap;
0099 }
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 template <TrackContainerFrontend track_container_t>
0110 std::vector<std::size_t> solveAmbiguity(
0111 std::unordered_map<std::size_t, std::vector<std::size_t>>& clusters,
0112 const track_container_t& tracks) const {
0113 std::vector<std::vector<float>> outputTensor =
0114 m_duplicateClassifier.inferScores(clusters, tracks);
0115 std::vector<std::size_t> goodTracks =
0116 m_duplicateClassifier.trackSelection(clusters, outputTensor);
0117
0118 return goodTracks;
0119 }
0120
0121 private:
0122
0123 Config m_cfg;
0124
0125
0126
0127 AmbiguityNetwork m_duplicateClassifier;
0128
0129
0130 std::unique_ptr<const Logger> m_logger = nullptr;
0131
0132
0133 const Logger& logger() const { return *m_logger; }
0134 };
0135
0136 }