File indexing completed on 2025-08-06 08:11:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/EventData/GenericCurvilinearTrackParameters.hpp"
0016 #include "Acts/EventData/MultiTrajectory.hpp"
0017 #include "Acts/EventData/TrackParameters.hpp"
0018 #include "Acts/EventData/TrackStatePropMask.hpp"
0019 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0020 #include "Acts/EventData/detail/TestSourceLink.hpp"
0021 #include "Acts/Propagator/EigenStepper.hpp"
0022 #include "Acts/Propagator/Navigator.hpp"
0023 #include "Acts/Propagator/Propagator.hpp"
0024 #include "Acts/Propagator/StraightLineStepper.hpp"
0025 #include "Acts/Tests/CommonHelpers/LineSurfaceStub.hpp"
0026 #include "Acts/TrackFitting/GainMatrixSmoother.hpp"
0027 #include "Acts/TrackFitting/GainMatrixUpdater.hpp"
0028 #include "Acts/TrackFitting/KalmanFitter.hpp"
0029 #include "Acts/Utilities/Delegate.hpp"
0030 #include "Acts/Utilities/Logger.hpp"
0031
0032 #include <algorithm>
0033 #include <functional>
0034 #include <map>
0035 #include <memory>
0036 #include <optional>
0037 #include <random>
0038 #include <utility>
0039
0040 #include "FitterTestsCommon.hpp"
0041
0042 namespace {
0043
0044 using namespace Acts;
0045 using namespace Acts::Test;
0046 using namespace Acts::detail::Test;
0047 using namespace Acts::UnitLiterals;
0048
0049 using StraightPropagator =
0050 Acts::Propagator<Acts::StraightLineStepper, Acts::Navigator>;
0051 using ConstantFieldStepper = Acts::EigenStepper<>;
0052 using ConstantFieldPropagator =
0053 Acts::Propagator<ConstantFieldStepper, Acts::Navigator>;
0054
0055 using KalmanUpdater = Acts::GainMatrixUpdater;
0056 using KalmanSmoother = Acts::GainMatrixSmoother;
0057 using KalmanFitter =
0058 Acts::KalmanFitter<ConstantFieldPropagator, VectorMultiTrajectory>;
0059
0060 static const auto pion = Acts::ParticleHypothesis::pion();
0061
0062 KalmanUpdater kfUpdater;
0063 KalmanSmoother kfSmoother;
0064
0065
0066 Acts::CurvilinearTrackParameters makeParameters() {
0067
0068 Acts::BoundVector stddev;
0069 stddev[Acts::eBoundLoc0] = 100_um;
0070 stddev[Acts::eBoundLoc1] = 100_um;
0071 stddev[Acts::eBoundTime] = 25_ns;
0072 stddev[Acts::eBoundPhi] = 2_degree;
0073 stddev[Acts::eBoundTheta] = 2_degree;
0074 stddev[Acts::eBoundQOverP] = 1 / 100_GeV;
0075 Acts::BoundSquareMatrix cov = stddev.cwiseProduct(stddev).asDiagonal();
0076
0077 Acts::Vector4 mPos4(-3_m, 0., 0., 42_ns);
0078 return Acts::CurvilinearTrackParameters(mPos4, 0_degree, 90_degree,
0079 1_e / 1_GeV, cov, pion);
0080 }
0081
0082
0083 const FitterTester tester;
0084
0085
0086 auto kfLogger = getDefaultLogger("KalmanFilter", Logging::INFO);
0087 const auto kfZeroPropagator =
0088 makeConstantFieldPropagator<ConstantFieldStepper>(tester.geometry, 0_T);
0089 const auto kfZero = KalmanFitter(kfZeroPropagator, std::move(kfLogger));
0090
0091 std::default_random_engine rng(42);
0092
0093 auto makeDefaultKalmanFitterOptions() {
0094 KalmanFitterExtensions<VectorMultiTrajectory> extensions;
0095 extensions.calibrator
0096 .connect<&testSourceLinkCalibrator<VectorMultiTrajectory>>();
0097 extensions.updater.connect<&KalmanUpdater::operator()<VectorMultiTrajectory>>(
0098 &kfUpdater);
0099 extensions.smoother
0100 .connect<&KalmanSmoother::operator()<VectorMultiTrajectory>>(&kfSmoother);
0101 extensions.surfaceAccessor.connect<
0102 &Acts::detail::Test::TestSourceLink::SurfaceAccessor::operator()>(
0103 &tester.surfaceAccessor);
0104
0105 return KalmanFitterOptions(tester.geoCtx, tester.magCtx, tester.calCtx,
0106 extensions, PropagatorPlainOptions());
0107 }
0108
0109 }
0110
0111 BOOST_AUTO_TEST_SUITE(TrackFittingKalmanFitter)
0112
0113 BOOST_AUTO_TEST_CASE(ZeroFieldNoSurfaceForward) {
0114 auto start = makeParameters();
0115 auto kfOptions = makeDefaultKalmanFitterOptions();
0116
0117 bool expected_reversed = false;
0118 bool expected_smoothed = true;
0119 tester.test_ZeroFieldNoSurfaceForward(kfZero, kfOptions, start, rng,
0120 expected_reversed, expected_smoothed,
0121 true);
0122 }
0123
0124 BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceForward) {
0125 auto start = makeParameters();
0126 auto kfOptions = makeDefaultKalmanFitterOptions();
0127
0128
0129 kfOptions.reversedFiltering = false;
0130 bool expected_reversed = false;
0131 bool expected_smoothed = true;
0132 tester.test_ZeroFieldWithSurfaceForward(kfZero, kfOptions, start, rng,
0133 expected_reversed, expected_smoothed,
0134 true);
0135
0136
0137 kfOptions.reversedFiltering = true;
0138 kfOptions.reversedFilteringCovarianceScaling = 100.0;
0139 expected_reversed = true;
0140 expected_smoothed = false;
0141 tester.test_ZeroFieldWithSurfaceForward(kfZero, kfOptions, start, rng,
0142 expected_reversed, expected_smoothed,
0143 true);
0144 }
0145
0146 BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceBackward) {
0147 auto start = makeParameters();
0148 auto kfOptions = makeDefaultKalmanFitterOptions();
0149
0150
0151 kfOptions.reversedFiltering = false;
0152 bool expected_reversed = false;
0153 bool expected_smoothed = true;
0154 tester.test_ZeroFieldWithSurfaceBackward(kfZero, kfOptions, start, rng,
0155 expected_reversed, expected_smoothed,
0156 true);
0157
0158
0159 kfOptions.reversedFiltering = true;
0160 kfOptions.reversedFilteringCovarianceScaling = 100.0;
0161 expected_reversed = true;
0162 expected_smoothed = false;
0163 tester.test_ZeroFieldWithSurfaceBackward(kfZero, kfOptions, start, rng,
0164 expected_reversed, expected_smoothed,
0165 true);
0166 }
0167
0168 BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceAtExit) {
0169 auto start = makeParameters();
0170 auto kfOptions = makeDefaultKalmanFitterOptions();
0171
0172 bool expected_reversed = false;
0173 bool expected_smoothed = true;
0174 tester.test_ZeroFieldWithSurfaceAtExit(kfZero, kfOptions, start, rng,
0175 expected_reversed, expected_smoothed,
0176 true);
0177 }
0178
0179 BOOST_AUTO_TEST_CASE(ZeroFieldShuffled) {
0180 auto start = makeParameters();
0181 auto kfOptions = makeDefaultKalmanFitterOptions();
0182
0183 bool expected_reversed = false;
0184 bool expected_smoothed = true;
0185 tester.test_ZeroFieldShuffled(kfZero, kfOptions, start, rng,
0186 expected_reversed, expected_smoothed, true);
0187 }
0188
0189 BOOST_AUTO_TEST_CASE(ZeroFieldWithHole) {
0190 auto start = makeParameters();
0191 auto kfOptions = makeDefaultKalmanFitterOptions();
0192
0193 bool expected_reversed = false;
0194 bool expected_smoothed = true;
0195 tester.test_ZeroFieldWithHole(kfZero, kfOptions, start, rng,
0196 expected_reversed, expected_smoothed, true);
0197 }
0198
0199 BOOST_AUTO_TEST_CASE(ZeroFieldWithOutliers) {
0200 auto start = makeParameters();
0201
0202
0203
0204 auto kfOptions = makeDefaultKalmanFitterOptions();
0205
0206 TestOutlierFinder tof{5_mm};
0207 kfOptions.extensions.outlierFinder
0208 .connect<&TestOutlierFinder::operator()<VectorMultiTrajectory>>(&tof);
0209
0210 bool expected_reversed = false;
0211 bool expected_smoothed = true;
0212 tester.test_ZeroFieldWithOutliers(kfZero, kfOptions, start, rng,
0213 expected_reversed, expected_smoothed, true);
0214 }
0215
0216 BOOST_AUTO_TEST_CASE(ZeroFieldWithReverseFiltering) {
0217 auto start = makeParameters();
0218
0219 auto test = [&](double threshold, bool reverse, bool expected_reversed,
0220 bool expected_smoothed) {
0221 auto kfOptions = makeDefaultKalmanFitterOptions();
0222
0223 TestReverseFilteringLogic trfl{threshold};
0224 kfOptions.extensions.reverseFilteringLogic
0225 .connect<&TestReverseFilteringLogic::operator()<VectorMultiTrajectory>>(
0226 &trfl);
0227
0228 kfOptions.reversedFiltering = reverse;
0229 kfOptions.reversedFilteringCovarianceScaling = 100.0;
0230
0231 tester.test_ZeroFieldWithReverseFiltering(kfZero, kfOptions, start, rng,
0232 expected_reversed,
0233 expected_smoothed, true);
0234 };
0235
0236
0237
0238 test(0.1_GeV, false, false, true);
0239
0240
0241
0242 test(10._GeV, false, true, false);
0243
0244
0245
0246 test(0.1_GeV, true, true, false);
0247 }
0248
0249
0250
0251 BOOST_AUTO_TEST_CASE(GlobalCovariance) {
0252 auto start = makeParameters();
0253 auto kfOptions = makeDefaultKalmanFitterOptions();
0254
0255 tester.test_GlobalCovariance(kfZero, kfOptions, start, rng);
0256 }
0257
0258 BOOST_AUTO_TEST_SUITE_END()