Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:23

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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/Geometry/GeometryContext.hpp"
0012 #include "Acts/MagneticField/ConstantBField.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/Propagator/EigenStepper.hpp"
0015 #include "Acts/Propagator/Navigator.hpp"
0016 #include "Acts/Propagator/Propagator.hpp"
0017 #include "Acts/Propagator/detail/SteppingLogger.hpp"
0018 #include "Acts/Surfaces/BoundaryCheck.hpp"
0019 #include "Acts/Tests/CommonHelpers/CubicTrackingGeometry.hpp"
0020 #include "Acts/Utilities/Logger.hpp"
0021 
0022 using namespace Acts::UnitLiterals;
0023 
0024 /// This tests intend to check the behaviour of the navigator in cases where the
0025 /// straight-line approach for the layer resolval can fail. This is in
0026 /// particular the case with bent tracks in telesocpe-like geometries, and can
0027 /// be fixed by not doing the bounds check in the initial resolving.
0028 
0029 using MagneticField = Acts::ConstantBField;
0030 using Stepper = Acts::EigenStepper<>;
0031 using Propagator = Acts::Propagator<Stepper, Acts::Navigator>;
0032 
0033 const Acts::GeometryContext geoCtx;
0034 const Acts::MagneticFieldContext magCtx;
0035 
0036 std::vector<double> xPositionsOfPassedSurfaces(Acts::Navigator::Config navCfg,
0037                                                double bz) {
0038   auto magField = std::make_shared<MagneticField>(Acts::Vector3(0.0, 0.0, bz));
0039   Acts::Test::CubicTrackingGeometry cubicBuilder(geoCtx);
0040 
0041   navCfg.trackingGeometry = cubicBuilder();
0042   Stepper stepper(std::move(magField));
0043   Propagator propagator(
0044       stepper,
0045       Acts::Navigator(navCfg,
0046                       Acts::getDefaultLogger("nav", Acts::Logging::VERBOSE)),
0047       Acts::getDefaultLogger("nav", Acts::Logging::VERBOSE));
0048 
0049   // Start with a slightly tilted direction that does not hit the surfaces at
0050   // x=2000 with 0 B-Field
0051   Acts::Vector3 dir = Acts::Vector3{1.0_m, 0.3_m, 0.0_m};
0052 
0053   // Start a bit in the volume 2, so we do not have any boundary checking for
0054   // the volume transition in the log
0055   Acts::CurvilinearTrackParameters start(
0056       Acts::Vector4(0.01, 0, 0, 0), dir.normalized(), 1 / 1_GeV, std::nullopt,
0057       Acts::ParticleHypothesis::pion());
0058 
0059   Acts::PropagatorOptions<Acts::ActionList<Acts::detail::SteppingLogger>,
0060                           Acts::AbortList<Acts::EndOfWorldReached>>
0061       opts(geoCtx, magCtx);
0062 
0063   auto res = propagator.propagate(start, opts);
0064 
0065   BOOST_CHECK(res.ok());
0066 
0067   const auto &stepLog = res->get<Acts::detail::SteppingLogger::result_type>();
0068 
0069   std::vector<double> xPositions;
0070   for (const auto &step : stepLog.steps) {
0071     if (step.surface) {
0072       xPositions.push_back(step.surface->center(geoCtx)[Acts::ePos0]);
0073     }
0074   }
0075 
0076   return xPositions;
0077 }
0078 
0079 BOOST_AUTO_TEST_CASE(with_boundary_check_no_bfield) {
0080   auto navCfg = Acts::Navigator::Config{};
0081   const auto xPositions = xPositionsOfPassedSurfaces(navCfg, 0.0_T);
0082 
0083   // without bfield we exit at the side so we don't hit the surfaces at x ~
0084   // 2000 and also not the boundary surface at x = 3000, regardless of the
0085   // boundary checking
0086   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 999.0), 1);
0087   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 1001.0),
0088                     1);
0089   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 1999.0),
0090                     0);
0091   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 2001.0),
0092                     0);
0093   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 3000.0),
0094                     0);
0095 }
0096 
0097 BOOST_AUTO_TEST_CASE(with_boundary_check_with_bfield) {
0098   auto navCfg = Acts::Navigator::Config{};
0099   const auto xPositions = xPositionsOfPassedSurfaces(navCfg, 0.5_T);
0100 
0101   // With default navigation config we miss the surfaces at x ~ 2000, but hit
0102   // the boundary surface at x = 3000
0103   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 999.0), 1);
0104   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 1001.0),
0105                     1);
0106   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 1999.0),
0107                     0);
0108   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 2001.0),
0109                     0);
0110   BOOST_CHECK_EQUAL(std::count(xPositions.begin(), xPositions.end(), 3000.0),
0111                     1);
0112 }