From 5e8efd662189ef54fddbd328c535309a97d4c857 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Sat, 7 Dec 2024 00:58:52 +0100 Subject: [PATCH] refactor: Remove `SurfaceSortingAlgorithm` from Examples (#3952) In https://github.com/acts-project/acts/pull/3944 we found out that this algorithm is not needed anymore ## Summary by CodeRabbit - **New Features** - Enhanced configurability for machine learning-based seed filtering with the addition of an ONNX model parameter. - Streamlined seeding and track fitting algorithms for improved modularity. - **Bug Fixes** - Removed unnecessary complexity by eliminating the `directNavigation` parameter from multiple functions. - **Documentation** - Updated test suite to improve clarity and maintainability. - **Chores** - Removed obsolete files and references related to the `SurfaceSortingAlgorithm` class to streamline the codebase. --- .../Algorithms/TrackFitting/CMakeLists.txt | 1 - .../TrackFitting/SurfaceSortingAlgorithm.hpp | 55 ------------ .../src/SurfaceSortingAlgorithm.cpp | 84 ------------------- .../python/acts/examples/reconstruction.py | 12 --- Examples/Python/src/TrackFitting.cpp | 17 ---- Examples/Python/tests/root_file_hashes.txt | 24 ++---- Examples/Python/tests/test_algorithms.py | 2 - Examples/Python/tests/test_examples.py | 4 +- .../Scripts/Python/truth_tracking_kalman.py | 2 - 9 files changed, 9 insertions(+), 192 deletions(-) delete mode 100644 Examples/Algorithms/TrackFitting/include/ActsExamples/TrackFitting/SurfaceSortingAlgorithm.hpp delete mode 100644 Examples/Algorithms/TrackFitting/src/SurfaceSortingAlgorithm.cpp diff --git a/Examples/Algorithms/TrackFitting/CMakeLists.txt b/Examples/Algorithms/TrackFitting/CMakeLists.txt index 07e26091384..a6a9a5afe3b 100644 --- a/Examples/Algorithms/TrackFitting/CMakeLists.txt +++ b/Examples/Algorithms/TrackFitting/CMakeLists.txt @@ -2,7 +2,6 @@ add_library( ActsExamplesTrackFitting SHARED src/RefittingCalibrator.cpp - src/SurfaceSortingAlgorithm.cpp src/TrackFittingAlgorithm.cpp src/KalmanFitterFunction.cpp src/RefittingAlgorithm.cpp diff --git a/Examples/Algorithms/TrackFitting/include/ActsExamples/TrackFitting/SurfaceSortingAlgorithm.hpp b/Examples/Algorithms/TrackFitting/include/ActsExamples/TrackFitting/SurfaceSortingAlgorithm.hpp deleted file mode 100644 index 6315e192e67..00000000000 --- a/Examples/Algorithms/TrackFitting/include/ActsExamples/TrackFitting/SurfaceSortingAlgorithm.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/EventData/Measurement.hpp" -#include "ActsExamples/EventData/ProtoTrack.hpp" -#include "ActsExamples/EventData/SimHit.hpp" -#include "ActsExamples/Framework/DataHandle.hpp" -#include "ActsExamples/Framework/IAlgorithm.hpp" -#include "ActsExamples/Framework/ProcessCode.hpp" - -#include - -namespace ActsExamples { - -class SurfaceSortingAlgorithm final : public IAlgorithm { - public: - struct Config { - /// Input proto track collection - std::string inputProtoTracks; - /// Input simulated hit collection - std::string inputSimHits; - /// Input measurement to simulated hit map for truth position - std::string inputMeasurementSimHitsMap; - /// Output proto track collection - std::string outputProtoTracks; - }; - - SurfaceSortingAlgorithm(Config cfg, Acts::Logging::Level level); - - ActsExamples::ProcessCode execute(const AlgorithmContext& ctx) const final; - - /// Get readonly access to the config parameters - const Config& config() const { return m_cfg; } - - private: - Config m_cfg; - - ReadDataHandle m_inputProtoTracks{this, - "InputProtoTracks"}; - ReadDataHandle m_inputSimHits{this, "InputSimHits"}; - ReadDataHandle m_inputMeasurementSimHitsMap{ - this, "InputMeasurementSimHitsMap"}; - WriteDataHandle m_outputProtoTracks{this, - "OutputProtoTracks"}; -}; - -} // namespace ActsExamples diff --git a/Examples/Algorithms/TrackFitting/src/SurfaceSortingAlgorithm.cpp b/Examples/Algorithms/TrackFitting/src/SurfaceSortingAlgorithm.cpp deleted file mode 100644 index 57a79ab2db0..00000000000 --- a/Examples/Algorithms/TrackFitting/src/SurfaceSortingAlgorithm.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#include "ActsExamples/TrackFitting/SurfaceSortingAlgorithm.hpp" - -#include "ActsExamples/EventData/ProtoTrack.hpp" -#include "ActsFatras/EventData/Hit.hpp" - -#include -#include -#include -#include - -namespace ActsExamples { - -SurfaceSortingAlgorithm::SurfaceSortingAlgorithm(Config cfg, - Acts::Logging::Level level) - : IAlgorithm("SurfaceSortingAlgorithm", level), m_cfg(std::move(cfg)) { - if (m_cfg.inputProtoTracks.empty()) { - throw std::invalid_argument("Missing input proto track collection"); - } - if (m_cfg.inputSimHits.empty()) { - throw std::invalid_argument("Missing input simulated hits collection"); - } - if (m_cfg.inputMeasurementSimHitsMap.empty()) { - throw std::invalid_argument("Missing input measurement sim hits map"); - } - if (m_cfg.outputProtoTracks.empty()) { - throw std::invalid_argument("Missing output proto track collection"); - } - - m_inputProtoTracks.initialize(m_cfg.inputProtoTracks); - m_inputSimHits.initialize(m_cfg.inputSimHits); - m_inputMeasurementSimHitsMap.initialize(m_cfg.inputMeasurementSimHitsMap); - m_outputProtoTracks.initialize(m_cfg.outputProtoTracks); -} - -ProcessCode SurfaceSortingAlgorithm::execute( - const AlgorithmContext& ctx) const { - const auto& protoTracks = m_inputProtoTracks(ctx); - const auto& simHits = m_inputSimHits(ctx); - const auto& simHitsMap = m_inputMeasurementSimHitsMap(ctx); - - ProtoTrackContainer sortedTracks; - sortedTracks.reserve(protoTracks.size()); - std::map trackHitList; - - for (std::size_t itrack = 0; itrack < protoTracks.size(); ++itrack) { - const auto& protoTrack = protoTracks[itrack]; - - ProtoTrack sortedProtoTrack; - sortedProtoTrack.reserve(protoTrack.size()); - trackHitList.clear(); - - if (protoTrack.empty()) { - continue; - } - - for (const auto hit : protoTrack) { - const auto simHitIndex = simHitsMap.find(hit)->second; - auto simHit = simHits.nth(simHitIndex); - auto simHitTime = simHit->time(); - trackHitList.insert(std::make_pair(simHitTime, hit)); - } - - /// Map will now be sorted by truth hit time - for (auto const& [time, hit] : trackHitList) { - sortedProtoTrack.emplace_back(hit); - } - - sortedTracks.emplace_back(std::move(sortedProtoTrack)); - } - - m_outputProtoTracks(ctx, std::move(sortedTracks)); - - return ProcessCode::SUCCESS; -} - -} // namespace ActsExamples diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index 43792827e8d..0e30961fe39 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -1288,7 +1288,6 @@ def addKalmanTracks( s: acts.examples.Sequencer, trackingGeometry: acts.TrackingGeometry, field: acts.MagneticFieldProvider, - directNavigation: bool = False, reverseFilteringMomThreshold: float = 0 * u.GeV, inputProtoTracks: str = "truth_particle_tracks", multipleScattering: bool = True, @@ -1299,17 +1298,6 @@ def addKalmanTracks( ) -> None: customLogLevel = acts.examples.defaultLogging(s, logLevel) - if directNavigation: - srfSortAlg = acts.examples.SurfaceSortingAlgorithm( - level=customLogLevel(), - inputProtoTracks=inputProtoTracks, - inputSimHits="simhits", - inputMeasurementSimHitsMap="measurement_simhits_map", - outputProtoTracks="sorted_truth_particle_tracks", - ) - s.addAlgorithm(srfSortAlg) - inputProtoTracks = srfSortAlg.config.outputProtoTracks - kalmanOptions = { "multipleScattering": multipleScattering, "energyLoss": energyLoss, diff --git a/Examples/Python/src/TrackFitting.cpp b/Examples/Python/src/TrackFitting.cpp index c8dc72f9eef..6d1b9818e51 100644 --- a/Examples/Python/src/TrackFitting.cpp +++ b/Examples/Python/src/TrackFitting.cpp @@ -6,35 +6,23 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp" #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/TrackFitting/BetheHeitlerApprox.hpp" #include "Acts/TrackFitting/GsfOptions.hpp" #include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/EventData/Cluster.hpp" #include "ActsExamples/EventData/MeasurementCalibration.hpp" #include "ActsExamples/EventData/ScalingCalibrator.hpp" #include "ActsExamples/TrackFitting/RefittingAlgorithm.hpp" -#include "ActsExamples/TrackFitting/SurfaceSortingAlgorithm.hpp" #include "ActsExamples/TrackFitting/TrackFitterFunction.hpp" #include "ActsExamples/TrackFitting/TrackFittingAlgorithm.hpp" #include #include -#include #include #include -namespace Acts { -class MagneticFieldProvider; -class TrackingGeometry; -} // namespace Acts -namespace ActsExamples { -class IAlgorithm; -} // namespace ActsExamples - namespace py = pybind11; using namespace ActsExamples; @@ -46,11 +34,6 @@ namespace Acts::Python { void addTrackFitting(Context& ctx) { auto mex = ctx.get("examples"); - ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::SurfaceSortingAlgorithm, mex, - "SurfaceSortingAlgorithm", inputProtoTracks, - inputSimHits, inputMeasurementSimHitsMap, - outputProtoTracks); - ACTS_PYTHON_DECLARE_ALGORITHM( ActsExamples::TrackFittingAlgorithm, mex, "TrackFittingAlgorithm", inputMeasurements, inputProtoTracks, inputInitialTrackParameters, diff --git a/Examples/Python/tests/root_file_hashes.txt b/Examples/Python/tests/root_file_hashes.txt index e1b2833c2eb..07d42c66ad1 100644 --- a/Examples/Python/tests/root_file_hashes.txt +++ b/Examples/Python/tests/root_file_hashes.txt @@ -78,19 +78,11 @@ test_refitting[odd]__trackstates_gsf_refit.root: e297749dc1e7eda3b8dea13defa0499 test_refitting[odd]__tracksummary_gsf_refit.root: d5085882e45a0b699194dff9f40a36e9291227bf65f9aaaf9087f9242ef5ae22 test_refitting[generic]__trackstates_gsf_refit.root: 4424fdf2f27575db825c1a59f8e53a1595946211cbd5b2c8d3a2f71cdcc77ae9 test_refitting[generic]__tracksummary_gsf_refit.root: 562deecee4cfb97ceee72eff53d63da079e3249fb62d6bcd556e6f27d495dfd9 -test_truth_tracking_kalman[generic-False-0.0]__trackstates_kf.root: 9f77962b92037cb760b1629a602b1dae61f45e659c45d9a87baa784f6190960e -test_truth_tracking_kalman[generic-False-0.0]__tracksummary_kf.root: 562deecee4cfb97ceee72eff53d63da079e3249fb62d6bcd556e6f27d495dfd9 -test_truth_tracking_kalman[generic-False-1000.0]__trackstates_kf.root: 56a1bd989b9c1316b9098c65fa75df9e6683e62e35ae68d8f72d27220be0fd7d -test_truth_tracking_kalman[generic-False-1000.0]__tracksummary_kf.root: 2d85be3a5dff01a1076e80f8c225aca32f65b30dc9c3551b610ac2f12d006a39 -test_truth_tracking_kalman[generic-True-0.0]__trackstates_kf.root: 9f77962b92037cb760b1629a602b1dae61f45e659c45d9a87baa784f6190960e -test_truth_tracking_kalman[generic-True-0.0]__tracksummary_kf.root: 562deecee4cfb97ceee72eff53d63da079e3249fb62d6bcd556e6f27d495dfd9 -test_truth_tracking_kalman[generic-True-1000.0]__trackstates_kf.root: 56a1bd989b9c1316b9098c65fa75df9e6683e62e35ae68d8f72d27220be0fd7d -test_truth_tracking_kalman[generic-True-1000.0]__tracksummary_kf.root: 2d85be3a5dff01a1076e80f8c225aca32f65b30dc9c3551b610ac2f12d006a39 -test_truth_tracking_kalman[odd-False-0.0]__trackstates_kf.root: 7e144571b19aaf00002aef4f5bec5d488b96fb9ed8e1b2904c3756b31be83513 -test_truth_tracking_kalman[odd-False-0.0]__tracksummary_kf.root: d5085882e45a0b699194dff9f40a36e9291227bf65f9aaaf9087f9242ef5ae22 -test_truth_tracking_kalman[odd-False-1000.0]__trackstates_kf.root: efdf37f56fa3ef85265cda61853f4c0f989e3d4f4745b5e351c9bcca78cd93cc -test_truth_tracking_kalman[odd-False-1000.0]__tracksummary_kf.root: b84fabd6c1b71c360019cd719400746ccff1e565a983ca23d0621790b8843e44 -test_truth_tracking_kalman[odd-True-0.0]__trackstates_kf.root: 7e144571b19aaf00002aef4f5bec5d488b96fb9ed8e1b2904c3756b31be83513 -test_truth_tracking_kalman[odd-True-0.0]__tracksummary_kf.root: d5085882e45a0b699194dff9f40a36e9291227bf65f9aaaf9087f9242ef5ae22 -test_truth_tracking_kalman[odd-True-1000.0]__trackstates_kf.root: efdf37f56fa3ef85265cda61853f4c0f989e3d4f4745b5e351c9bcca78cd93cc -test_truth_tracking_kalman[odd-True-1000.0]__tracksummary_kf.root: b84fabd6c1b71c360019cd719400746ccff1e565a983ca23d0621790b8843e44 +test_truth_tracking_kalman[generic-0.0]__trackstates_kf.root: 9f77962b92037cb760b1629a602b1dae61f45e659c45d9a87baa784f6190960e +test_truth_tracking_kalman[generic-0.0]__tracksummary_kf.root: 562deecee4cfb97ceee72eff53d63da079e3249fb62d6bcd556e6f27d495dfd9 +test_truth_tracking_kalman[generic-1000.0]__trackstates_kf.root: 56a1bd989b9c1316b9098c65fa75df9e6683e62e35ae68d8f72d27220be0fd7d +test_truth_tracking_kalman[generic-1000.0]__tracksummary_kf.root: 2d85be3a5dff01a1076e80f8c225aca32f65b30dc9c3551b610ac2f12d006a39 +test_truth_tracking_kalman[odd-0.0]__trackstates_kf.root: 7e144571b19aaf00002aef4f5bec5d488b96fb9ed8e1b2904c3756b31be83513 +test_truth_tracking_kalman[odd-0.0]__tracksummary_kf.root: d5085882e45a0b699194dff9f40a36e9291227bf65f9aaaf9087f9242ef5ae22 +test_truth_tracking_kalman[odd-1000.0]__trackstates_kf.root: efdf37f56fa3ef85265cda61853f4c0f989e3d4f4745b5e351c9bcca78cd93cc +test_truth_tracking_kalman[odd-1000.0]__tracksummary_kf.root: b84fabd6c1b71c360019cd719400746ccff1e565a983ca23d0621790b8843e44 diff --git a/Examples/Python/tests/test_algorithms.py b/Examples/Python/tests/test_algorithms.py index 6311dc6460a..0f1e1f01a61 100644 --- a/Examples/Python/tests/test_algorithms.py +++ b/Examples/Python/tests/test_algorithms.py @@ -17,7 +17,6 @@ TrackParameterSmearing, TrackSelectorAlgorithm, TrackFittingAlgorithm, - SurfaceSortingAlgorithm, ParticlesPrinter, TrackParametersPrinter, PropagationAlgorithm, @@ -47,7 +46,6 @@ TrackParameterSmearing, TrackSelectorAlgorithm, TrackFittingAlgorithm, - SurfaceSortingAlgorithm, ParticlesPrinter, TrackParametersPrinter, PropagationAlgorithm, diff --git a/Examples/Python/tests/test_examples.py b/Examples/Python/tests/test_examples.py index 8441514c26b..daf40b6685a 100644 --- a/Examples/Python/tests/test_examples.py +++ b/Examples/Python/tests/test_examples.py @@ -579,9 +579,8 @@ def test_event_recording(tmp_path): @pytest.mark.parametrize("revFiltMomThresh", [0 * u.GeV, 1 * u.TeV]) -@pytest.mark.parametrize("directNavigation", [False, True]) def test_truth_tracking_kalman( - tmp_path, assert_root_hash, revFiltMomThresh, directNavigation, detector_config + tmp_path, assert_root_hash, revFiltMomThresh, detector_config ): root_files = [ ("trackstates_kf.root", "trackstates", 19), @@ -607,7 +606,6 @@ def test_truth_tracking_kalman( digiConfigFile=detector_config.digiConfigFile, outputDir=tmp_path, reverseFilteringMomThreshold=revFiltMomThresh, - directNavigation=directNavigation, s=seq, ) diff --git a/Examples/Scripts/Python/truth_tracking_kalman.py b/Examples/Scripts/Python/truth_tracking_kalman.py index 971f0c4bab4..3b857fd41da 100755 --- a/Examples/Scripts/Python/truth_tracking_kalman.py +++ b/Examples/Scripts/Python/truth_tracking_kalman.py @@ -17,7 +17,6 @@ def runTruthTrackingKalman( inputParticlePath: Optional[Path] = None, inputHitsPath: Optional[Path] = None, decorators=[], - directNavigation=False, reverseFilteringMomThreshold=0 * u.GeV, s: acts.examples.Sequencer = None, ): @@ -122,7 +121,6 @@ def runTruthTrackingKalman( s, trackingGeometry, field, - directNavigation, reverseFilteringMomThreshold, )