From bf49b8f60d5301e370fdf0da6465f17fb04b118d Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 17 Oct 2024 11:53:04 +0200 Subject: [PATCH 01/27] temp fix --- Core/include/Acts/EventData/Seed.hpp | 1 - Core/include/Acts/EventData/Seed.ipp | 6 ------ 2 files changed, 7 deletions(-) diff --git a/Core/include/Acts/EventData/Seed.hpp b/Core/include/Acts/EventData/Seed.hpp index db93b319dcb..87de8d4eb1b 100644 --- a/Core/include/Acts/EventData/Seed.hpp +++ b/Core/include/Acts/EventData/Seed.hpp @@ -14,7 +14,6 @@ namespace Acts { template - requires(N >= 3ul) class Seed { public: using value_type = external_spacepoint_t; diff --git a/Core/include/Acts/EventData/Seed.ipp b/Core/include/Acts/EventData/Seed.ipp index 74f2c0e4169..e977a3d67d7 100644 --- a/Core/include/Acts/EventData/Seed.ipp +++ b/Core/include/Acts/EventData/Seed.ipp @@ -9,7 +9,6 @@ namespace Acts { template - requires(N >= 3ul) template requires(sizeof...(args_t) == N) && (std::same_as && ...) @@ -17,32 +16,27 @@ Seed::Seed(const args_t&... points) : m_spacepoints({&points...}) {} template - requires(N >= 3ul) void Seed::setVertexZ(float vertex) { m_vertexZ = vertex; } template - requires(N >= 3ul) void Seed::setQuality(float seedQuality) { m_seedQuality = seedQuality; } template - requires(N >= 3ul) const std::array& Seed::sp() const { return m_spacepoints; } template - requires(N >= 3ul) float Seed::z() const { return m_vertexZ; } template - requires(N >= 3ul) float Seed::seedQuality() const { return m_seedQuality; } From 1ec76b1f31e85cd1e132bbc344daad7a92db40ab Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 22 Jan 2025 20:30:45 +0100 Subject: [PATCH 02/27] added eta based cuts --- .../ScoreBasedAmbiguityResolution.hpp | 28 ++-- .../ScoreBasedAmbiguityResolution.ipp | 142 +++++++----------- .../ScoreBasedAmbiguityResolution.cpp | 50 ++++++ .../Json/src/AmbiguityConfigJsonConverter.cpp | 17 ++- 4 files changed, 133 insertions(+), 104 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index 6ed24a71be8..0fc550ca574 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -38,6 +38,7 @@ namespace Acts { /// enough hits /// 5) Remove tracks that are not good enough based on cuts Contains method for /// data preparations + class ScoreBasedAmbiguityResolution { public: /// @brief Detector configuration struct : contains the configuration for each detector @@ -50,11 +51,16 @@ class ScoreBasedAmbiguityResolution { int outliersScoreWeight = 0; int otherScoreWeight = 0; - std::size_t minHits = 0; + // the minimum number of hits for each detector for each eta bin + std::vector etaBins = {-5, 5}; + + std::vector minHitsPerEta = {0}; + std::vector maxHolesPerEta = {0}; + std::vector maxOutliersPerEta = {0}; + std::vector maxSharedHitsPerEta = {0}; + std::size_t maxHits = 0; std::size_t maxHoles = 0; - std::size_t maxOutliers = 0; - std::size_t maxSharedHits = 0; /// if true, the shared hits are considered as bad hits for this detector bool sharedHitsFlag = false; @@ -108,15 +114,6 @@ class ScoreBasedAmbiguityResolution { /// maximum number of shared hit per track std::size_t maxShared = 5; - double pTMin = 0 * UnitConstants::GeV; - double pTMax = 1e5 * UnitConstants::GeV; - - double phiMin = -std::numbers::pi * UnitConstants::rad; - double phiMax = std::numbers::pi * UnitConstants::rad; - - double etaMin = -5; - double etaMax = 5; - // if true, the ambiguity score is computed based on a different function. bool useAmbiguityFunction = false; }; @@ -185,6 +182,10 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; + bool etaBasedCuts( + const DetectorConfig& detector, const TrackFeatures& trackFeatures, + const double& eta) const; + /// Remove hits that are not good enough for each track and removes tracks /// that have a score below a certain threshold or not enough hits. /// @@ -221,6 +222,9 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; + static std::size_t getValueAtEta(std::vector cuts, std::size_t etaBinSize, + std::size_t binIndex); + private: Config m_cfg; diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index 247b767dd3d..d423eea8913 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -91,38 +91,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::simpleScore( double score = 1; auto pT = Acts::VectorHelpers::perp(track.momentum()); auto eta = Acts::VectorHelpers::eta(track.momentum()); - auto phi = Acts::VectorHelpers::phi(track.momentum()); - // cuts on pT - if (pT < m_cfg.pTMin || pT > m_cfg.pTMax) { - score = 0; - iTrack++; - trackScore.push_back(score); - ACTS_DEBUG("Track: " << iTrack - << " has score = 0, due to pT cuts --- pT = " << pT); - continue; - } - - // cuts on phi - if (phi > m_cfg.phiMax || phi < m_cfg.phiMin) { - score = 0; - iTrack++; - trackScore.push_back(score); - ACTS_DEBUG("Track: " << iTrack - << " has score = 0, due to phi cuts --- phi = " - << phi); - continue; - } - - // cuts on eta - if (eta > m_cfg.etaMax || eta < m_cfg.etaMin) { - score = 0; - iTrack++; - trackScore.push_back(score); - ACTS_DEBUG("Track: " << iTrack - << " has score = 0, due to eta cuts --- eta = " - << eta); - continue; - } // cuts on optional cuts for (const auto& cutFunction : optionalCuts.cuts) { @@ -140,6 +108,7 @@ std::vector Acts::ScoreBasedAmbiguityResolution::simpleScore( ACTS_DEBUG("Track: " << iTrack << " score : " << score); continue; } + // Reject tracks which didn't pass the detector cuts. for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { @@ -147,15 +116,14 @@ std::vector Acts::ScoreBasedAmbiguityResolution::simpleScore( const auto& trackFeatures = trackFeaturesVector[detectorId]; - ACTS_DEBUG("---> Found summary information"); - ACTS_DEBUG("---> Detector ID: " << detectorId); - ACTS_DEBUG("---> Number of hits: " << trackFeatures.nHits); - ACTS_DEBUG("---> Number of holes: " << trackFeatures.nHoles); - ACTS_DEBUG("---> Number of outliers: " << trackFeatures.nOutliers); + ACTS_VERBOSE("---> Found summary information"); + ACTS_VERBOSE("---> Detector ID: " << detectorId); + ACTS_VERBOSE("---> Number of hits: " << trackFeatures.nHits); + ACTS_VERBOSE("---> Number of holes: " << trackFeatures.nHoles); + ACTS_VERBOSE("---> Number of outliers: " << trackFeatures.nOutliers); - if ((trackFeatures.nHits < detector.minHits) || - (trackFeatures.nHoles > detector.maxHoles) || - (trackFeatures.nOutliers > detector.maxOutliers)) { + // eta based cuts + if (etaBasedCuts(detector, trackFeatures, eta)) { score = 0; ACTS_DEBUG("Track: " << iTrack << " has score = 0, due to detector cuts"); @@ -170,9 +138,7 @@ std::vector Acts::ScoreBasedAmbiguityResolution::simpleScore( continue; } - // real scoring starts here - // if the ambiguity scoring function is used, the score is processed with a - // different algorithm than the simple score. + // All cuts passed, now start scoring the track ACTS_VERBOSE("Using Simple Scoring function"); @@ -241,38 +207,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( double score = 1; auto pT = Acts::VectorHelpers::perp(track.momentum()); auto eta = Acts::VectorHelpers::eta(track.momentum()); - auto phi = Acts::VectorHelpers::phi(track.momentum()); - // cuts on pT - if (pT < m_cfg.pTMin || pT > m_cfg.pTMax) { - score = 0; - iTrack++; - trackScore.push_back(score); - ACTS_DEBUG("Track: " << iTrack - << " has score = 0, due to pT cuts --- pT = " << pT); - continue; - } - - // cuts on phi - if (phi > m_cfg.phiMax || phi < m_cfg.phiMin) { - score = 0; - iTrack++; - trackScore.push_back(score); - ACTS_DEBUG("Track: " << iTrack - << " has score = 0, due to phi cuts --- phi = " - << phi); - continue; - } - - // cuts on eta - if (eta > m_cfg.etaMax || eta < m_cfg.etaMin) { - score = 0; - iTrack++; - trackScore.push_back(score); - ACTS_DEBUG("Track: " << iTrack - << " has score = 0, due to eta cuts --- eta = " - << eta); - continue; - } // cuts on optional cuts for (const auto& cutFunction : optionalCuts.cuts) { @@ -290,6 +224,7 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( ACTS_DEBUG("Track: " << iTrack << " score : " << score); continue; } + // Reject tracks which didn't pass the detector cuts. for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { @@ -297,15 +232,14 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( const auto& trackFeatures = trackFeaturesVector[detectorId]; - ACTS_DEBUG("---> Found summary information"); - ACTS_DEBUG("---> Detector ID: " << detectorId); - ACTS_DEBUG("---> Number of hits: " << trackFeatures.nHits); - ACTS_DEBUG("---> Number of holes: " << trackFeatures.nHoles); - ACTS_DEBUG("---> Number of outliers: " << trackFeatures.nOutliers); + ACTS_VERBOSE("---> Found summary information"); + ACTS_VERBOSE("---> Detector ID: " << detectorId); + ACTS_VERBOSE("---> Number of hits: " << trackFeatures.nHits); + ACTS_VERBOSE("---> Number of holes: " << trackFeatures.nHoles); + ACTS_VERBOSE("---> Number of outliers: " << trackFeatures.nOutliers); - if ((trackFeatures.nHits < detector.minHits) || - (trackFeatures.nHoles > detector.maxHoles) || - (trackFeatures.nOutliers > detector.maxOutliers)) { + // eta based cuts + if (etaBasedCuts(detector, trackFeatures, eta)) { score = 0; ACTS_DEBUG("Track: " << iTrack << " has score = 0, due to detector cuts"); @@ -320,23 +254,32 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( continue; } + // All cuts passed, now start scoring the track + + std::cout << ", Score before Pt," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; // start with larger score for tracks with higher pT. score = std::log10(pT / UnitConstants::MeV) - 1.; // pT in GeV, hence 100 MeV is minimum and gets score = 1 ACTS_DEBUG("Modifier for pT = " << pT << " GeV is : " << score << " New score now: " << score); + std::cout << ", Score after Pt," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; + for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { const auto& detector = m_cfg.detectorConfigs.at(detectorId); const auto& trackFeatures = trackFeaturesVector[detectorId]; + std::cout << ", Score before detector " << detectorId << " Hits," << score + << ", pT, " << pT << ", eta, " << eta << std::endl; // choosing a scaling factor based on the number of hits in a track per // detector. std::size_t nHits = trackFeatures.nHits; if (nHits > detector.maxHits) { - score = score * (detector.maxHits - nHits + 1); // hits are good ! + score = score * (nHits - detector.maxHits + 1); // hits are good ! nHits = detector.maxHits; } score = score * detector.factorHits[nHits]; @@ -344,6 +287,12 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " hits: " << detector.factorHits[nHits] << " New score now: " << score); + std::cout << ", Score after detector " << detectorId << " Hits," << score + << ", pT, " << pT << ", eta, " << eta << std::endl; + + std::cout << ", Score before detector " << detectorId << " Holes," + << score << ", pT, " << pT << ", eta, " << eta << std::endl; + // choosing a scaling factor based on the number of holes in a track per // detector. std::size_t iHoles = trackFeatures.nHoles; @@ -355,12 +304,17 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( ACTS_DEBUG("Modifier for " << iHoles << " holes: " << detector.factorHoles[iHoles] << " New score now: " << score); + std::cout << ", Score after detector " << detectorId << " Holes," << score + << ", pT, " << pT << ", eta, " << eta << std::endl; } for (const auto& scoreFunction : optionalCuts.scores) { scoreFunction(track, score); } + std::cout << ", Score before chi2," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; + if (track.chi2() > 0 && track.nDoF() > 0) { double chi2 = track.chi2(); int indf = track.nDoF(); @@ -370,6 +324,9 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " is : " << fac << " New score now: " << score); } + + std::cout << ", Score after chi2," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; iTrack++; // Add the score to the vector @@ -451,11 +408,24 @@ std::vector Acts::ScoreBasedAmbiguityResolution::solveAmbiguity( // Check if the track has too many shared hits to be accepted. auto trackFeaturesVector = trackFeaturesVectors.at(iTrack); bool trkCouldBeAccepted = true; + double eta = Acts::VectorHelpers::eta(track.momentum()); + for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { auto detector = m_cfg.detectorConfigs.at(detectorId); - if (trackFeaturesVector[detectorId].nSharedHits > - detector.maxSharedHits) { + + std::vector etaBins = detector.etaBins; + int etaBin = 0; + + for (std::size_t i = 0; i < detector.etaBins.size() - 1; ++i) { + if (eta >= etaBins[i] && eta < detector.etaBins[i + 1]) { + etaBin = i; + break; + } + } + + if (trackFeaturesVector[detectorId].nSharedHits < + getValueAtEta(detector.maxSharedHitsPerEta, etaBins.size(), etaBin)) { trkCouldBeAccepted = false; break; } diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index c7e47f41046..26524c03785 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -7,3 +7,53 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp" + +std::size_t Acts::ScoreBasedAmbiguityResolution::getValueAtEta( + std::vector cuts, std::size_t etaBinSize, + std::size_t binIndex) { + if (cuts.size() == etaBinSize - 1) { + return cuts[binIndex]; + } + + else if (cuts.size() == 1) { + return cuts[0]; + } + + else { + std::cerr + << "The size of minHits is not equal to 1 or the number of eta bins" + << std::endl; + return 0; + } +} + +bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( + const DetectorConfig& detector, const TrackFeatures& trackFeatures, + const double& eta) const { + std::vector etaBins = detector.etaBins; + int etaBin = 0; + + bool cutApplied = false; + + for (std::size_t i = 0; i < etaBins.size() - 1; ++i) { + if (eta >= etaBins[i] && eta < etaBins[i + 1]) { + etaBin = i; + break; + } + } + + cutApplied = + (trackFeatures.nHits < + getValueAtEta(detector.minHitsPerEta, etaBins.size(), etaBin)) || + cutApplied; + cutApplied = + (trackFeatures.nHoles > + getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || + cutApplied; + cutApplied = + (trackFeatures.nOutliers > + getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || + cutApplied; + + return cutApplied; +} diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index ded95d8c122..dc1c7780ab3 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -27,12 +27,6 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { detectorConfig.outliersScoreWeight = value["outliersScoreWeight"]; detectorConfig.otherScoreWeight = value["otherScoreWeight"]; - detectorConfig.minHits = value["minHits"]; - detectorConfig.maxHits = value["maxHits"]; - detectorConfig.maxHoles = value["maxHoles"]; - detectorConfig.maxOutliers = value["maxOutliers"]; - detectorConfig.maxSharedHits = value["maxSharedHits"]; - detectorConfig.sharedHitsFlag = value["sharedHitsFlag"]; const std::vector& goodHits = value["goodHits"]; @@ -41,10 +35,19 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { const std::vector& fakeHits = value["fakeHits"]; const std::vector& fakeHoles = value["fakeHoles"]; + const std::vector& minHitsPerEta = value["minHitsPerEta"]; + const std::vector& maxHolesPerEta = value["maxHolesPerEta"]; + const std::vector& maxOutliersPerEta = + value["maxOutliersPerEta"]; + const std::vector& maxSharedHitsPerEta = + value["maxSharedHitsPerEta"]; + if (goodHits.size() != fakeHits.size()) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); } + detectorConfig.maxHits = goodHits.size() - 1; + for (std::size_t i = 0; i < goodHits.size(); i++) { detectorConfig.factorHits.push_back(goodHits[i] / fakeHits[i]); } @@ -53,6 +56,8 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { throw std::invalid_argument("goodHoles and FakeHoles size mismatch"); } + detectorConfig.maxHoles = goodHoles.size() - 1; + for (std::size_t i = 0; i < goodHoles.size(); i++) { detectorConfig.factorHoles.push_back(goodHoles[i] / fakeHoles[i]); } From c8ae9f9ee6063fe52a1bc56587bfecb4f40cfd81 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 22 Jan 2025 20:39:51 +0100 Subject: [PATCH 03/27] removed cout statements --- .../ScoreBasedAmbiguityResolution.ipp | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index d423eea8913..99834315ceb 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -256,25 +256,18 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( // All cuts passed, now start scoring the track - std::cout << ", Score before Pt," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; // start with larger score for tracks with higher pT. score = std::log10(pT / UnitConstants::MeV) - 1.; // pT in GeV, hence 100 MeV is minimum and gets score = 1 ACTS_DEBUG("Modifier for pT = " << pT << " GeV is : " << score << " New score now: " << score); - std::cout << ", Score after Pt," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; - for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { const auto& detector = m_cfg.detectorConfigs.at(detectorId); const auto& trackFeatures = trackFeaturesVector[detectorId]; - std::cout << ", Score before detector " << detectorId << " Hits," << score - << ", pT, " << pT << ", eta, " << eta << std::endl; // choosing a scaling factor based on the number of hits in a track per // detector. std::size_t nHits = trackFeatures.nHits; @@ -287,12 +280,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " hits: " << detector.factorHits[nHits] << " New score now: " << score); - std::cout << ", Score after detector " << detectorId << " Hits," << score - << ", pT, " << pT << ", eta, " << eta << std::endl; - - std::cout << ", Score before detector " << detectorId << " Holes," - << score << ", pT, " << pT << ", eta, " << eta << std::endl; - // choosing a scaling factor based on the number of holes in a track per // detector. std::size_t iHoles = trackFeatures.nHoles; @@ -304,17 +291,13 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( ACTS_DEBUG("Modifier for " << iHoles << " holes: " << detector.factorHoles[iHoles] << " New score now: " << score); - std::cout << ", Score after detector " << detectorId << " Holes," << score - << ", pT, " << pT << ", eta, " << eta << std::endl; + ; } for (const auto& scoreFunction : optionalCuts.scores) { scoreFunction(track, score); } - std::cout << ", Score before chi2," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; - if (track.chi2() > 0 && track.nDoF() > 0) { double chi2 = track.chi2(); int indf = track.nDoF(); @@ -325,8 +308,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " New score now: " << score); } - std::cout << ", Score after chi2," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; iTrack++; // Add the score to the vector From bd5ddc3298f41fa43270b30e1210fbbdf318af21 Mon Sep 17 00:00:00 2001 From: Ragansu Chakkappai <66349236+Ragansu@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:21:19 +0100 Subject: [PATCH 04/27] Update ScoreBasedAmbiguityResolution.ipp removed unused varible --- .../Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index 99834315ceb..808d37e6602 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -89,7 +89,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::simpleScore( // get the trackFeatures map for the track const auto& trackFeaturesVector = trackFeaturesVectors[iTrack]; double score = 1; - auto pT = Acts::VectorHelpers::perp(track.momentum()); auto eta = Acts::VectorHelpers::eta(track.momentum()); // cuts on optional cuts From 81cfacf40455a22994da3ccfd457099cda174a7e Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 17:01:41 +0100 Subject: [PATCH 05/27] updated Exams and tests --- .../ScoreBasedAmbiguityResolutionAlgorithm.hpp | 9 --------- .../src/ScoreBasedAmbiguityResolutionAlgorithm.cpp | 6 ------ .../ScoreBasedAmbiguityResolutionTest.cpp | 6 ------ 3 files changed, 21 deletions(-) diff --git a/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp b/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp index b63100f8751..fc39610345d 100644 --- a/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp +++ b/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp @@ -54,15 +54,6 @@ class ScoreBasedAmbiguityResolutionAlgorithm final : public IAlgorithm { // maximum number of shared hit per track std::size_t maxShared = 5; - double pTMin = 0 * Acts::UnitConstants::GeV; - double pTMax = 1e5 * Acts::UnitConstants::GeV; - - double phiMin = -std::numbers::pi * Acts::UnitConstants::rad; - double phiMax = std::numbers::pi * Acts::UnitConstants::rad; - - double etaMin = -5; - double etaMax = 5; - bool useAmbiguityFunction = false; }; diff --git a/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp b/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp index b1a6e251dba..3ac5b429206 100644 --- a/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp +++ b/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp @@ -44,12 +44,6 @@ Acts::ScoreBasedAmbiguityResolution::Config transformConfig( result.minScoreSharedTracks = cfg.minScoreSharedTracks; result.maxSharedTracksPerMeasurement = cfg.maxSharedTracksPerMeasurement; result.maxShared = cfg.maxShared; - result.pTMin = cfg.pTMin; - result.pTMax = cfg.pTMax; - result.phiMin = cfg.phiMin; - result.phiMax = cfg.phiMax; - result.etaMin = cfg.etaMin; - result.etaMax = cfg.etaMax; result.useAmbiguityFunction = cfg.useAmbiguityFunction; return result; } diff --git a/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp b/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp index 55beab4ca2f..1b2eb55ca11 100644 --- a/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp +++ b/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp @@ -49,12 +49,6 @@ struct Fixture { config.minScoreSharedTracks = 100; config.maxShared = 5; config.maxSharedTracksPerMeasurement = 10; - config.phiMax = 3.14; - config.phiMin = -3.14; - config.etaMax = 2.7; - config.etaMin = -2.7; - config.pTMax = 1400; - config.pTMin = 0.5; config.useAmbiguityFunction = false; } From 284a2da4bf1224914d1a6c0b2783e9b472551520 Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 17:03:31 +0100 Subject: [PATCH 06/27] fixed formating --- .../ScoreBasedAmbiguityResolution.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index 26524c03785..0f62709df46 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -42,17 +42,15 @@ bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( } } + cutApplied = (trackFeatures.nHits < getValueAtEta(detector.minHitsPerEta, + etaBins.size(), etaBin)) || + cutApplied; + cutApplied = (trackFeatures.nHoles > getValueAtEta(detector.maxHolesPerEta, + etaBins.size(), etaBin)) || + cutApplied; cutApplied = - (trackFeatures.nHits < - getValueAtEta(detector.minHitsPerEta, etaBins.size(), etaBin)) || - cutApplied; - cutApplied = - (trackFeatures.nHoles > - getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || - cutApplied; - cutApplied = - (trackFeatures.nOutliers > - getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || + (trackFeatures.nOutliers > + getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || cutApplied; return cutApplied; From 357ceaea69037e5e7ae0fc52b7aae469cb56e068 Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 17:06:54 +0100 Subject: [PATCH 07/27] format check for hpp --- .../ScoreBasedAmbiguityResolution.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index 0fc550ca574..4f7526e752d 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -182,9 +182,9 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - bool etaBasedCuts( - const DetectorConfig& detector, const TrackFeatures& trackFeatures, - const double& eta) const; + bool etaBasedCuts(const DetectorConfig& detector, + const TrackFeatures& trackFeatures, + const double& eta) const; /// Remove hits that are not good enough for each track and removes tracks /// that have a score below a certain threshold or not enough hits. @@ -222,8 +222,9 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - static std::size_t getValueAtEta(std::vector cuts, std::size_t etaBinSize, - std::size_t binIndex); + static std::size_t getValueAtEta(std::vector cuts, + std::size_t etaBinSize, + std::size_t binIndex); private: Config m_cfg; From 1f6dc5c9435793504cb28bf3f77d15dc0fe159f9 Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 17:20:59 +0100 Subject: [PATCH 08/27] updated Examply python code --- Examples/Python/python/acts/examples/reconstruction.py | 6 ------ Examples/Python/src/AmbiguityResolution.cpp | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index b1536c01845..feecc46e4be 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -217,12 +217,6 @@ def trackSelectorDefaultKWArgs(c): "minScoreSharedTracks", "maxShared", "maxSharedTracksPerMeasurement", - "pTMax", - "pTMin", - "phiMax", - "phiMin", - "etaMax", - "etaMin", "useAmbiguityFunction", ], defaults=[None] * 11, diff --git a/Examples/Python/src/AmbiguityResolution.cpp b/Examples/Python/src/AmbiguityResolution.cpp index 2075a522609..ecae082d67b 100644 --- a/Examples/Python/src/AmbiguityResolution.cpp +++ b/Examples/Python/src/AmbiguityResolution.cpp @@ -34,8 +34,7 @@ void addAmbiguityResolution(Context& ctx) { ActsExamples::ScoreBasedAmbiguityResolutionAlgorithm, mex, "ScoreBasedAmbiguityResolutionAlgorithm", inputTracks, configFile, outputTracks, minScore, minScoreSharedTracks, maxShared, - maxSharedTracksPerMeasurement, pTMin, pTMax, phiMin, phiMax, etaMin, - etaMax, useAmbiguityFunction); + maxSharedTracksPerMeasurement, useAmbiguityFunction); } } // namespace Acts::Python From 926c57b7dcf435506a3c6665a0154b44d2e7204f Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 17:29:03 +0100 Subject: [PATCH 09/27] update python scripts --- Examples/Python/python/acts/examples/reconstruction.py | 6 +----- Examples/Scripts/Python/full_chain_odd.py | 6 ------ Examples/Scripts/Python/full_chain_odd_LRT.py | 6 ------ Examples/Scripts/Python/full_chain_test.py | 6 ------ 4 files changed, 1 insertion(+), 23 deletions(-) diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index feecc46e4be..2fc008bcef3 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -219,7 +219,7 @@ def trackSelectorDefaultKWArgs(c): "maxSharedTracksPerMeasurement", "useAmbiguityFunction", ], - defaults=[None] * 11, + defaults=[None] * 5, ) AmbiguityResolutionMLConfig = namedtuple( @@ -1942,10 +1942,6 @@ def addScoreBasedAmbiguityResolution( minScoreSharedTracks=config.minScoreSharedTracks, maxShared=config.maxShared, maxSharedTracksPerMeasurement=config.maxSharedTracksPerMeasurement, - phiMax=config.phiMax, - phiMin=config.phiMin, - etaMax=config.etaMax, - etaMin=config.etaMin, useAmbiguityFunction=config.useAmbiguityFunction, ), ) diff --git a/Examples/Scripts/Python/full_chain_odd.py b/Examples/Scripts/Python/full_chain_odd.py index 50fa2465e38..dadd87f5899 100755 --- a/Examples/Scripts/Python/full_chain_odd.py +++ b/Examples/Scripts/Python/full_chain_odd.py @@ -415,12 +415,6 @@ minScoreSharedTracks=1, maxShared=2, maxSharedTracksPerMeasurement=2, - pTMax=1400, - pTMin=0.5, - phiMax=math.pi, - phiMin=-math.pi, - etaMax=4, - etaMin=-4, useAmbiguityFunction=False, ), outputDirRoot=outputDir if args.output_root else None, diff --git a/Examples/Scripts/Python/full_chain_odd_LRT.py b/Examples/Scripts/Python/full_chain_odd_LRT.py index fde8b3b418c..bb92e93656b 100644 --- a/Examples/Scripts/Python/full_chain_odd_LRT.py +++ b/Examples/Scripts/Python/full_chain_odd_LRT.py @@ -418,12 +418,6 @@ minScoreSharedTracks=1, maxShared=2, maxSharedTracksPerMeasurement=2, - pTMax=1400, - pTMin=0.5, - phiMax=math.pi, - phiMin=-math.pi, - etaMax=4, - etaMin=-4, useAmbiguityFunction=False, ), outputDirRoot=outputDir if args.output_root else None, diff --git a/Examples/Scripts/Python/full_chain_test.py b/Examples/Scripts/Python/full_chain_test.py index 492c823cb5f..4905471becf 100755 --- a/Examples/Scripts/Python/full_chain_test.py +++ b/Examples/Scripts/Python/full_chain_test.py @@ -728,12 +728,6 @@ def full_chain(args): minScoreSharedTracks=1, maxShared=2, maxSharedTracksPerMeasurement=2, - pTMax=1400, - pTMin=0.5, - phiMax=math.pi, - phiMin=-math.pi, - etaMax=4, - etaMin=-4, useAmbiguityFunction=False, ), ambiVolumeFile=args.ambi_config, From 96de71d83687ed1931daa4a53f39880736395f1c Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 17:47:28 +0100 Subject: [PATCH 10/27] fixed json reader --- Plugins/Json/src/AmbiguityConfigJsonConverter.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index dc1c7780ab3..94a2311ab72 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -35,12 +35,10 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { const std::vector& fakeHits = value["fakeHits"]; const std::vector& fakeHoles = value["fakeHoles"]; - const std::vector& minHitsPerEta = value["minHitsPerEta"]; - const std::vector& maxHolesPerEta = value["maxHolesPerEta"]; - const std::vector& maxOutliersPerEta = - value["maxOutliersPerEta"]; - const std::vector& maxSharedHitsPerEta = - value["maxSharedHitsPerEta"]; + detectorConfig.minHitsPerEta = value["minHitsPerEta"]; + detectorConfig.maxHolesPerEta = value["maxHolesPerEta"]; + detectorConfig.maxOutliersPerEta = value["maxOutliersPerEta"]; + detectorConfig.maxSharedHitsPerEta = value["maxSharedHitsPerEta"]; if (goodHits.size() != fakeHits.size()) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); From 54cd92345ad8a1a79cb4836a253ccfd5842d9311 Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 18:05:33 +0100 Subject: [PATCH 11/27] fixed issues with josn loader --- .../ScoreBasedAmbiguityResolution.cpp | 6 ++-- .../Json/src/AmbiguityConfigJsonConverter.cpp | 32 +++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index 0f62709df46..38c55359440 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -42,14 +42,14 @@ bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( } } - cutApplied = (trackFeatures.nHits < getValueAtEta(detector.minHitsPerEta, + cutApplied = (trackFeatures.nHits <= getValueAtEta(detector.minHitsPerEta, etaBins.size(), etaBin)) || cutApplied; - cutApplied = (trackFeatures.nHoles > getValueAtEta(detector.maxHolesPerEta, + cutApplied = (trackFeatures.nHoles >= getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || cutApplied; cutApplied = - (trackFeatures.nOutliers > + (trackFeatures.nOutliers >= getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || cutApplied; diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index 94a2311ab72..f7f2b683d22 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -35,17 +35,38 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { const std::vector& fakeHits = value["fakeHits"]; const std::vector& fakeHoles = value["fakeHoles"]; - detectorConfig.minHitsPerEta = value["minHitsPerEta"]; - detectorConfig.maxHolesPerEta = value["maxHolesPerEta"]; - detectorConfig.maxOutliersPerEta = value["maxOutliersPerEta"]; - detectorConfig.maxSharedHitsPerEta = value["maxSharedHitsPerEta"]; + const std::vector& etaBins = value["etaBins"]; + for (auto etaBin : etaBins) { + detectorConfig.etaBins.push_back(etaBin); + } + + const std::vector& minHitsPerEta = value["minHitsPerEta"]; + for (auto minHit : minHitsPerEta) { + detectorConfig.minHitsPerEta.push_back(minHit); + } + + const std::vector& maxHolesPerEta = value["maxHolesPerEta"]; + for (auto maxHole : maxHolesPerEta) { + detectorConfig.maxHolesPerEta.push_back(maxHole); + } + + const std::vector& maxOutliersPerEta = + value["maxOutliersPerEta"]; + for (auto maxOutlier : maxOutliersPerEta) { + detectorConfig.maxOutliersPerEta.push_back(maxOutlier); + } + + const std::vector& maxSharedHitsPerEta = + value["maxSharedHitsPerEta"]; + for (auto maxSharedHit : maxSharedHitsPerEta) { + detectorConfig.maxSharedHitsPerEta.push_back(maxSharedHit); + } if (goodHits.size() != fakeHits.size()) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); } detectorConfig.maxHits = goodHits.size() - 1; - for (std::size_t i = 0; i < goodHits.size(); i++) { detectorConfig.factorHits.push_back(goodHits[i] / fakeHits[i]); } @@ -55,7 +76,6 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { } detectorConfig.maxHoles = goodHoles.size() - 1; - for (std::size_t i = 0; i < goodHoles.size(); i++) { detectorConfig.factorHoles.push_back(goodHoles[i] / fakeHoles[i]); } From 41dd332b8bdc9d51eaafb4d36d6f01d08df78af7 Mon Sep 17 00:00:00 2001 From: ragansu Date: Thu, 23 Jan 2025 18:12:18 +0100 Subject: [PATCH 12/27] lint fix --- .../AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index 38c55359440..2f74f4f3873 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -43,11 +43,12 @@ bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( } cutApplied = (trackFeatures.nHits <= getValueAtEta(detector.minHitsPerEta, - etaBins.size(), etaBin)) || - cutApplied; - cutApplied = (trackFeatures.nHoles >= getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || cutApplied; + cutApplied = + (trackFeatures.nHoles >= + getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || + cutApplied; cutApplied = (trackFeatures.nOutliers >= getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || From a8400d83920ebadf7c12753dc6b2d260b0ad42f8 Mon Sep 17 00:00:00 2001 From: ragansu Date: Fri, 24 Jan 2025 10:29:44 +0100 Subject: [PATCH 13/27] Fixed issue with json loaded, and shared hits eta cuts, --- .../ScoreBasedAmbiguityResolution.ipp | 23 +++++++++++++++++-- .../ScoreBasedAmbiguityResolution.cpp | 19 +++++++-------- .../Json/src/AmbiguityConfigJsonConverter.cpp | 7 ++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index 808d37e6602..ac889a98eb8 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -255,18 +255,25 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( // All cuts passed, now start scoring the track + std::cout << ", Score before Pt," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; // start with larger score for tracks with higher pT. score = std::log10(pT / UnitConstants::MeV) - 1.; // pT in GeV, hence 100 MeV is minimum and gets score = 1 ACTS_DEBUG("Modifier for pT = " << pT << " GeV is : " << score << " New score now: " << score); + std::cout << ", Score after Pt," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; + for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { const auto& detector = m_cfg.detectorConfigs.at(detectorId); const auto& trackFeatures = trackFeaturesVector[detectorId]; + std::cout << ", Score before detector " << detectorId << " Hits," << score + << ", pT, " << pT << ", eta, " << eta << std::endl; // choosing a scaling factor based on the number of hits in a track per // detector. std::size_t nHits = trackFeatures.nHits; @@ -279,6 +286,12 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " hits: " << detector.factorHits[nHits] << " New score now: " << score); + std::cout << ", Score after detector " << detectorId << " Hits," << score + << ", pT, " << pT << ", eta, " << eta << std::endl; + + std::cout << ", Score before detector " << detectorId << " Holes," + << score << ", pT, " << pT << ", eta, " << eta << std::endl; + // choosing a scaling factor based on the number of holes in a track per // detector. std::size_t iHoles = trackFeatures.nHoles; @@ -290,13 +303,17 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( ACTS_DEBUG("Modifier for " << iHoles << " holes: " << detector.factorHoles[iHoles] << " New score now: " << score); - ; + std::cout << ", Score after detector " << detectorId << " Holes," << score + << ", pT, " << pT << ", eta, " << eta << std::endl; } for (const auto& scoreFunction : optionalCuts.scores) { scoreFunction(track, score); } + std::cout << ", Score before chi2," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; + if (track.chi2() > 0 && track.nDoF() > 0) { double chi2 = track.chi2(); int indf = track.nDoF(); @@ -307,6 +324,8 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " New score now: " << score); } + std::cout << ", Score after chi2," << score << ", pT, " << pT << ", eta, " + << eta << std::endl; iTrack++; // Add the score to the vector @@ -404,7 +423,7 @@ std::vector Acts::ScoreBasedAmbiguityResolution::solveAmbiguity( } } - if (trackFeaturesVector[detectorId].nSharedHits < + if (trackFeaturesVector[detectorId].nSharedHits > getValueAtEta(detector.maxSharedHitsPerEta, etaBins.size(), etaBin)) { trkCouldBeAccepted = false; break; diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index 2f74f4f3873..8b558017abd 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -20,9 +20,9 @@ std::size_t Acts::ScoreBasedAmbiguityResolution::getValueAtEta( } else { - std::cerr - << "The size of minHits is not equal to 1 or the number of eta bins" - << std::endl; + std::cerr << "The size of cuts is not equal to 1 or the number of eta bins" + << " size of cuts: " << cuts.size() + << " number of eta bins: " << etaBinSize << std::endl; return 0; } } @@ -42,15 +42,16 @@ bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( } } - cutApplied = (trackFeatures.nHits <= getValueAtEta(detector.minHitsPerEta, + cutApplied = (trackFeatures.nHits < getValueAtEta(detector.minHitsPerEta, + etaBins.size(), etaBin)) || + cutApplied; + + cutApplied = (trackFeatures.nHoles > getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || cutApplied; + cutApplied = - (trackFeatures.nHoles >= - getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || - cutApplied; - cutApplied = - (trackFeatures.nOutliers >= + (trackFeatures.nOutliers > getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || cutApplied; diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index f7f2b683d22..fe086f9b90e 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -36,28 +36,33 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { const std::vector& fakeHoles = value["fakeHoles"]; const std::vector& etaBins = value["etaBins"]; + detectorConfig.etaBins = {}; for (auto etaBin : etaBins) { detectorConfig.etaBins.push_back(etaBin); } const std::vector& minHitsPerEta = value["minHitsPerEta"]; + detectorConfig.minHitsPerEta = {}; for (auto minHit : minHitsPerEta) { detectorConfig.minHitsPerEta.push_back(minHit); } const std::vector& maxHolesPerEta = value["maxHolesPerEta"]; + detectorConfig.maxHolesPerEta = {}; for (auto maxHole : maxHolesPerEta) { detectorConfig.maxHolesPerEta.push_back(maxHole); } const std::vector& maxOutliersPerEta = value["maxOutliersPerEta"]; + detectorConfig.maxOutliersPerEta = {}; for (auto maxOutlier : maxOutliersPerEta) { detectorConfig.maxOutliersPerEta.push_back(maxOutlier); } const std::vector& maxSharedHitsPerEta = value["maxSharedHitsPerEta"]; + detectorConfig.maxSharedHitsPerEta = {}; for (auto maxSharedHit : maxSharedHitsPerEta) { detectorConfig.maxSharedHitsPerEta.push_back(maxSharedHit); } @@ -66,6 +71,7 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); } + detectorConfig.factorHits = {}; detectorConfig.maxHits = goodHits.size() - 1; for (std::size_t i = 0; i < goodHits.size(); i++) { detectorConfig.factorHits.push_back(goodHits[i] / fakeHits[i]); @@ -75,6 +81,7 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { throw std::invalid_argument("goodHoles and FakeHoles size mismatch"); } + detectorConfig.factorHoles = {}; detectorConfig.maxHoles = goodHoles.size() - 1; for (std::size_t i = 0; i < goodHoles.size(); i++) { detectorConfig.factorHoles.push_back(goodHoles[i] / fakeHoles[i]); From ee233888e0d4c5ea759c5d27f521a1498474adae Mon Sep 17 00:00:00 2001 From: ragansu Date: Fri, 24 Jan 2025 11:16:43 +0100 Subject: [PATCH 14/27] minor change in minScore --- .../Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index ac889a98eb8..1dcc019633f 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -439,7 +439,7 @@ std::vector Acts::ScoreBasedAmbiguityResolution::solveAmbiguity( nTracksPerMeasurement, optionalHitSelections); if (trkCouldBeAccepted) { cleanTrackIndex++; - if (trackScore[iTrack] >= m_cfg.minScore) { + if (trackScore[iTrack] > m_cfg.minScore) { goodTracks.push_back(track.index()); } } From 5edccdcf23294c7f5e08cc13d6b7e7b0b837af5f Mon Sep 17 00:00:00 2001 From: ragansu Date: Sat, 25 Jan 2025 21:43:10 +0100 Subject: [PATCH 15/27] added minUnshared --- .../ScoreBasedAmbiguityResolution.hpp | 14 ++++++++------ .../ScoreBasedAmbiguityResolution.ipp | 2 +- .../ScoreBasedAmbiguityResolutionAlgorithm.hpp | 3 +++ .../src/ScoreBasedAmbiguityResolutionAlgorithm.cpp | 1 + .../Python/python/acts/examples/reconstruction.py | 4 +++- Examples/Python/src/AmbiguityResolution.cpp | 2 +- Examples/Scripts/Python/full_chain_odd.py | 1 + Examples/Scripts/Python/full_chain_odd_LRT.py | 1 + Examples/Scripts/Python/full_chain_test.py | 1 + .../ScoreBasedAmbiguityResolutionTest.cpp | 1 + 10 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index 4f7526e752d..30179d0458f 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -113,6 +113,9 @@ class ScoreBasedAmbiguityResolution { std::size_t maxSharedTracksPerMeasurement = 10; /// maximum number of shared hit per track std::size_t maxShared = 5; + /// minimum number of unshared hits per track + std::size_t minUnshared = 5; + // if true, the ambiguity score is computed based on a different function. bool useAmbiguityFunction = false; @@ -182,9 +185,9 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - bool etaBasedCuts(const DetectorConfig& detector, - const TrackFeatures& trackFeatures, - const double& eta) const; + bool etaBasedCuts( + const DetectorConfig& detector, const TrackFeatures& trackFeatures, + const double& eta) const; /// Remove hits that are not good enough for each track and removes tracks /// that have a score below a certain threshold or not enough hits. @@ -222,9 +225,8 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - static std::size_t getValueAtEta(std::vector cuts, - std::size_t etaBinSize, - std::size_t binIndex); + static std::size_t getValueAtEta(std::vector cuts, std::size_t etaBinSize, + std::size_t binIndex); private: Config m_cfg; diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index 1dcc019633f..d00c9da523c 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -554,7 +554,7 @@ bool Acts::ScoreBasedAmbiguityResolution::getCleanedOutTracks( } } // Check if the track has enough hits to be accepted. - if (newMeasurementsPerTrack.size() < 3) { + if (newMeasurementsPerTrack.size() < m_cfg.minUnshared) { return false; } else { return true; diff --git a/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp b/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp index fc39610345d..922f8c8ae8b 100644 --- a/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp +++ b/Examples/Algorithms/AmbiguityResolution/include/ActsExamples/AmbiguityResolution/ScoreBasedAmbiguityResolutionAlgorithm.hpp @@ -54,6 +54,9 @@ class ScoreBasedAmbiguityResolutionAlgorithm final : public IAlgorithm { // maximum number of shared hit per track std::size_t maxShared = 5; + // minimum number of unshared hits per track + std::size_t minUnshared = 5; + bool useAmbiguityFunction = false; }; diff --git a/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp b/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp index 3ac5b429206..d8b0c18688a 100644 --- a/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp +++ b/Examples/Algorithms/AmbiguityResolution/src/ScoreBasedAmbiguityResolutionAlgorithm.cpp @@ -44,6 +44,7 @@ Acts::ScoreBasedAmbiguityResolution::Config transformConfig( result.minScoreSharedTracks = cfg.minScoreSharedTracks; result.maxSharedTracksPerMeasurement = cfg.maxSharedTracksPerMeasurement; result.maxShared = cfg.maxShared; + result.minUnshared = cfg.minUnshared; result.useAmbiguityFunction = cfg.useAmbiguityFunction; return result; } diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index 2fc008bcef3..62d998a77e0 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -216,10 +216,11 @@ def trackSelectorDefaultKWArgs(c): "minScore", "minScoreSharedTracks", "maxShared", + 'minUnshared', "maxSharedTracksPerMeasurement", "useAmbiguityFunction", ], - defaults=[None] * 5, + defaults=[None] * 6, ) AmbiguityResolutionMLConfig = namedtuple( @@ -1941,6 +1942,7 @@ def addScoreBasedAmbiguityResolution( minScore=config.minScore, minScoreSharedTracks=config.minScoreSharedTracks, maxShared=config.maxShared, + minUnshared=config.minUnshared, maxSharedTracksPerMeasurement=config.maxSharedTracksPerMeasurement, useAmbiguityFunction=config.useAmbiguityFunction, ), diff --git a/Examples/Python/src/AmbiguityResolution.cpp b/Examples/Python/src/AmbiguityResolution.cpp index ecae082d67b..95d9a567054 100644 --- a/Examples/Python/src/AmbiguityResolution.cpp +++ b/Examples/Python/src/AmbiguityResolution.cpp @@ -33,7 +33,7 @@ void addAmbiguityResolution(Context& ctx) { ACTS_PYTHON_DECLARE_ALGORITHM( ActsExamples::ScoreBasedAmbiguityResolutionAlgorithm, mex, "ScoreBasedAmbiguityResolutionAlgorithm", inputTracks, configFile, - outputTracks, minScore, minScoreSharedTracks, maxShared, + outputTracks, minScore, minScoreSharedTracks, maxShared, minUnshared, maxSharedTracksPerMeasurement, useAmbiguityFunction); } diff --git a/Examples/Scripts/Python/full_chain_odd.py b/Examples/Scripts/Python/full_chain_odd.py index dadd87f5899..8b5a5a1b5d7 100755 --- a/Examples/Scripts/Python/full_chain_odd.py +++ b/Examples/Scripts/Python/full_chain_odd.py @@ -414,6 +414,7 @@ minScore=0, minScoreSharedTracks=1, maxShared=2, + minUnshared=3, maxSharedTracksPerMeasurement=2, useAmbiguityFunction=False, ), diff --git a/Examples/Scripts/Python/full_chain_odd_LRT.py b/Examples/Scripts/Python/full_chain_odd_LRT.py index bb92e93656b..7463b8f95b7 100644 --- a/Examples/Scripts/Python/full_chain_odd_LRT.py +++ b/Examples/Scripts/Python/full_chain_odd_LRT.py @@ -417,6 +417,7 @@ minScore=0, minScoreSharedTracks=1, maxShared=2, + minUnshared=3, maxSharedTracksPerMeasurement=2, useAmbiguityFunction=False, ), diff --git a/Examples/Scripts/Python/full_chain_test.py b/Examples/Scripts/Python/full_chain_test.py index 4905471becf..11504f4cd01 100755 --- a/Examples/Scripts/Python/full_chain_test.py +++ b/Examples/Scripts/Python/full_chain_test.py @@ -727,6 +727,7 @@ def full_chain(args): minScore=0, minScoreSharedTracks=1, maxShared=2, + minUnshared=3, maxSharedTracksPerMeasurement=2, useAmbiguityFunction=False, ), diff --git a/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp b/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp index 1b2eb55ca11..8a1f716ac45 100644 --- a/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp +++ b/Tests/UnitTests/Core/AmbiguityResolution/ScoreBasedAmbiguityResolutionTest.cpp @@ -48,6 +48,7 @@ struct Fixture { config.minScore = 0; config.minScoreSharedTracks = 100; config.maxShared = 5; + config.minUnshared = 3; config.maxSharedTracksPerMeasurement = 10; config.useAmbiguityFunction = false; } From 5f56dd45367ad7475647a81946eed2f457d77f2b Mon Sep 17 00:00:00 2001 From: ragansu Date: Sat, 25 Jan 2025 22:04:55 +0100 Subject: [PATCH 16/27] lint fix reco --- Examples/Python/python/acts/examples/reconstruction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index 62d998a77e0..9319599ca0a 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -216,7 +216,7 @@ def trackSelectorDefaultKWArgs(c): "minScore", "minScoreSharedTracks", "maxShared", - 'minUnshared', + "minUnshared", "maxSharedTracksPerMeasurement", "useAmbiguityFunction", ], From cf7c0331c73ba8dadeaaf3a7249f6a7089125721 Mon Sep 17 00:00:00 2001 From: ragansu Date: Sat, 25 Jan 2025 23:16:38 +0100 Subject: [PATCH 17/27] added sharedHItsFlag for detectors --- .../ScoreBasedAmbiguityResolution.hpp | 12 ++++++------ .../ScoreBasedAmbiguityResolution.ipp | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index 30179d0458f..db04f70d6db 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -116,7 +116,6 @@ class ScoreBasedAmbiguityResolution { /// minimum number of unshared hits per track std::size_t minUnshared = 5; - // if true, the ambiguity score is computed based on a different function. bool useAmbiguityFunction = false; }; @@ -185,9 +184,9 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - bool etaBasedCuts( - const DetectorConfig& detector, const TrackFeatures& trackFeatures, - const double& eta) const; + bool etaBasedCuts(const DetectorConfig& detector, + const TrackFeatures& trackFeatures, + const double& eta) const; /// Remove hits that are not good enough for each track and removes tracks /// that have a score below a certain threshold or not enough hits. @@ -225,8 +224,9 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - static std::size_t getValueAtEta(std::vector cuts, std::size_t etaBinSize, - std::size_t binIndex); + static std::size_t getValueAtEta(std::vector cuts, + std::size_t etaBinSize, + std::size_t binIndex); private: Config m_cfg; diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index d00c9da523c..dced2b89e3f 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -510,6 +510,18 @@ bool Acts::ScoreBasedAmbiguityResolution::getCleanedOutTracks( ACTS_DEBUG("Track state has no reference surface"); continue; } + + std::size_t ivolume = ts.referenceSurface().geometryId().volume(); + auto volume_it = m_cfg.volumeMap.find(ivolume); + if (volume_it == m_cfg.volumeMap.end()) { + ACTS_ERROR("Volume " << ivolume << "not found in the volume map"); + continue; + } + + std::size_t detectorID = volume_it->second; + + const auto& detector = m_cfg.detectorConfigs.at(detectorID); + measurement = measurementsPerTrack[index]; auto it = nTracksPerMeasurement.find(measurement); @@ -542,7 +554,8 @@ bool Acts::ScoreBasedAmbiguityResolution::getCleanedOutTracks( else { ACTS_DEBUG("Try to recover shared hit "); if (nTracksShared <= m_cfg.maxSharedTracksPerMeasurement && - trackScore > m_cfg.minScoreSharedTracks) { + trackScore > m_cfg.minScoreSharedTracks && + !detector.sharedHitsFlag) { ACTS_DEBUG("Accepted hit shared with " << nTracksShared << " tracks"); newMeasurementsPerTrack.push_back(measurement); nshared++; From f80adfa3a80a4d4cec5ee7653acf7381f4a3d054 Mon Sep 17 00:00:00 2001 From: ragansu Date: Tue, 28 Jan 2025 14:47:37 +0100 Subject: [PATCH 18/27] removed couts again --- .../ScoreBasedAmbiguityResolution.ipp | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index dced2b89e3f..6897b1f3aa8 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -255,25 +255,18 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( // All cuts passed, now start scoring the track - std::cout << ", Score before Pt," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; // start with larger score for tracks with higher pT. score = std::log10(pT / UnitConstants::MeV) - 1.; // pT in GeV, hence 100 MeV is minimum and gets score = 1 ACTS_DEBUG("Modifier for pT = " << pT << " GeV is : " << score << " New score now: " << score); - std::cout << ", Score after Pt," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; - for (std::size_t detectorId = 0; detectorId < m_cfg.detectorConfigs.size(); detectorId++) { const auto& detector = m_cfg.detectorConfigs.at(detectorId); const auto& trackFeatures = trackFeaturesVector[detectorId]; - std::cout << ", Score before detector " << detectorId << " Hits," << score - << ", pT, " << pT << ", eta, " << eta << std::endl; // choosing a scaling factor based on the number of hits in a track per // detector. std::size_t nHits = trackFeatures.nHits; @@ -286,12 +279,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " hits: " << detector.factorHits[nHits] << " New score now: " << score); - std::cout << ", Score after detector " << detectorId << " Hits," << score - << ", pT, " << pT << ", eta, " << eta << std::endl; - - std::cout << ", Score before detector " << detectorId << " Holes," - << score << ", pT, " << pT << ", eta, " << eta << std::endl; - // choosing a scaling factor based on the number of holes in a track per // detector. std::size_t iHoles = trackFeatures.nHoles; @@ -303,17 +290,12 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( ACTS_DEBUG("Modifier for " << iHoles << " holes: " << detector.factorHoles[iHoles] << " New score now: " << score); - std::cout << ", Score after detector " << detectorId << " Holes," << score - << ", pT, " << pT << ", eta, " << eta << std::endl; } for (const auto& scoreFunction : optionalCuts.scores) { scoreFunction(track, score); } - std::cout << ", Score before chi2," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; - if (track.chi2() > 0 && track.nDoF() > 0) { double chi2 = track.chi2(); int indf = track.nDoF(); @@ -324,8 +306,6 @@ std::vector Acts::ScoreBasedAmbiguityResolution::ambiguityScore( << " New score now: " << score); } - std::cout << ", Score after chi2," << score << ", pT, " << pT << ", eta, " - << eta << std::endl; iTrack++; // Add the score to the vector From ee0a36af2dcaf433bfa7c5c5a45dd6e939a37768 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 11:19:14 +0100 Subject: [PATCH 19/27] Error handling + doc --- .../ScoreBasedAmbiguityResolution.hpp | 21 +++++++++- .../ScoreBasedAmbiguityResolution.cpp | 40 ++++++------------- .../Json/src/AmbiguityConfigJsonConverter.cpp | 18 +++++++-- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index db04f70d6db..5bf48648f30 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -51,12 +51,19 @@ class ScoreBasedAmbiguityResolution { int outliersScoreWeight = 0; int otherScoreWeight = 0; - // the minimum number of hits for each detector for each eta bin + // the eta bins for the detector std::vector etaBins = {-5, 5}; + // the minimum number of hits for each detector for each eta bin std::vector minHitsPerEta = {0}; + + // the maximum number of holes for each detector for each eta bin std::vector maxHolesPerEta = {0}; + + // the maximum number of outliers for each detector for each eta bin std::vector maxOutliersPerEta = {0}; + + // the maximum number of shared hits for each detector for each eta bin std::vector maxSharedHitsPerEta = {0}; std::size_t maxHits = 0; @@ -184,6 +191,12 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; + /// Rejects Tracks based on eta dependent cuts. + /// + /// @param track is the input track + /// @param trackFeatures is the trackFeatures object for a specific detector + /// @param eta is the eta of the track + /// @return true if the track is rejected, false otherwise bool etaBasedCuts(const DetectorConfig& detector, const TrackFeatures& trackFeatures, const double& eta) const; @@ -224,6 +237,12 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; + /// Get the value at a specific eta bin. + /// + /// @param cuts is the input vector of cuts + /// @param etaBinSize is the size of the eta bin + /// @param binIndex is the index of the bin + /// @return the value of cut at the specific eta bin static std::size_t getValueAtEta(std::vector cuts, std::size_t etaBinSize, std::size_t binIndex); diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index 8b558017abd..d34448e9037 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -20,10 +20,9 @@ std::size_t Acts::ScoreBasedAmbiguityResolution::getValueAtEta( } else { - std::cerr << "The size of cuts is not equal to 1 or the number of eta bins" - << " size of cuts: " << cuts.size() - << " number of eta bins: " << etaBinSize << std::endl; - return 0; + throw std::invalid_argument("Invalid cuts size. Expected 1 or " + + std::to_string(etaBinSize - 1) + ", got " + + std::to_string(cuts.size())); } } @@ -31,29 +30,16 @@ bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( const DetectorConfig& detector, const TrackFeatures& trackFeatures, const double& eta) const { std::vector etaBins = detector.etaBins; - int etaBin = 0; - bool cutApplied = false; - - for (std::size_t i = 0; i < etaBins.size() - 1; ++i) { - if (eta >= etaBins[i] && eta < etaBins[i + 1]) { - etaBin = i; - break; - } + auto it = std::upper_bound(etaBins.begin(), etaBins.end(), eta); + if (it == etaBins.begin() || it == etaBins.end()) { + return false; // eta out of range } - - cutApplied = (trackFeatures.nHits < getValueAtEta(detector.minHitsPerEta, - etaBins.size(), etaBin)) || - cutApplied; - - cutApplied = (trackFeatures.nHoles > getValueAtEta(detector.maxHolesPerEta, - etaBins.size(), etaBin)) || - cutApplied; - - cutApplied = - (trackFeatures.nOutliers > - getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)) || - cutApplied; - - return cutApplied; + std::size_t etaBin = std::distance(etaBins.begin(), it) - 1; + return (trackFeatures.nHits < + getValueAtEta(detector.minHitsPerEta, etaBins.size(), etaBin)) || + (trackFeatures.nHoles > + getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || + (trackFeatures.nOutliers > + getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)); } diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index fe086f9b90e..f97c6875795 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -36,11 +36,21 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { const std::vector& fakeHoles = value["fakeHoles"]; const std::vector& etaBins = value["etaBins"]; - detectorConfig.etaBins = {}; - for (auto etaBin : etaBins) { - detectorConfig.etaBins.push_back(etaBin); - } + // Validate eta bins + if (!etaBins.empty()) { + // Verify monotonically increasing eta bins + if (!std::is_sorted(etaBins.begin(), etaBins.end())) { + throw std::invalid_argument( + "Eta bins must be monotonically increasing"); + } + + detectorConfig.etaBins = {}; + for (auto etaBin : etaBins) { + detectorConfig.etaBins.push_back(etaBin); + } + } + const std::vector& minHitsPerEta = value["minHitsPerEta"]; detectorConfig.minHitsPerEta = {}; for (auto minHit : minHitsPerEta) { From 541f3f74cad57d64c7afe5d7b3796aababa3a672 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 11:38:07 +0100 Subject: [PATCH 20/27] fixed doc issue --- .../Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index 5bf48648f30..d97d140e098 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -193,7 +193,7 @@ class ScoreBasedAmbiguityResolution { /// Rejects Tracks based on eta dependent cuts. /// - /// @param track is the input track + /// @param detector is the detector configuration object /// @param trackFeatures is the trackFeatures object for a specific detector /// @param eta is the eta of the track /// @return true if the track is rejected, false otherwise From 3cf3136ff9889429a18ef42a733cdfd430848fd6 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 12:48:45 +0100 Subject: [PATCH 21/27] updated the etabased cuts initialization --- .../Json/src/AmbiguityConfigJsonConverter.cpp | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index f97c6875795..40bf0d1aeb5 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -11,6 +11,13 @@ #include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp" #include "Acts/Plugins/Json/ActsJson.hpp" +void initializeEtaVector(std::vector& target, + const std::vector& source) { + target = {}; + for (auto value : source) { + target.push_back(value); + } +} namespace Acts { void from_json(const nlohmann::json& j, ConfigPair& p) { @@ -50,32 +57,20 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { detectorConfig.etaBins.push_back(etaBin); } } - + const std::vector& minHitsPerEta = value["minHitsPerEta"]; - detectorConfig.minHitsPerEta = {}; - for (auto minHit : minHitsPerEta) { - detectorConfig.minHitsPerEta.push_back(minHit); - } + initializeEtaVector(detectorConfig.minHitsPerEta, minHitsPerEta); const std::vector& maxHolesPerEta = value["maxHolesPerEta"]; - detectorConfig.maxHolesPerEta = {}; - for (auto maxHole : maxHolesPerEta) { - detectorConfig.maxHolesPerEta.push_back(maxHole); - } + initializeEtaVector(detectorConfig.maxHolesPerEta, maxHolesPerEta); const std::vector& maxOutliersPerEta = value["maxOutliersPerEta"]; - detectorConfig.maxOutliersPerEta = {}; - for (auto maxOutlier : maxOutliersPerEta) { - detectorConfig.maxOutliersPerEta.push_back(maxOutlier); - } + initializeEtaVector(detectorConfig.maxOutliersPerEta, maxOutliersPerEta); const std::vector& maxSharedHitsPerEta = value["maxSharedHitsPerEta"]; - detectorConfig.maxSharedHitsPerEta = {}; - for (auto maxSharedHit : maxSharedHitsPerEta) { - detectorConfig.maxSharedHitsPerEta.push_back(maxSharedHit); - } + initializeEtaVector(detectorConfig.maxSharedHitsPerEta, maxSharedHitsPerEta); if (goodHits.size() != fakeHits.size()) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); From b75d2b2a48745d636d8727ae7e7e3af253ea9abc Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 12:54:19 +0100 Subject: [PATCH 22/27] lint fix --- Plugins/Json/src/AmbiguityConfigJsonConverter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index 40bf0d1aeb5..c1fc1d7f4b0 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -12,7 +12,7 @@ #include "Acts/Plugins/Json/ActsJson.hpp" void initializeEtaVector(std::vector& target, - const std::vector& source) { + const std::vector& source) { target = {}; for (auto value : source) { target.push_back(value); @@ -70,7 +70,8 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { const std::vector& maxSharedHitsPerEta = value["maxSharedHitsPerEta"]; - initializeEtaVector(detectorConfig.maxSharedHitsPerEta, maxSharedHitsPerEta); + initializeEtaVector(detectorConfig.maxSharedHitsPerEta, + maxSharedHitsPerEta); if (goodHits.size() != fakeHits.size()) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); From ed378313fbe4f8bfa93a329441e3bf22b3bb22d5 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 18:31:33 +0100 Subject: [PATCH 23/27] updated etabased cuts for efficiency and easy validation --- .../ScoreBasedAmbiguityResolution.hpp | 10 ------- .../ScoreBasedAmbiguityResolution.ipp | 2 +- .../ScoreBasedAmbiguityResolution.cpp | 27 +++---------------- .../Json/src/AmbiguityConfigJsonConverter.cpp | 16 ++++++++--- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp index d97d140e098..1753e21bc23 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp @@ -237,16 +237,6 @@ class ScoreBasedAmbiguityResolution { const OptionalCuts& optionalCuts = {}) const; - /// Get the value at a specific eta bin. - /// - /// @param cuts is the input vector of cuts - /// @param etaBinSize is the size of the eta bin - /// @param binIndex is the index of the bin - /// @return the value of cut at the specific eta bin - static std::size_t getValueAtEta(std::vector cuts, - std::size_t etaBinSize, - std::size_t binIndex); - private: Config m_cfg; diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index 6897b1f3aa8..91a4af14214 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -404,7 +404,7 @@ std::vector Acts::ScoreBasedAmbiguityResolution::solveAmbiguity( } if (trackFeaturesVector[detectorId].nSharedHits > - getValueAtEta(detector.maxSharedHitsPerEta, etaBins.size(), etaBin)) { + detector.maxSharedHitsPerEta[etaBin]) { trkCouldBeAccepted = false; break; } diff --git a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp index d34448e9037..41cc6a9aeb5 100644 --- a/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp +++ b/Core/src/AmbiguityResolution/ScoreBasedAmbiguityResolution.cpp @@ -8,24 +8,6 @@ #include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp" -std::size_t Acts::ScoreBasedAmbiguityResolution::getValueAtEta( - std::vector cuts, std::size_t etaBinSize, - std::size_t binIndex) { - if (cuts.size() == etaBinSize - 1) { - return cuts[binIndex]; - } - - else if (cuts.size() == 1) { - return cuts[0]; - } - - else { - throw std::invalid_argument("Invalid cuts size. Expected 1 or " + - std::to_string(etaBinSize - 1) + ", got " + - std::to_string(cuts.size())); - } -} - bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( const DetectorConfig& detector, const TrackFeatures& trackFeatures, const double& eta) const { @@ -36,10 +18,7 @@ bool Acts::ScoreBasedAmbiguityResolution::etaBasedCuts( return false; // eta out of range } std::size_t etaBin = std::distance(etaBins.begin(), it) - 1; - return (trackFeatures.nHits < - getValueAtEta(detector.minHitsPerEta, etaBins.size(), etaBin)) || - (trackFeatures.nHoles > - getValueAtEta(detector.maxHolesPerEta, etaBins.size(), etaBin)) || - (trackFeatures.nOutliers > - getValueAtEta(detector.maxOutliersPerEta, etaBins.size(), etaBin)); + return (trackFeatures.nHits < detector.minHitsPerEta[etaBin] || + trackFeatures.nHoles > detector.maxHolesPerEta[etaBin] || + trackFeatures.nOutliers > detector.maxOutliersPerEta[etaBin]); } diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index c1fc1d7f4b0..d89470f506e 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -12,10 +12,18 @@ #include "Acts/Plugins/Json/ActsJson.hpp" void initializeEtaVector(std::vector& target, - const std::vector& source) { - target = {}; - for (auto value : source) { - target.push_back(value); + const std::vector& source, + int etaBinSize) { + if (source.size() == etaBinSize - 1) { + target = source; // Directly copy if sizes match + } else if (source.size() == 1) { + target.resize(etaBinSize - 1); // Resize target to the required size + std::fill(target.begin(), target.end(), + source[0]); // Fill with the single value from source + } else { + throw std::invalid_argument("Invalid cuts size. Expected 1 or " + + std::to_string(etaBinSize - 1) + ", got " + + std::to_string(source.size())); } } namespace Acts { From b432c54ce3695842f138b03271fbdc46fd6edce0 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 19:14:23 +0100 Subject: [PATCH 24/27] fixed issues with initializeEtaVector --- Plugins/Json/src/AmbiguityConfigJsonConverter.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index d89470f506e..4c591c11732 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -67,19 +67,22 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { } const std::vector& minHitsPerEta = value["minHitsPerEta"]; - initializeEtaVector(detectorConfig.minHitsPerEta, minHitsPerEta); + initializeEtaVector(detectorConfig.minHitsPerEta, minHitsPerEta, + detectorConfig.etaBins.size()); const std::vector& maxHolesPerEta = value["maxHolesPerEta"]; - initializeEtaVector(detectorConfig.maxHolesPerEta, maxHolesPerEta); + initializeEtaVector(detectorConfig.maxHolesPerEta, maxHolesPerEta, + detectorConfig.etaBins.size()); const std::vector& maxOutliersPerEta = value["maxOutliersPerEta"]; - initializeEtaVector(detectorConfig.maxOutliersPerEta, maxOutliersPerEta); + initializeEtaVector(detectorConfig.maxOutliersPerEta, maxOutliersPerEta, + detectorConfig.etaBins.size()); const std::vector& maxSharedHitsPerEta = value["maxSharedHitsPerEta"]; - initializeEtaVector(detectorConfig.maxSharedHitsPerEta, - maxSharedHitsPerEta); + initializeEtaVector(detectorConfig.maxSharedHitsPerEta, maxSharedHitsPerEta, + detectorConfig.etaBins.size()); if (goodHits.size() != fakeHits.size()) { throw std::invalid_argument("goodHits and FakeHits size mismatch"); From 2a372119e8576ae51f704b6ceeb0e4b37446bf5a Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 19:33:43 +0100 Subject: [PATCH 25/27] switched linear search with binary search --- .../ScoreBasedAmbiguityResolution.ipp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp index 91a4af14214..6dc116dda23 100644 --- a/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp +++ b/Core/include/Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.ipp @@ -394,14 +394,9 @@ std::vector Acts::ScoreBasedAmbiguityResolution::solveAmbiguity( auto detector = m_cfg.detectorConfigs.at(detectorId); std::vector etaBins = detector.etaBins; - int etaBin = 0; - for (std::size_t i = 0; i < detector.etaBins.size() - 1; ++i) { - if (eta >= etaBins[i] && eta < detector.etaBins[i + 1]) { - etaBin = i; - break; - } - } + auto it = std::upper_bound(etaBins.begin(), etaBins.end(), eta); + std::size_t etaBin = std::distance(etaBins.begin(), it) - 1; if (trackFeaturesVector[detectorId].nSharedHits > detector.maxSharedHitsPerEta[etaBin]) { From babb8230a8af06ef4cc0dfce037dcf584ad96e09 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 19:57:25 +0100 Subject: [PATCH 26/27] fixing signess issue --- Plugins/Json/src/AmbiguityConfigJsonConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index 4c591c11732..406a4f4437a 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -13,7 +13,7 @@ void initializeEtaVector(std::vector& target, const std::vector& source, - int etaBinSize) { + std::size_t etaBinSize) { if (source.size() == etaBinSize - 1) { target = source; // Directly copy if sizes match } else if (source.size() == 1) { From 0c77316028453289df6de9f414069509ede1a5d8 Mon Sep 17 00:00:00 2001 From: ragansu Date: Wed, 29 Jan 2025 20:08:49 +0100 Subject: [PATCH 27/27] direct assignment for etaBins --- Plugins/Json/src/AmbiguityConfigJsonConverter.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp index 406a4f4437a..b6c9a9999d8 100644 --- a/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp +++ b/Plugins/Json/src/AmbiguityConfigJsonConverter.cpp @@ -60,10 +60,7 @@ void from_json(const nlohmann::json& j, ConfigPair& p) { "Eta bins must be monotonically increasing"); } - detectorConfig.etaBins = {}; - for (auto etaBin : etaBins) { - detectorConfig.etaBins.push_back(etaBin); - } + detectorConfig.etaBins = etaBins; } const std::vector& minHitsPerEta = value["minHitsPerEta"];