From a1b701dc6d1e206c5af6d8873be40fd19ba04e64 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 17 Dec 2024 18:20:37 +0100 Subject: [PATCH 1/3] feat: Allow trimming other non measurements states --- Core/include/Acts/Utilities/TrackHelpers.hpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Core/include/Acts/Utilities/TrackHelpers.hpp b/Core/include/Acts/Utilities/TrackHelpers.hpp index dc3765be7f6..365bf48cdba 100644 --- a/Core/include/Acts/Utilities/TrackHelpers.hpp +++ b/Core/include/Acts/Utilities/TrackHelpers.hpp @@ -412,9 +412,10 @@ void calculateTrackQuantities(track_proxy_t track) /// @param trimHoles whether to trim holes /// @param trimOutliers whether to trim outliers /// @param trimMaterial whether to trim pure material states +/// @param trimOther whether to trim other, non measurement, states template void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial) + bool trimMaterial, bool trimOther = false) requires(!track_proxy_t::ReadOnly) { using TrackStateProxy = typename track_proxy_t::TrackStateProxy; @@ -435,6 +436,9 @@ void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, !typeFlags.test(TrackStateFlag::MeasurementFlag)) { continue; } + if (trimOther && !typeFlags.test(TrackStateFlag::MeasurementFlag)) { + continue; + } front = trackState; } @@ -450,9 +454,10 @@ void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, /// @param trimHoles whether to trim holes /// @param trimOutliers whether to trim outliers /// @param trimMaterial whether to trim pure material states +/// @param trimOther whether to trim other, non measurement, states template void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial) + bool trimMaterial, bool trimOther = false) requires(!track_proxy_t::ReadOnly) { using TrackStateProxy = typename track_proxy_t::TrackStateProxy; @@ -473,6 +478,9 @@ void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, !typeFlags.test(TrackStateFlag::MeasurementFlag)) { continue; } + if (trimOther && !typeFlags.test(TrackStateFlag::MeasurementFlag)) { + continue; + } break; } @@ -488,13 +496,14 @@ void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, /// @param trimHoles whether to trim holes /// @param trimOutliers whether to trim outliers /// @param trimMaterial whether to trim pure material states +/// @param trimOther whether to trim other, non measurement, states template void trimTrack(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial) + bool trimMaterial, bool trimOther = false) requires(!track_proxy_t::ReadOnly) { - trimTrackFront(track, trimHoles, trimOutliers, trimMaterial); - trimTrackBack(track, trimHoles, trimOutliers, trimMaterial); + trimTrackFront(track, trimHoles, trimOutliers, trimMaterial, trimOther); + trimTrackBack(track, trimHoles, trimOutliers, trimMaterial, trimOther); } /// Helper function to calculate the predicted residual and its covariance From be47d9eef68441bfe023bed46eaefc9eea1be563 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Wed, 18 Dec 2024 10:00:09 +0100 Subject: [PATCH 2/3] test; break --- Core/include/Acts/Utilities/TrackHelpers.hpp | 6 +++--- .../TrackFinding/src/TrackFindingAlgorithm.cpp | 2 +- Tests/UnitTests/Core/Utilities/TrackHelpersTests.cpp | 12 +++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Core/include/Acts/Utilities/TrackHelpers.hpp b/Core/include/Acts/Utilities/TrackHelpers.hpp index 365bf48cdba..2b222374ee5 100644 --- a/Core/include/Acts/Utilities/TrackHelpers.hpp +++ b/Core/include/Acts/Utilities/TrackHelpers.hpp @@ -415,7 +415,7 @@ void calculateTrackQuantities(track_proxy_t track) /// @param trimOther whether to trim other, non measurement, states template void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial, bool trimOther = false) + bool trimMaterial, bool trimOther) requires(!track_proxy_t::ReadOnly) { using TrackStateProxy = typename track_proxy_t::TrackStateProxy; @@ -457,7 +457,7 @@ void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, /// @param trimOther whether to trim other, non measurement, states template void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial, bool trimOther = false) + bool trimMaterial, bool trimOther) requires(!track_proxy_t::ReadOnly) { using TrackStateProxy = typename track_proxy_t::TrackStateProxy; @@ -499,7 +499,7 @@ void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, /// @param trimOther whether to trim other, non measurement, states template void trimTrack(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial, bool trimOther = false) + bool trimMaterial, bool trimOther) requires(!track_proxy_t::ReadOnly) { trimTrackFront(track, trimHoles, trimOutliers, trimMaterial, trimOther); diff --git a/Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp index b1ef900c5b9..53b47a86d07 100644 --- a/Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp @@ -421,7 +421,7 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const { // trim the track if requested if (m_cfg.trimTracks) { - Acts::trimTrack(track, true, true, true); + Acts::trimTrack(track, true, true, true, true); } Acts::calculateTrackQuantities(track); diff --git a/Tests/UnitTests/Core/Utilities/TrackHelpersTests.cpp b/Tests/UnitTests/Core/Utilities/TrackHelpersTests.cpp index c08cbd5455d..adc33d2168d 100644 --- a/Tests/UnitTests/Core/Utilities/TrackHelpersTests.cpp +++ b/Tests/UnitTests/Core/Utilities/TrackHelpersTests.cpp @@ -89,6 +89,7 @@ BOOST_AUTO_TEST_CASE(CalculateQuantities) { BOOST_AUTO_TEST_CASE(TrimTrack) { TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}}; auto t = createTestTrack(tc, std::vector>{ + {}, {HoleFlag}, {MeasurementFlag}, {OutlierFlag}, @@ -98,34 +99,39 @@ BOOST_AUTO_TEST_CASE(TrimTrack) { {HoleFlag}, {MeasurementFlag}, {OutlierFlag}, + {}, }); calculateTrackQuantities(t); + BOOST_CHECK_EQUAL(t.nTrackStates(), 11); BOOST_CHECK_EQUAL(t.nHoles(), 3); BOOST_CHECK_EQUAL(t.nMeasurements(), 3); BOOST_CHECK_EQUAL(t.nOutliers(), 3); BOOST_CHECK_EQUAL(t.nSharedHits(), 1); - trimTrackFront(t, true, true, true); + trimTrackFront(t, true, true, true, true); calculateTrackQuantities(t); + BOOST_CHECK_EQUAL(t.nTrackStates(), 9); BOOST_CHECK_EQUAL(t.nHoles(), 2); BOOST_CHECK_EQUAL(t.nMeasurements(), 3); BOOST_CHECK_EQUAL(t.nOutliers(), 3); BOOST_CHECK_EQUAL(t.nSharedHits(), 1); - trimTrackBack(t, true, true, true); + trimTrackBack(t, true, true, true, true); calculateTrackQuantities(t); + BOOST_CHECK_EQUAL(t.nTrackStates(), 7); BOOST_CHECK_EQUAL(t.nHoles(), 2); BOOST_CHECK_EQUAL(t.nMeasurements(), 3); BOOST_CHECK_EQUAL(t.nOutliers(), 2); BOOST_CHECK_EQUAL(t.nSharedHits(), 1); - trimTrack(t, true, true, true); + trimTrack(t, true, true, true, true); calculateTrackQuantities(t); + BOOST_CHECK_EQUAL(t.nTrackStates(), 7); BOOST_CHECK_EQUAL(t.nHoles(), 2); BOOST_CHECK_EQUAL(t.nMeasurements(), 3); BOOST_CHECK_EQUAL(t.nOutliers(), 2); From b8ce8e9ad49c367c73b11a1ba493caaa640cf8d9 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Wed, 8 Jan 2025 16:30:02 +0100 Subject: [PATCH 3/3] trimOtherNoneMeasurement --- Core/include/Acts/Utilities/TrackHelpers.hpp | 50 +++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/Core/include/Acts/Utilities/TrackHelpers.hpp b/Core/include/Acts/Utilities/TrackHelpers.hpp index 2b222374ee5..f8c61135502 100644 --- a/Core/include/Acts/Utilities/TrackHelpers.hpp +++ b/Core/include/Acts/Utilities/TrackHelpers.hpp @@ -412,10 +412,10 @@ void calculateTrackQuantities(track_proxy_t track) /// @param trimHoles whether to trim holes /// @param trimOutliers whether to trim outliers /// @param trimMaterial whether to trim pure material states -/// @param trimOther whether to trim other, non measurement, states +/// @param trimOtherNoneMeasurement whether to trim other, non measurement, states template void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial, bool trimOther) + bool trimMaterial, bool trimOtherNoneMeasurement) requires(!track_proxy_t::ReadOnly) { using TrackStateProxy = typename track_proxy_t::TrackStateProxy; @@ -426,17 +426,23 @@ void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, for (TrackStateProxy trackState : track.trackStatesReversed()) { TrackStateType typeFlags = trackState.typeFlags(); - if (trimHoles && typeFlags.test(TrackStateFlag::HoleFlag)) { + bool isHole = typeFlags.test(TrackStateFlag::HoleFlag); + bool isOutlier = typeFlags.test(TrackStateFlag::OutlierFlag); + bool isMaterial = typeFlags.test(TrackStateFlag::MaterialFlag) && + !typeFlags.test(TrackStateFlag::MeasurementFlag); + bool isOtherNoneMeasurement = + !typeFlags.test(TrackStateFlag::MeasurementFlag) && !isHole && + !isOutlier && !isMaterial; + if (trimHoles && isHole) { continue; } - if (trimOutliers && typeFlags.test(TrackStateFlag::OutlierFlag)) { + if (trimOutliers && isOutlier) { continue; } - if (trimMaterial && typeFlags.test(TrackStateFlag::MaterialFlag) && - !typeFlags.test(TrackStateFlag::MeasurementFlag)) { + if (trimMaterial && isMaterial) { continue; } - if (trimOther && !typeFlags.test(TrackStateFlag::MeasurementFlag)) { + if (trimOtherNoneMeasurement && isOtherNoneMeasurement) { continue; } @@ -454,10 +460,10 @@ void trimTrackFront(track_proxy_t track, bool trimHoles, bool trimOutliers, /// @param trimHoles whether to trim holes /// @param trimOutliers whether to trim outliers /// @param trimMaterial whether to trim pure material states -/// @param trimOther whether to trim other, non measurement, states +/// @param trimOtherNoneMeasurement whether to trim other, non measurement, states template void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial, bool trimOther) + bool trimMaterial, bool trimOtherNoneMeasurement) requires(!track_proxy_t::ReadOnly) { using TrackStateProxy = typename track_proxy_t::TrackStateProxy; @@ -468,17 +474,23 @@ void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, back = trackState; TrackStateType typeFlags = trackState.typeFlags(); - if (trimHoles && typeFlags.test(TrackStateFlag::HoleFlag)) { + bool isHole = typeFlags.test(TrackStateFlag::HoleFlag); + bool isOutlier = typeFlags.test(TrackStateFlag::OutlierFlag); + bool isMaterial = typeFlags.test(TrackStateFlag::MaterialFlag) && + !typeFlags.test(TrackStateFlag::MeasurementFlag); + bool isOtherNoneMeasurement = + !typeFlags.test(TrackStateFlag::MeasurementFlag) && !isHole && + !isOutlier && !isMaterial; + if (trimHoles && isHole) { continue; } - if (trimOutliers && typeFlags.test(TrackStateFlag::OutlierFlag)) { + if (trimOutliers && isOutlier) { continue; } - if (trimMaterial && typeFlags.test(TrackStateFlag::MaterialFlag) && - !typeFlags.test(TrackStateFlag::MeasurementFlag)) { + if (trimMaterial && isMaterial) { continue; } - if (trimOther && !typeFlags.test(TrackStateFlag::MeasurementFlag)) { + if (trimOtherNoneMeasurement && isOtherNoneMeasurement) { continue; } @@ -496,14 +508,16 @@ void trimTrackBack(track_proxy_t track, bool trimHoles, bool trimOutliers, /// @param trimHoles whether to trim holes /// @param trimOutliers whether to trim outliers /// @param trimMaterial whether to trim pure material states -/// @param trimOther whether to trim other, non measurement, states +/// @param trimOtherNoneMeasurement whether to trim other, non measurement, states template void trimTrack(track_proxy_t track, bool trimHoles, bool trimOutliers, - bool trimMaterial, bool trimOther) + bool trimMaterial, bool trimOtherNoneMeasurement) requires(!track_proxy_t::ReadOnly) { - trimTrackFront(track, trimHoles, trimOutliers, trimMaterial, trimOther); - trimTrackBack(track, trimHoles, trimOutliers, trimMaterial, trimOther); + trimTrackFront(track, trimHoles, trimOutliers, trimMaterial, + trimOtherNoneMeasurement); + trimTrackBack(track, trimHoles, trimOutliers, trimMaterial, + trimOtherNoneMeasurement); } /// Helper function to calculate the predicted residual and its covariance