Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-15 07:39:50

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/EventData/MultiTrajectory.hpp"
0014 #include "Acts/EventData/SourceLink.hpp"
0015 #include "Acts/EventData/TrackStatePropMask.hpp"
0016 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0017 #include "Acts/EventData/detail/TestSourceLink.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/TrackFitting/GainMatrixUpdater.hpp"
0020 #include "Acts/TrackFitting/KalmanFitterError.hpp"
0021 #include "Acts/Utilities/CalibrationContext.hpp"
0022 #include "Acts/Utilities/Result.hpp"
0023 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0024 
0025 #include <algorithm>
0026 #include <cmath>
0027 #include <numbers>
0028 #include <utility>
0029 
0030 namespace {
0031 
0032 using namespace Acts;
0033 using namespace Acts::detail::Test;
0034 
0035 using ParametersVector = Acts::BoundVector;
0036 using CovarianceMatrix = Acts::BoundMatrix;
0037 using Jacobian = Acts::BoundMatrix;
0038 
0039 constexpr double tol = 1e-6;
0040 const Acts::GeometryContext tgContext =
0041     Acts::GeometryContext::dangerouslyDefaultConstruct();
0042 
0043 }  // namespace
0044 
0045 namespace ActsTests {
0046 
0047 BOOST_AUTO_TEST_SUITE(TrackFittingSuite)
0048 
0049 BOOST_AUTO_TEST_CASE(Update) {
0050   // Make dummy measurement
0051   Vector2 measPar(-0.1, 0.45);
0052   SquareMatrix2 measCov = Vector2(0.04, 0.1).asDiagonal();
0053   auto sourceLink = TestSourceLink(eBoundLoc0, eBoundLoc1, measPar, measCov);
0054 
0055   // Make dummy track parameters
0056   ParametersVector trkPar;
0057   trkPar << 0.3, 0.5, std::numbers::pi / 2., 0.3 * std::numbers::pi, 0.01, 0.;
0058   CovarianceMatrix trkCov = CovarianceMatrix::Zero();
0059   trkCov.diagonal() << 0.08, 0.3, 1, 1, 1, 0;
0060 
0061   // Make trajectory w/ one state
0062   VectorMultiTrajectory traj;
0063   auto idx = traj.addTrackState(TrackStatePropMask::All);
0064   auto ts = traj.getTrackState(idx);
0065 
0066   // Fill the state w/ the dummy information
0067   ts.predicted() = trkPar;
0068   ts.predictedCovariance() = trkCov;
0069   ts.pathLength() = 0.;
0070   BOOST_CHECK(!ts.hasUncalibratedSourceLink());
0071   testSourceLinkCalibrator<VectorMultiTrajectory>(
0072       tgContext, CalibrationContext{}, SourceLink{std::move(sourceLink)}, ts);
0073   BOOST_CHECK(ts.hasUncalibratedSourceLink());
0074 
0075   // Check that the state has storage available
0076   BOOST_CHECK(ts.hasPredicted());
0077   BOOST_CHECK(ts.hasFiltered());
0078   BOOST_CHECK(ts.hasCalibrated());
0079 
0080   // Gain matrix update and filtered state
0081   BOOST_CHECK(GainMatrixUpdater()
0082                   .operator()<VectorMultiTrajectory>(tgContext, ts)
0083                   .ok());
0084 
0085   // Check for regression. This does NOT test if the math is correct, just that
0086   // the result is the same as when the test was written.
0087 
0088   ParametersVector expPar;
0089   expPar << 0.0333333, 0.4625000, 1.5707963, 0.9424778, 0.0100000, 0.0000000;
0090   CHECK_CLOSE_ABS(ts.filtered(), expPar, tol);
0091 
0092   CovarianceMatrix expCov = CovarianceMatrix::Zero();
0093   expCov.diagonal() << 0.0266667, 0.0750000, 1.0000000, 1.0000000, 1.0000000,
0094       0.0000000;
0095   CHECK_CLOSE_ABS(ts.filteredCovariance(), expCov, tol);
0096 
0097   CHECK_CLOSE_ABS(ts.chi2(), 1.33958, 1e-4);
0098 }
0099 
0100 BOOST_AUTO_TEST_CASE(UpdateFailed) {
0101   // Make dummy measurement
0102   Vector2 measPar(-0.1, 0.45);
0103   SquareMatrix2 measCov = SquareMatrix2::Zero();
0104   auto sourceLink = TestSourceLink(eBoundLoc0, eBoundLoc1, measPar, measCov);
0105 
0106   // Make dummy track parameters
0107   ParametersVector trkPar;
0108   trkPar << 0.3, 0.5, std::numbers::pi / 2., 0.3 * std::numbers::pi, 0.01, 0.;
0109   CovarianceMatrix trkCov = CovarianceMatrix::Zero();
0110 
0111   // Make trajectory w/ one state
0112   VectorMultiTrajectory traj;
0113   auto idx = traj.addTrackState(TrackStatePropMask::All);
0114   auto ts = traj.getTrackState(idx);
0115 
0116   // Fill the state w/ the dummy information
0117   ts.predicted() = trkPar;
0118   ts.predictedCovariance() = trkCov;
0119   ts.pathLength() = 0.;
0120   BOOST_CHECK(!ts.hasUncalibratedSourceLink());
0121   testSourceLinkCalibrator<VectorMultiTrajectory>(
0122       tgContext, CalibrationContext{}, SourceLink{std::move(sourceLink)}, ts);
0123   BOOST_CHECK(ts.hasUncalibratedSourceLink());
0124 
0125   // Check that the state has storage available
0126   BOOST_CHECK(ts.hasPredicted());
0127   BOOST_CHECK(ts.hasFiltered());
0128   BOOST_CHECK(ts.hasCalibrated());
0129 
0130   // Gain matrix update and filtered state
0131   BOOST_CHECK(GainMatrixUpdater()
0132                   .operator()<VectorMultiTrajectory>(tgContext, ts)
0133                   .error() == KalmanFitterError::UpdateFailed);
0134 }
0135 
0136 BOOST_AUTO_TEST_SUITE_END()
0137 
0138 }  // namespace ActsTests