Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 08:21:07

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/data/test_case.hpp>
0010 #include <boost/test/tools/context.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/EventData/MultiTrajectory.hpp"
0015 #include "Acts/EventData/ProxyAccessor.hpp"
0016 #include "Acts/EventData/TrackStatePropMask.hpp"
0017 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0018 #include "Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp"
0019 #include "Acts/EventData/detail/TestTrackState.hpp"
0020 #include "Acts/Geometry/GeometryContext.hpp"
0021 
0022 #include <random>
0023 #include <string>
0024 #include <type_traits>
0025 #include <utility>
0026 
0027 namespace {
0028 
0029 using namespace Acts;
0030 using namespace Acts::UnitLiterals;
0031 using namespace Acts::detail::Test;
0032 using namespace Acts::HashedStringLiteral;
0033 namespace bd = boost::unit_test::data;
0034 
0035 using ParametersVector = BoundVector;
0036 using CovarianceMatrix = BoundMatrix;
0037 using Jacobian = BoundMatrix;
0038 
0039 const auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0040 // fixed seed for reproducible tests
0041 std::default_random_engine rng(31415);
0042 
0043 struct Factory {
0044   using trajectory_t = VectorMultiTrajectory;
0045   using const_trajectory_t = ConstVectorMultiTrajectory;
0046 
0047   VectorMultiTrajectory create() { return {}; }
0048   ConstVectorMultiTrajectory createConst() { return {}; }
0049 };
0050 
0051 using CommonTests = MultiTrajectoryTestsCommon<Factory>;
0052 
0053 }  // namespace
0054 
0055 namespace ActsTests {
0056 
0057 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0058 
0059 BOOST_AUTO_TEST_CASE(Build) {
0060   CommonTests ct;
0061   ct.testBuild();
0062 }
0063 
0064 BOOST_AUTO_TEST_CASE(ConstCorrectness) {
0065   // make mutable
0066   VectorMultiTrajectory t;
0067   auto i0 = t.addTrackState();
0068 
0069   BOOST_CHECK(!IsReadOnlyMultiTrajectory<decltype(t)>::value);
0070 
0071   {
0072     VectorMultiTrajectory::TrackStateProxy tsp = t.getTrackState(i0);
0073     static_cast<void>(tsp);
0074     VectorMultiTrajectory::ConstTrackStateProxy ctsp{t.getTrackState(i0)};
0075     static_cast<void>(ctsp);
0076 
0077     tsp.predicted().setRandom();
0078     // const auto& tsp_const = tsp;
0079     // tsp_const.predicted().setRandom();
0080     // ctsp.predicted().setRandom();
0081   }
0082 
0083   // is this something we actually want?
0084   ConstVectorMultiTrajectory ct{t};
0085   BOOST_CHECK_EQUAL(ct.size(), t.size());
0086 
0087   ConstVectorMultiTrajectory ctm{std::move(t)};
0088   BOOST_CHECK_EQUAL(ctm.size(), ct.size());
0089 
0090   {
0091     static_assert(
0092         std::is_same_v<ConstVectorMultiTrajectory::ConstTrackStateProxy,
0093                        decltype(ctm.getTrackState(i0))>,
0094         "Got mutable track state proxy");
0095     ConstVectorMultiTrajectory::ConstTrackStateProxy ctsp =
0096         ctm.getTrackState(i0);
0097     static_cast<void>(ctsp);
0098 
0099     // doesn't compile:
0100     // ctsp.predictedCovariance().setIdentity();
0101   }
0102 
0103   // doesn't compile:
0104   // ct.clear();
0105   // ct.addTrackState();
0106 }
0107 
0108 BOOST_AUTO_TEST_CASE(Clear) {
0109   CommonTests ct;
0110   ct.testClear();
0111 }
0112 
0113 BOOST_AUTO_TEST_CASE(ApplyWithAbort) {
0114   CommonTests ct;
0115   ct.testApplyWithAbort();
0116 }
0117 
0118 BOOST_AUTO_TEST_CASE(AddTrackStateWithBitMask) {
0119   CommonTests ct;
0120   ct.testAddTrackStateWithBitMask();
0121 }
0122 
0123 BOOST_AUTO_TEST_CASE(AddTrackStateComponents) {
0124   CommonTests ct;
0125   ct.testAddTrackStateComponents();
0126 }
0127 
0128 BOOST_AUTO_TEST_CASE(AddTrackStateComponentsAfterShareAndUnset) {
0129   CommonTests ct;
0130   ct.testAddTrackStateComponentsAfterShareAndUnset();
0131 }
0132 
0133 // assert expected "cross-talk" between trackstate proxies
0134 BOOST_AUTO_TEST_CASE(TrackStateProxyCrossTalk) {
0135   CommonTests ct;
0136   ct.testTrackStateProxyCrossTalk(rng);
0137 }
0138 
0139 BOOST_AUTO_TEST_CASE(TrackStateReassignment) {
0140   CommonTests ct;
0141   ct.testTrackStateReassignment(rng);
0142 }
0143 
0144 BOOST_DATA_TEST_CASE(TrackStateProxyStorage, bd::make({1u, 2u}),
0145                      nMeasurements) {
0146   CommonTests ct;
0147   ct.testTrackStateProxyStorage(rng, nMeasurements);
0148 }
0149 
0150 BOOST_AUTO_TEST_CASE(TrackStateProxyAllocations) {
0151   CommonTests ct;
0152   ct.testTrackStateProxyAllocations(rng);
0153 }
0154 
0155 BOOST_AUTO_TEST_CASE(TrackStateProxyGetMask) {
0156   CommonTests ct;
0157   ct.testTrackStateProxyGetMask();
0158 }
0159 
0160 BOOST_AUTO_TEST_CASE(TrackStateProxyCopy) {
0161   CommonTests ct;
0162   ct.testTrackStateProxyCopy(rng);
0163 }
0164 
0165 BOOST_AUTO_TEST_CASE(TrackStateCopyDynamicColumns) {
0166   CommonTests ct;
0167   ct.testTrackStateCopyDynamicColumns();
0168 }
0169 
0170 BOOST_AUTO_TEST_CASE(TrackStateProxyCopyDiffMTJ) {
0171   CommonTests ct;
0172   ct.testTrackStateProxyCopyDiffMTJ();
0173 }
0174 
0175 BOOST_AUTO_TEST_CASE(ProxyAssignment) {
0176   CommonTests ct;
0177   ct.testProxyAssignment();
0178 }
0179 
0180 BOOST_AUTO_TEST_CASE(CopyFromConst) {
0181   CommonTests ct;
0182   ct.testCopyFromConst();
0183 }
0184 
0185 BOOST_AUTO_TEST_CASE(TrackStateProxyShare) {
0186   CommonTests ct;
0187   ct.testTrackStateProxyShare(rng);
0188 }
0189 
0190 BOOST_AUTO_TEST_CASE(MultiTrajectoryExtraColumns) {
0191   CommonTests ct;
0192   ct.testMultiTrajectoryExtraColumns();
0193 }
0194 
0195 BOOST_AUTO_TEST_CASE(MultiTrajectoryExtraColumnsRuntime) {
0196   CommonTests ct;
0197   ct.testMultiTrajectoryExtraColumnsRuntime();
0198 }
0199 
0200 BOOST_AUTO_TEST_CASE(MultiTrajectoryAllocateCalibratedInit) {
0201   CommonTests ct;
0202   ct.testMultiTrajectoryAllocateCalibratedInit(rng);
0203 }
0204 
0205 BOOST_AUTO_TEST_CASE(MemoryStats) {
0206   using namespace boost::histogram;
0207   using cat = axis::category<std::string>;
0208 
0209   VectorMultiTrajectory mt;
0210 
0211   auto stats = mt.statistics();
0212 
0213   std::stringstream ss;
0214   stats.toStream(ss);
0215   std::string out = ss.str();
0216   BOOST_CHECK(!out.empty());
0217   BOOST_CHECK_NE(out.find("total"), std::string::npos);
0218 
0219   const auto& h = stats.hist;
0220 
0221   auto column_axis = axis::get<cat>(h.axis(0));
0222   auto type_axis = axis::get<axis::category<>>(h.axis(1));
0223 
0224   for (int t = 0; t < type_axis.size(); t++) {
0225     for (int c = 0; c < column_axis.size(); c++) {
0226       double v = h.at(c, t);
0227       BOOST_CHECK_EQUAL(v, 0.0);
0228     }
0229   }
0230 
0231   TestTrackState pc(rng, 2u);
0232   auto ts = mt.makeTrackState();
0233   fillTrackState<VectorMultiTrajectory>(pc, TrackStatePropMask::All, ts);
0234 
0235   stats = mt.statistics();
0236 
0237   for (int t = 0; t < type_axis.size(); t++) {
0238     BOOST_TEST_CONTEXT((type_axis.bin(t) == 1 ? "meas" : "other"))
0239     for (int c = 0; c < column_axis.size(); c++) {
0240       std::string key = column_axis.bin(c);
0241       BOOST_TEST_CONTEXT("column: " << key) {
0242         double v = h.at(c, t);
0243         if (t == 0) {
0244           BOOST_CHECK_NE(v, 0.0);
0245         } else {
0246           BOOST_CHECK_EQUAL(v, 0.0);
0247         }
0248       }
0249     }
0250   }
0251 }
0252 
0253 BOOST_AUTO_TEST_CASE(Accessors) {
0254   VectorMultiTrajectory mtj;
0255   mtj.addColumn<unsigned int>("ndof");
0256   mtj.addColumn<double>("super_chi2");
0257 
0258   auto ts = mtj.makeTrackState();
0259 
0260   ProxyAccessor<unsigned int> ndof("ndof");
0261   ConstProxyAccessor<unsigned int> ndofConst("ndof");
0262   ProxyAccessor<double> superChi2("super_chi2");
0263   ConstProxyAccessor<double> superChi2Const("super_chi2");
0264 
0265   ndof(ts) = 65;
0266   BOOST_CHECK_EQUAL((ts.component<unsigned int, "ndof"_hash>()), 65);
0267   BOOST_CHECK_EQUAL(ndofConst(ts), 65);
0268 
0269   // should not compile
0270   // ndofConst(ts) = 66;
0271 
0272   superChi2(ts) = 123.45;
0273   BOOST_CHECK_EQUAL((ts.component<double, "super_chi2"_hash>()), 123.45);
0274   BOOST_CHECK_EQUAL(superChi2Const(ts), 123.45);
0275 
0276   // should not compile
0277   // superChi2Const(ts) = 66.66;
0278 }
0279 
0280 BOOST_AUTO_TEST_CASE(ChangeSourceLinkType) {
0281   VectorMultiTrajectory mtj;
0282   auto ts = mtj.makeTrackState();
0283 
0284   int value = 5;
0285   ts.setUncalibratedSourceLink(SourceLink{value});
0286 
0287   BOOST_CHECK_EQUAL(ts.getUncalibratedSourceLink().get<int>(), value);
0288   BOOST_CHECK_THROW(ts.getUncalibratedSourceLink().get<double>(),
0289                     std::bad_any_cast);
0290 
0291   double otherValue = 42.42;
0292 
0293   // this changes the stored type
0294   ts.setUncalibratedSourceLink(SourceLink{otherValue});
0295   BOOST_CHECK_EQUAL(ts.getUncalibratedSourceLink().get<double>(), otherValue);
0296   BOOST_CHECK_THROW(ts.getUncalibratedSourceLink().get<int>(),
0297                     std::bad_any_cast);
0298 }
0299 
0300 BOOST_AUTO_TEST_SUITE_END()
0301 
0302 }  // namespace ActsTests