Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:30

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019-2020 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 http://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/TrackStatePropMask.hpp"
0015 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0018 #include "Acts/TrackFitting/GainMatrixSmoother.hpp"
0019 #include "Acts/Utilities/Result.hpp"
0020 
0021 #include <cmath>
0022 #include <cstddef>
0023 
0024 namespace {
0025 
0026 using namespace Acts;
0027 using namespace Acts::Test;
0028 
0029 using ParametersVector = Acts::BoundVector;
0030 using CovarianceMatrix = Acts::BoundSquareMatrix;
0031 using Jacobian = Acts::BoundMatrix;
0032 
0033 const Acts::GeometryContext tgContext;
0034 
0035 }  // namespace
0036 
0037 BOOST_AUTO_TEST_SUITE(TrackFittingGainMatrixSmoother)
0038 
0039 BOOST_AUTO_TEST_CASE(Smooth) {
0040   VectorMultiTrajectory traj;
0041   std::size_t ts_idx = traj.addTrackState(TrackStatePropMask::All);
0042   auto ts = traj.getTrackState(ts_idx);
0043 
0044   // Make dummy track parameter
0045   CovarianceMatrix covTrk;
0046   covTrk.setIdentity();
0047   covTrk.diagonal() << 0.08, 0.3, 1, 1, 1, 1;
0048   BoundVector parValues;
0049   parValues << 0.3, 0.5, 0.5 * M_PI, 0., 1 / 100., 0.;
0050 
0051   ts.predicted() = parValues;
0052   ts.predictedCovariance() = covTrk;
0053 
0054   parValues << 0.301, 0.503, 0.5 * M_PI, 0., 1 / 100., 0.;
0055 
0056   ts.filtered() = parValues;
0057   ts.filteredCovariance() = covTrk;
0058   ts.pathLength() = 1.;
0059   ts.jacobian().setIdentity();
0060 
0061   ts_idx = traj.addTrackState(TrackStatePropMask::All, ts_idx);
0062   ts = traj.getTrackState(ts_idx);
0063 
0064   parValues << 0.2, 0.5, 0.5 * M_PI, 0., 1 / 100., 0.;
0065   ts.predicted() = parValues;
0066   ts.predictedCovariance() = covTrk;
0067 
0068   parValues << 0.27, 0.53, 0.5 * M_PI, 0., 1 / 100., 0.;
0069   ts.filtered() = parValues;
0070   ts.filteredCovariance() = covTrk;
0071   ts.pathLength() = 2.;
0072   ts.jacobian().setIdentity();
0073 
0074   ts_idx = traj.addTrackState(TrackStatePropMask::All, ts_idx);
0075   ts = traj.getTrackState(ts_idx);
0076 
0077   parValues << 0.35, 0.49, 0.5 * M_PI, 0., 1 / 100., 0.;
0078   ts.predicted() = parValues;
0079   ts.predictedCovariance() = covTrk;
0080 
0081   parValues << 0.33, 0.43, 0.5 * M_PI, 0., 1 / 100., 0.;
0082   ts.filtered() = parValues;
0083   ts.filteredCovariance() = covTrk;
0084   ts.pathLength() = 3.;
0085   ts.jacobian().setIdentity();
0086 
0087   // "smooth" these three track states
0088   BOOST_CHECK(GainMatrixSmoother()(tgContext, traj, ts_idx).ok());
0089 
0090   // Regression tests, only tests very basic correctness of the math, but tests
0091   // for regressions in the result.
0092 
0093   auto ts1 = traj.getTrackState(0);
0094   BOOST_CHECK(ts1.hasSmoothed());
0095   BOOST_CHECK_NE(ts1.filtered(), ts1.smoothed());
0096 
0097   double tol = 1e-6;
0098 
0099   ParametersVector expPars;
0100   expPars << 0.3510000, 0.4730000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
0101   CovarianceMatrix expCov;
0102   expCov.setIdentity();
0103   expCov.diagonal() << 0.0800000, 0.3000000, 1.0000000, 1.0000000, 1.0000000,
0104       1.0000000;
0105   CHECK_CLOSE_ABS(ts1.smoothed(), expPars, tol);
0106   CHECK_CLOSE_ABS(ts1.smoothedCovariance(), expCov, tol);
0107 
0108   auto ts2 = traj.getTrackState(1);
0109   BOOST_CHECK(ts2.hasSmoothed());
0110   BOOST_CHECK_NE(ts2.filtered(), ts2.smoothed());
0111 
0112   expPars << 0.2500000, 0.4700000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
0113   CHECK_CLOSE_ABS(ts2.smoothed(), expPars, tol);
0114   CHECK_CLOSE_ABS(ts2.smoothedCovariance(), expCov, tol);
0115 
0116   auto ts3 = traj.getTrackState(2);
0117   BOOST_CHECK(ts3.hasSmoothed());
0118   // last one, smoothed == filtered
0119   BOOST_CHECK_EQUAL(ts3.filtered(), ts3.smoothed());
0120 
0121   expPars << 0.3300000, 0.4300000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
0122   CHECK_CLOSE_ABS(ts3.smoothed(), expPars, tol);
0123   CHECK_CLOSE_ABS(ts3.smoothedCovariance(), expCov, tol);
0124 }
0125 
0126 BOOST_AUTO_TEST_SUITE_END()