Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:54

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