File indexing completed on 2026-11-28 09:14:40
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/MagneticField/ConstantBField.hpp"
0016 #include "Acts/Propagator/EigenStepper.hpp"
0017 #include "Acts/Propagator/Navigator.hpp"
0018 #include "Acts/Propagator/Propagator.hpp"
0019 #include "Acts/Propagator/StraightLineStepper.hpp"
0020 #include "Acts/Propagator/SurfaceCollector.hpp"
0021 #include "Acts/Propagator/TryAllNavigator.hpp"
0022 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0023 #include "Acts/Utilities/Logger.hpp"
0024 #include "Acts/Utilities/VectorHelpers.hpp"
0025 #include "ActsTests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0026
0027 #include <algorithm>
0028 #include <numbers>
0029
0030 namespace bdata = boost::unit_test::data;
0031
0032 using namespace Acts;
0033 using namespace Acts::UnitLiterals;
0034 using Acts::VectorHelpers::perp;
0035
0036 namespace ActsTests {
0037
0038
0039 GeometryContext tgContext = GeometryContext::dangerouslyDefaultConstruct();
0040 MagneticFieldContext mfContext = MagneticFieldContext();
0041
0042 ActsTests::CylindricalTrackingGeometry cGeometry(tgContext);
0043 auto tGeometry = cGeometry();
0044
0045 const double Bz = 2_T;
0046 auto bField = std::make_shared<ConstantBField>(Vector3{0, 0, Bz});
0047
0048 using TestSurfaceCollector = SurfaceCollector<SurfaceSelector>;
0049 using ParamRecorder = BoundParameterRecorder<SurfaceSelector>;
0050
0051 std::vector<GeometryIdentifier> collectRelevantGeoIds(
0052 const TestSurfaceCollector::State& surfaceHits) {
0053 std::vector<GeometryIdentifier> geoIds;
0054 for (const auto& surfaceHit : surfaceHits.collected) {
0055 auto geoId = surfaceHit.surface->geometryId();
0056 auto material = surfaceHit.surface->surfaceMaterial();
0057 if (geoId.sensitive() == 0 && material == nullptr) {
0058 continue;
0059 }
0060 geoIds.push_back(geoId);
0061 }
0062 return geoIds;
0063 }
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 template <typename propagator_t>
0074 void runSelfConsistencyTest(const propagator_t& prop,
0075 const BoundTrackParameters& start,
0076 const Logger& logger) {
0077
0078 using ActorList =
0079 ActorList<DefaultActor, TestSurfaceCollector, ParamRecorder>;
0080 using Options = typename propagator_t::template Options<ActorList>;
0081
0082
0083 Options fwdOptions(tgContext, mfContext);
0084 fwdOptions.pathLimit = 25_cm;
0085
0086
0087 auto& fwdSurfaceCollector =
0088 fwdOptions.actor.template get<TestSurfaceCollector>();
0089 fwdSurfaceCollector.selector.selectSensitive = true;
0090 fwdSurfaceCollector.selector.selectMaterial = true;
0091 fwdSurfaceCollector.selector.selectPassive = true;
0092
0093 auto& paramRecorder = fwdOptions.actor.template get<ParamRecorder>();
0094 paramRecorder.selector.selectSensitive = true;
0095 paramRecorder.selector.selectMaterial = true;
0096 paramRecorder.selector.selectPassive = true;
0097
0098 ACTS_DEBUG(">>> Forward Propagation : start.");
0099 auto fwdState = prop.makeState(fwdOptions);
0100 auto fwdResult = prop.propagate(fwdState, start).value();
0101 auto fwdSurfaceHits =
0102 fwdState.actor.template get<TestSurfaceCollector::State>().collected;
0103
0104 auto fwdTrackRecords = fwdState.actor.template get<ParamRecorder::State>();
0105
0106 BOOST_CHECK_EQUAL(fwdTrackRecords.size(), fwdSurfaceHits.size());
0107 for (const auto& boundPars :
0108 fwdState.actor.template get<ParamRecorder::State>()) {
0109 BOOST_CHECK_EQUAL(boundPars.particleHypothesis(),
0110 start.particleHypothesis());
0111 BOOST_CHECK_EQUAL(boundPars.covariance().has_value(),
0112 start.covariance().has_value());
0113 BOOST_CHECK_EQUAL(
0114 std::ranges::any_of(
0115 fwdSurfaceHits,
0116 [&](const Acts::SurfaceHit& hit) {
0117 return hit.surface ==
0118 boundPars.referenceSurface().getSharedPtr().get();
0119 }),
0120 true);
0121 }
0122
0123 auto fwdSurfaces = collectRelevantGeoIds(
0124 fwdState.actor.template get<TestSurfaceCollector::State>());
0125
0126 ACTS_DEBUG(">>> Surface hits found on ...");
0127 for (const auto& fwdSteps : fwdSurfaces) {
0128 ACTS_DEBUG("--> Surface with " << fwdSteps);
0129 }
0130 ACTS_DEBUG(">>> Forward Propagation : end.");
0131
0132
0133 Options bwdOptions(tgContext, mfContext);
0134 bwdOptions.pathLimit = 25_cm;
0135 bwdOptions.direction = Direction::Backward();
0136
0137
0138 auto& bwdMSurfaceCollector =
0139 bwdOptions.actor.template get<TestSurfaceCollector>();
0140 bwdMSurfaceCollector.selector.selectSensitive = true;
0141 bwdMSurfaceCollector.selector.selectMaterial = true;
0142 bwdMSurfaceCollector.selector.selectPassive = true;
0143
0144 const auto& startSurface = start.referenceSurface();
0145
0146 ACTS_DEBUG(">>> Backward Propagation : start.");
0147 auto bwdState = prop.makeState(bwdOptions);
0148 prop.propagate(bwdState, *fwdResult.endParameters, &startSurface).value();
0149 auto bwdSurfaceHits =
0150 bwdState.actor.template get<TestSurfaceCollector::State>().collected;
0151 auto bwdSurfaces = collectRelevantGeoIds(
0152 bwdState.actor.template get<TestSurfaceCollector::State>());
0153
0154 ACTS_DEBUG(">>> Surface hits found on ...");
0155 for (auto& bwdSteps : bwdSurfaces) {
0156 ACTS_DEBUG("--> Surface with " << bwdSteps);
0157 }
0158 ACTS_DEBUG(">>> Backward Propagation : end.");
0159
0160
0161 {
0162 std::ranges::reverse(bwdSurfaces);
0163 BOOST_CHECK_EQUAL_COLLECTIONS(bwdSurfaces.begin(), bwdSurfaces.end(),
0164 fwdSurfaces.begin(), fwdSurfaces.end());
0165 }
0166
0167
0168
0169 Options fwdStepOptions(tgContext, mfContext);
0170
0171
0172 auto& fwdStepSurfaceCollector =
0173 fwdOptions.actor.template get<TestSurfaceCollector>();
0174 fwdStepSurfaceCollector.selector.selectSensitive = true;
0175 fwdStepSurfaceCollector.selector.selectMaterial = true;
0176 fwdStepSurfaceCollector.selector.selectPassive = true;
0177
0178 std::vector<GeometryIdentifier> fwdStepSurfaces;
0179
0180
0181 BoundTrackParameters sParameters = start;
0182 std::vector<BoundTrackParameters> stepParameters;
0183 for (auto& fwdSteps : fwdSurfaceHits) {
0184 ACTS_DEBUG(">>> Forward step : "
0185 << sParameters.referenceSurface().geometryId() << " --> "
0186 << fwdSteps.surface->geometryId());
0187
0188
0189 auto fwdStepState = prop.makeState(fwdStepOptions);
0190 auto fwdStep =
0191 prop.propagate(fwdStepState, sParameters, fwdSteps.surface).value();
0192
0193 auto fwdStepSurfacesTmp = collectRelevantGeoIds(
0194 fwdStepState.actor.template get<TestSurfaceCollector::State>());
0195 fwdStepSurfaces.insert(fwdStepSurfaces.end(), fwdStepSurfacesTmp.begin(),
0196 fwdStepSurfacesTmp.end());
0197
0198 if (fwdStep.endParameters.has_value()) {
0199
0200 stepParameters.push_back(*fwdStep.endParameters);
0201 sParameters = stepParameters.back();
0202 }
0203 }
0204
0205 const Surface& dSurface = fwdResult.endParameters->referenceSurface();
0206 ACTS_DEBUG(">>> Forward step : "
0207 << sParameters.referenceSurface().geometryId() << " --> "
0208 << dSurface.geometryId());
0209 auto fwdStepFinalState = prop.makeState(fwdStepOptions);
0210 prop.propagate(fwdStepFinalState, sParameters, &dSurface).value();
0211 auto fwdStepSurfacesTmp = collectRelevantGeoIds(
0212 fwdStepFinalState.actor.template get<TestSurfaceCollector::State>());
0213 fwdStepSurfaces.insert(fwdStepSurfaces.end(), fwdStepSurfacesTmp.begin(),
0214 fwdStepSurfacesTmp.end());
0215
0216
0217
0218
0219
0220 Options bwdStepOptions(tgContext, mfContext);
0221 bwdStepOptions.direction = Direction::Backward();
0222
0223
0224 auto& bwdStepSurfaceCollector =
0225 bwdOptions.actor.template get<TestSurfaceCollector>();
0226 bwdStepSurfaceCollector.selector.selectSensitive = true;
0227 bwdStepSurfaceCollector.selector.selectMaterial = true;
0228 bwdStepSurfaceCollector.selector.selectPassive = true;
0229
0230 std::vector<GeometryIdentifier> bwdStepSurfaces;
0231
0232
0233 sParameters = *fwdResult.endParameters;
0234 for (auto& bwdSteps : bwdSurfaceHits) {
0235 ACTS_DEBUG(">>> Backward step : "
0236 << sParameters.referenceSurface().geometryId() << " --> "
0237 << bwdSteps.surface->geometryId());
0238
0239
0240 auto bwdStepState = prop.makeState(bwdStepOptions);
0241 auto bwdStep =
0242 prop.propagate(bwdStepState, sParameters, bwdSteps.surface).value();
0243
0244 auto bwdStepSurfacesTmp = collectRelevantGeoIds(
0245 bwdStepState.actor.template get<TestSurfaceCollector::State>());
0246 bwdStepSurfaces.insert(bwdStepSurfaces.end(), bwdStepSurfacesTmp.begin(),
0247 bwdStepSurfacesTmp.end());
0248
0249 if (bwdStep.endParameters.has_value()) {
0250
0251 stepParameters.push_back(*bwdStep.endParameters);
0252 sParameters = stepParameters.back();
0253 }
0254 }
0255
0256 const Surface& dbSurface = start.referenceSurface();
0257 ACTS_DEBUG(">>> Backward step : "
0258 << sParameters.referenceSurface().geometryId() << " --> "
0259 << dSurface.geometryId());
0260 auto bwdStepFinalState = prop.makeState(bwdStepOptions);
0261 prop.propagate(bwdStepFinalState, sParameters, &dbSurface).value();
0262 auto bwdStepSurfacesTmp = collectRelevantGeoIds(
0263 bwdStepFinalState.actor.template get<TestSurfaceCollector::State>());
0264 bwdStepSurfaces.insert(bwdStepSurfaces.end(), bwdStepSurfacesTmp.begin(),
0265 bwdStepSurfacesTmp.end());
0266
0267
0268
0269 std::ranges::reverse(bwdStepSurfaces);
0270 BOOST_CHECK_EQUAL_COLLECTIONS(bwdStepSurfaces.begin(), bwdStepSurfaces.end(),
0271 fwdStepSurfaces.begin(), fwdStepSurfaces.end());
0272 }
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284 template <typename propagator_probe_t, typename propagator_ref_t>
0285 void runConsistencyTest(const propagator_probe_t& propProbe,
0286 const propagator_ref_t& propRef,
0287 const BoundTrackParameters& start,
0288 const Logger& logger) {
0289
0290 using ActorList = ActorList<DefaultActor, TestSurfaceCollector>;
0291
0292 auto run = [&](const auto& prop) {
0293 using propagator_t = std::decay_t<decltype(prop)>;
0294 using Options = typename propagator_t::template Options<ActorList>;
0295
0296
0297 Options fwdOptions(tgContext, mfContext);
0298 fwdOptions.pathLimit = 25_cm;
0299 fwdOptions.stepping.maxStepSize = 1_cm;
0300
0301
0302 auto& fwdSurfaceCollector =
0303 fwdOptions.actor.template get<TestSurfaceCollector>();
0304 fwdSurfaceCollector.selector.selectSensitive = true;
0305 fwdSurfaceCollector.selector.selectMaterial = true;
0306 fwdSurfaceCollector.selector.selectPassive = true;
0307
0308 auto fwdState = prop.makeState(fwdOptions);
0309 prop.propagate(fwdState, start).value();
0310 auto fwdSurfaces = collectRelevantGeoIds(
0311 fwdState.actor.template get<TestSurfaceCollector::State>());
0312
0313 ACTS_DEBUG(">>> Surface hits found on ...");
0314 for (const auto& fwdSteps : fwdSurfaces) {
0315 ACTS_DEBUG("--> Surface with " << fwdSteps);
0316 }
0317
0318 return fwdSurfaces;
0319 };
0320
0321 ACTS_DEBUG(">>> Probe Propagation : start.");
0322 const auto& probeSurfaces = run(propProbe);
0323 ACTS_DEBUG(">>> Probe Propagation : end.");
0324
0325 ACTS_DEBUG(">>> Reference Propagation : start.");
0326 const auto& refSurfaces = run(propRef);
0327 ACTS_DEBUG(">>> Reference Propagation : end.");
0328
0329
0330 BOOST_CHECK_EQUAL_COLLECTIONS(probeSurfaces.begin(), probeSurfaces.end(),
0331 refSurfaces.begin(), refSurfaces.end());
0332 }
0333
0334 Logging::Level logLevel = Logging::INFO;
0335
0336 const int nTestsSelfConsistency = 500;
0337 const int nTestsRefConsistency = 500;
0338
0339 using StraightLinePropagator = Propagator<StraightLineStepper, Navigator>;
0340 using TestEigenStepper = EigenStepper<>;
0341 using EigenPropagator = Propagator<TestEigenStepper, Navigator>;
0342 using ReferenceStraightLinePropagator =
0343 Propagator<StraightLineStepper, Experimental::TryAllNavigator>;
0344 using ReferenceEigenPropagator =
0345 Propagator<TestEigenStepper, Experimental::TryAllNavigator>;
0346
0347 StraightLineStepper slstepper;
0348 TestEigenStepper estepper(bField);
0349
0350 StraightLinePropagator slpropagator(slstepper,
0351 Navigator({tGeometry, true, true, false},
0352 getDefaultLogger("sl_nav",
0353 Logging::INFO)),
0354 getDefaultLogger("sl_prop", Logging::INFO));
0355 EigenPropagator epropagator(estepper,
0356 Navigator({tGeometry, true, true, false},
0357 getDefaultLogger("e_nav", Logging::INFO)),
0358 getDefaultLogger("e_prop", Logging::INFO));
0359
0360 ReferenceStraightLinePropagator refslpropagator(
0361 slstepper,
0362 Experimental::TryAllNavigator({tGeometry, true, true, false},
0363 getDefaultLogger("ref_sl_nav",
0364 Logging::INFO)),
0365 getDefaultLogger("ref_sl_prop", Logging::INFO));
0366 ReferenceEigenPropagator refepropagator(
0367 estepper,
0368 Experimental::TryAllNavigator({tGeometry, true, true, false,
0369 BoundaryTolerance::Infinite()},
0370 getDefaultLogger("ref_e_nav", Logging::INFO)),
0371 getDefaultLogger("ref_e_prop", Logging::INFO));
0372
0373 auto eventGen =
0374 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 20,
0375 bdata::distribution = std::uniform_real_distribution<double>(
0376 0.5_GeV, 10_GeV))) ^
0377 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 21,
0378 bdata::distribution = std::uniform_real_distribution<double>(
0379 -std::numbers::pi, std::numbers::pi))) ^
0380 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
0381 bdata::distribution = std::uniform_real_distribution<double>(
0382 1., std::numbers::pi - 1.))) ^
0383 bdata::random(
0384 (bdata::engine = std::mt19937(), bdata::seed = 23,
0385 bdata::distribution = std::uniform_int_distribution<int>(0, 1)));
0386
0387 BoundTrackParameters createStartParameters(double pT, double phi, double theta,
0388 int charge) {
0389 double p = pT / std::sin(theta);
0390 double q = -1 + 2 * charge;
0391 return BoundTrackParameters::createCurvilinear(Vector4::Zero(), phi, theta,
0392 q / p, std::nullopt,
0393 ParticleHypothesis::pion());
0394 }
0395
0396 BOOST_DATA_TEST_CASE(NavigatorStraightLineSelfConsistency,
0397 eventGen ^ bdata::xrange(nTestsSelfConsistency), pT, phi,
0398 theta, charge, index) {
0399 ACTS_LOCAL_LOGGER(getDefaultLogger("NavigatorTest", logLevel));
0400
0401 BoundTrackParameters start = createStartParameters(pT, phi, theta, charge);
0402
0403 ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
0404 << pT << "\n phi = " << phi << "\n theta = " << theta
0405 << "\n charge = " << charge << "\n index = " << index);
0406
0407 ACTS_DEBUG(">>> Test self consistency slpropagator");
0408 runSelfConsistencyTest(slpropagator, start, logger());
0409 }
0410
0411 BOOST_DATA_TEST_CASE(NavigatorEigenSelfConsistency,
0412 eventGen ^ bdata::xrange(nTestsSelfConsistency), pT, phi,
0413 theta, charge, index) {
0414 ACTS_LOCAL_LOGGER(getDefaultLogger("NavigatorTest", logLevel));
0415
0416 BoundTrackParameters start = createStartParameters(pT, phi, theta, charge);
0417
0418 ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
0419 << pT << "\n phi = " << phi << "\n theta = " << theta
0420 << "\n charge = " << charge << "\n index = " << index);
0421
0422 ACTS_DEBUG(">>> Test self consistency epropagator");
0423 runSelfConsistencyTest(epropagator, start, logger());
0424 }
0425
0426 BOOST_DATA_TEST_CASE(NavigatorRefStraightLineConsistency,
0427 eventGen ^ bdata::xrange(nTestsRefConsistency), pT, phi,
0428 theta, charge, index) {
0429 ACTS_LOCAL_LOGGER(getDefaultLogger("NavigatorTest", logLevel));
0430
0431 BoundTrackParameters start = createStartParameters(pT, phi, theta, charge);
0432
0433 ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
0434 << pT << "\n phi = " << phi << "\n theta = " << theta
0435 << "\n charge = " << charge << "\n index = " << index);
0436
0437 ACTS_DEBUG(">>> Test reference consistency slpropagator");
0438 runConsistencyTest(slpropagator, refslpropagator, start, logger());
0439 }
0440
0441 BOOST_DATA_TEST_CASE(NavigatorRefEigenConsistency,
0442 eventGen ^ bdata::xrange(nTestsRefConsistency), pT, phi,
0443 theta, charge, index) {
0444 ACTS_LOCAL_LOGGER(getDefaultLogger("NavigatorTest", logLevel));
0445
0446 BoundTrackParameters start = createStartParameters(pT, phi, theta, charge);
0447
0448 ACTS_DEBUG(">>> Run navigation tests with:\n pT = "
0449 << pT << "\n phi = " << phi << "\n theta = " << theta
0450 << "\n charge = " << charge << "\n index = " << index);
0451
0452 ACTS_DEBUG(">>> Test reference consistency epropagator");
0453 runConsistencyTest(epropagator, refepropagator, start, logger());
0454 }
0455
0456 }