Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-16 08:04:25

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::BoundSquareMatrix;
0037 using Jacobian = Acts::BoundMatrix;
0038 
0039 constexpr double tol = 1e-6;
0040 const Acts::GeometryContext tgContext;
0041 
0042 }  // namespace
0043 
0044 namespace ActsTests {
0045 
0046 BOOST_AUTO_TEST_SUITE(TrackFittingSuite)
0047 
0048 BOOST_AUTO_TEST_CASE(Update) {
0049   // Make dummy measurement
0050   Vector2 measPar(-0.1, 0.45);
0051   SquareMatrix2 measCov = Vector2(0.04, 0.1).asDiagonal();
0052   auto sourceLink = TestSourceLink(eBoundLoc0, eBoundLoc1, measPar, measCov);
0053 
0054   // Make dummy track parameters
0055   ParametersVector trkPar;
0056   trkPar << 0.3, 0.5, std::numbers::pi / 2., 0.3 * std::numbers::pi, 0.01, 0.;
0057   CovarianceMatrix trkCov = CovarianceMatrix::Zero();
0058   trkCov.diagonal() << 0.08, 0.3, 1, 1, 1, 0;
0059 
0060   // Make trajectory w/ one state
0061   VectorMultiTrajectory traj;
0062   auto idx = traj.addTrackState(TrackStatePropMask::All);
0063   auto ts = traj.getTrackState(idx);
0064 
0065   // Fill the state w/ the dummy information
0066   ts.predicted() = trkPar;
0067   ts.predictedCovariance() = trkCov;
0068   ts.pathLength() = 0.;
0069   BOOST_CHECK(!ts.hasUncalibratedSourceLink());
0070   testSourceLinkCalibrator<VectorMultiTrajectory>(
0071       tgContext, CalibrationContext{}, SourceLink{std::move(sourceLink)}, ts);
0072   BOOST_CHECK(ts.hasUncalibratedSourceLink());
0073 
0074   // Check that the state has storage available
0075   BOOST_CHECK(ts.hasPredicted());
0076   BOOST_CHECK(ts.hasFiltered());
0077   BOOST_CHECK(ts.hasCalibrated());
0078 
0079   // Gain matrix update and filtered state
0080   BOOST_CHECK(GainMatrixUpdater()
0081                   .operator()<VectorMultiTrajectory>(tgContext, ts)
0082                   .ok());
0083 
0084   // Check for regression. This does NOT test if the math is correct, just that
0085   // the result is the same as when the test was written.
0086 
0087   ParametersVector expPar;
0088   expPar << 0.0333333, 0.4625000, 1.5707963, 0.9424778, 0.0100000, 0.0000000;
0089   CHECK_CLOSE_ABS(ts.filtered(), expPar, tol);
0090 
0091   CovarianceMatrix expCov = CovarianceMatrix::Zero();
0092   expCov.diagonal() << 0.0266667, 0.0750000, 1.0000000, 1.0000000, 1.0000000,
0093       0.0000000;
0094   CHECK_CLOSE_ABS(ts.filteredCovariance(), expCov, tol);
0095 
0096   CHECK_CLOSE_ABS(ts.chi2(), 1.33958, 1e-4);
0097 }
0098 
0099 BOOST_AUTO_TEST_CASE(UpdateFailed) {
0100   // Make dummy measurement
0101   Vector2 measPar(-0.1, 0.45);
0102   SquareMatrix2 measCov = SquareMatrix2::Zero();
0103   auto sourceLink = TestSourceLink(eBoundLoc0, eBoundLoc1, measPar, measCov);
0104 
0105   // Make dummy track parameters
0106   ParametersVector trkPar;
0107   trkPar << 0.3, 0.5, std::numbers::pi / 2., 0.3 * std::numbers::pi, 0.01, 0.;
0108   CovarianceMatrix trkCov = CovarianceMatrix::Zero();
0109 
0110   // Make trajectory w/ one state
0111   VectorMultiTrajectory traj;
0112   auto idx = traj.addTrackState(TrackStatePropMask::All);
0113   auto ts = traj.getTrackState(idx);
0114 
0115   // Fill the state w/ the dummy information
0116   ts.predicted() = trkPar;
0117   ts.predictedCovariance() = trkCov;
0118   ts.pathLength() = 0.;
0119   BOOST_CHECK(!ts.hasUncalibratedSourceLink());
0120   testSourceLinkCalibrator<VectorMultiTrajectory>(
0121       tgContext, CalibrationContext{}, SourceLink{std::move(sourceLink)}, ts);
0122   BOOST_CHECK(ts.hasUncalibratedSourceLink());
0123 
0124   // Check that the state has storage available
0125   BOOST_CHECK(ts.hasPredicted());
0126   BOOST_CHECK(ts.hasFiltered());
0127   BOOST_CHECK(ts.hasCalibrated());
0128 
0129   // Gain matrix update and filtered state
0130   BOOST_CHECK(GainMatrixUpdater()
0131                   .operator()<VectorMultiTrajectory>(tgContext, ts)
0132                   .error() == KalmanFitterError::UpdateFailed);
0133 }
0134 
0135 BOOST_AUTO_TEST_SUITE_END()
0136 
0137 }  // namespace ActsTests