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