Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:00

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/TrackParametrization.hpp"
0012 #include "Acts/EventData/TrackContainer.hpp"
0013 #include "Acts/EventData/TrackStateType.hpp"
0014 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0015 #include "Acts/EventData/VectorTrackContainer.hpp"
0016 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0017 #include "Acts/Utilities/TrackHelpers.hpp"
0018 
0019 namespace Acts::Test {
0020 
0021 namespace {
0022 
0023 template <typename TrackContainer, typename FlagsPerState>
0024 auto createTestTrack(TrackContainer& tc, const FlagsPerState& flagsPerState) {
0025   auto t = tc.makeTrack();
0026 
0027   for (const auto& flags : flagsPerState) {
0028     auto ts = t.appendTrackState();
0029     for (auto f : flags) {
0030       ts.typeFlags().set(f);
0031     }
0032   }
0033 
0034   return t;
0035 }
0036 
0037 template <typename TrackContainer>
0038 auto createTestTrackState(TrackContainer& tc) {
0039   auto t = tc.makeTrack();
0040 
0041   auto ts = t.appendTrackState();
0042 
0043   ts.allocateCalibrated(Vector2::Zero(), SquareMatrix2::Identity());
0044   ts.setProjectorSubspaceIndices(std::array{eBoundLoc0, eBoundLoc1});
0045 
0046   ts.predicted() = BoundVector::Zero();
0047   ts.predicted()[eBoundLoc0] = 1.;
0048   ts.predicted()[eBoundLoc1] = 1.;
0049   ts.predictedCovariance() = BoundMatrix::Identity() * 1.;
0050 
0051   ts.filtered() = BoundVector::Zero();
0052   ts.filtered()[eBoundLoc0] = 0.5;
0053   ts.filtered()[eBoundLoc1] = 0.5;
0054   ts.filteredCovariance() = BoundMatrix::Identity() * 0.5;
0055 
0056   ts.smoothed() = BoundVector::Zero();
0057   ts.smoothed()[eBoundLoc0] = 0.1;
0058   ts.smoothed()[eBoundLoc1] = 0.1;
0059   ts.smoothedCovariance() = BoundMatrix::Identity() * 0.1;
0060 
0061   return ts;
0062 }
0063 
0064 }  // namespace
0065 
0066 BOOST_AUTO_TEST_SUITE(Utilities)
0067 
0068 BOOST_AUTO_TEST_CASE(CalculateQuantities) {
0069   TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
0070   auto t = createTestTrack(tc, std::vector<std::vector<TrackStateFlag>>{
0071                                    {MeasurementFlag},
0072                                    {OutlierFlag},
0073                                    {MeasurementFlag, SharedHitFlag},
0074                                    {HoleFlag},
0075                                    {OutlierFlag},
0076                                    {HoleFlag},
0077                                    {MeasurementFlag, SharedHitFlag},
0078                                    {OutlierFlag},
0079                                });
0080 
0081   calculateTrackQuantities(t);
0082 
0083   BOOST_CHECK_EQUAL(t.nHoles(), 2);
0084   BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0085   BOOST_CHECK_EQUAL(t.nOutliers(), 3);
0086   BOOST_CHECK_EQUAL(t.nSharedHits(), 2);
0087 }
0088 
0089 BOOST_AUTO_TEST_CASE(TrimTrack) {
0090   TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
0091   auto t = createTestTrack(tc, std::vector<std::vector<TrackStateFlag>>{
0092                                    {},
0093                                    {HoleFlag},
0094                                    {MeasurementFlag},
0095                                    {OutlierFlag},
0096                                    {MeasurementFlag, SharedHitFlag},
0097                                    {HoleFlag},
0098                                    {OutlierFlag},
0099                                    {HoleFlag},
0100                                    {MeasurementFlag},
0101                                    {OutlierFlag},
0102                                    {},
0103                                });
0104 
0105   calculateTrackQuantities(t);
0106 
0107   BOOST_CHECK_EQUAL(t.nTrackStates(), 11);
0108   BOOST_CHECK_EQUAL(t.nHoles(), 3);
0109   BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0110   BOOST_CHECK_EQUAL(t.nOutliers(), 3);
0111   BOOST_CHECK_EQUAL(t.nSharedHits(), 1);
0112 
0113   trimTrackFront(t, true, true, true, true);
0114   calculateTrackQuantities(t);
0115 
0116   BOOST_CHECK_EQUAL(t.nTrackStates(), 9);
0117   BOOST_CHECK_EQUAL(t.nHoles(), 2);
0118   BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0119   BOOST_CHECK_EQUAL(t.nOutliers(), 3);
0120   BOOST_CHECK_EQUAL(t.nSharedHits(), 1);
0121 
0122   trimTrackBack(t, true, true, true, true);
0123   calculateTrackQuantities(t);
0124 
0125   BOOST_CHECK_EQUAL(t.nTrackStates(), 7);
0126   BOOST_CHECK_EQUAL(t.nHoles(), 2);
0127   BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0128   BOOST_CHECK_EQUAL(t.nOutliers(), 2);
0129   BOOST_CHECK_EQUAL(t.nSharedHits(), 1);
0130 
0131   trimTrack(t, true, true, true, true);
0132   calculateTrackQuantities(t);
0133 
0134   BOOST_CHECK_EQUAL(t.nTrackStates(), 7);
0135   BOOST_CHECK_EQUAL(t.nHoles(), 2);
0136   BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0137   BOOST_CHECK_EQUAL(t.nOutliers(), 2);
0138   BOOST_CHECK_EQUAL(t.nSharedHits(), 1);
0139 }
0140 
0141 BOOST_AUTO_TEST_CASE(CalculatePredictedChi2) {
0142   TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
0143   auto ts = createTestTrackState(tc);
0144 
0145   // reference found by running the code
0146   BOOST_CHECK_CLOSE(calculatePredictedChi2(ts), 1., 1e-6);
0147 }
0148 
0149 BOOST_AUTO_TEST_CASE(CalculateFilteredChi2) {
0150   TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
0151   auto ts = createTestTrackState(tc);
0152 
0153   // reference found by running the code
0154   BOOST_CHECK_CLOSE(calculateFilteredChi2(ts), 1. / 3., 1e-6);
0155 }
0156 
0157 BOOST_AUTO_TEST_CASE(CalculateSmoothedChi2) {
0158   TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
0159   auto ts = createTestTrackState(tc);
0160 
0161   // reference found by running the code
0162   BOOST_CHECK_CLOSE(calculateSmoothedChi2(ts), 1. / 55., 1e-6);
0163 }
0164 
0165 BOOST_AUTO_TEST_CASE(CalculateUnbiasedParametersCovariance) {
0166   TrackContainer tc{VectorTrackContainer{}, VectorMultiTrajectory{}};
0167   auto ts = createTestTrackState(tc);
0168 
0169   auto [params, cov] = calculateUnbiasedParametersCovariance(ts);
0170 
0171   // reference found by running the code
0172   BoundVector refParams = BoundVector::Zero();
0173   refParams[eBoundLoc0] = 1. / 9.;
0174   refParams[eBoundLoc1] = 1. / 9.;
0175   BoundMatrix refCov = BoundMatrix::Identity() * 0.1;
0176   refCov(eBoundLoc0, eBoundLoc0) = 1. / 9.;
0177   refCov(eBoundLoc1, eBoundLoc1) = 1. / 9.;
0178 
0179   CHECK_CLOSE_ABS(params, refParams, 1e-6);
0180   CHECK_CLOSE_ABS(cov, refCov, 1e-6);
0181 }
0182 
0183 BOOST_AUTO_TEST_SUITE_END()
0184 
0185 }  // namespace Acts::Test