File indexing completed on 2026-12-04 09:48:08
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/Units.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Surfaces/CylinderBounds.hpp"
0015 #include "Acts/Surfaces/CylinderSurface.hpp"
0016 #include "Acts/Surfaces/DiscSurface.hpp"
0017 #include "Acts/Surfaces/PlaneSurface.hpp"
0018 #include "Acts/Surfaces/RadialBounds.hpp"
0019 #include "Acts/Surfaces/RectangleBounds.hpp"
0020 #include "Acts/Surfaces/StrawSurface.hpp"
0021 #include "Acts/Surfaces/detail/CurvatureCorrection.hpp"
0022 #include "ActsTests/CommonHelpers/BenchmarkTools.hpp"
0023
0024 #include <chrono>
0025 #include <cmath>
0026 #include <numbers>
0027 #include <random>
0028
0029 using namespace Acts;
0030 using namespace Acts::UnitLiterals;
0031
0032 namespace bdata = boost::unit_test::data;
0033
0034 namespace ActsTests {
0035
0036
0037 unsigned int ntests = 10;
0038 unsigned int nrepts = 2000;
0039 const BoundaryTolerance boundaryTolerance = BoundaryTolerance::Infinite();
0040 const bool testPlane = true;
0041 const bool testDisc = true;
0042 const bool testCylinder = true;
0043 const bool testStraw = true;
0044
0045
0046 GeometryContext tgContext = GeometryContext::dangerouslyDefaultConstruct();
0047
0048
0049
0050 Transform3 at = Transform3::Identity() * Translation3(0_m, 0_m, 10_m) *
0051 AngleAxis3(0.15, Vector3(1.2, 1.2, 0.12).normalized());
0052
0053
0054 auto rb = std::make_shared<RectangleBounds>(1_m, 1_m);
0055 auto aPlane = Surface::makeShared<PlaneSurface>(at, std::move(rb));
0056
0057
0058 auto db = std::make_shared<RadialBounds>(0.2_m, 1.2_m);
0059 auto aDisc = Surface::makeShared<DiscSurface>(at, std::move(db));
0060
0061
0062 auto cb = std::make_shared<CylinderBounds>(10_m, 100_m);
0063 auto aCylinder = Surface::makeShared<CylinderSurface>(at, std::move(cb));
0064
0065
0066 auto aStraw = Surface::makeShared<StrawSurface>(at, 50_cm, 2_m);
0067
0068
0069 Vector3 origin(0., 0., 0.);
0070
0071
0072 Vector3 originStraw(0.3_m, -0.2_m, 11_m);
0073
0074 template <typename surface_t>
0075 MicroBenchmarkResult intersectionTest(const surface_t& surface, double phi,
0076 double theta) {
0077
0078 double cosPhi = std::cos(phi);
0079 double sinPhi = std::sin(phi);
0080 double cosTheta = std::cos(theta);
0081 double sinTheta = std::sin(theta);
0082
0083 Vector3 direction(cosPhi * sinTheta, sinPhi * sinTheta, cosTheta);
0084
0085 return microBenchmark(
0086 [&] {
0087 return surface.intersect(tgContext, origin, direction,
0088 boundaryTolerance);
0089 },
0090 nrepts);
0091 }
0092
0093 BOOST_DATA_TEST_CASE(
0094 benchmark_surface_intersections,
0095 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 21,
0096 bdata::distribution = std::uniform_real_distribution<double>(
0097 -std::numbers::pi, std::numbers::pi))) ^
0098 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
0099 bdata::distribution =
0100 std::uniform_real_distribution<double>(-0.3, 0.3))) ^
0101 bdata::xrange(ntests),
0102 phi, theta, index) {
0103 static_cast<void>(index);
0104
0105 std::cout << std::endl
0106 << "Benchmarking theta=" << theta << ", phi=" << phi << "..."
0107 << std::endl;
0108 if (testPlane) {
0109 std::cout << "- Plane: "
0110 << intersectionTest<PlaneSurface>(*aPlane, phi, theta)
0111 << std::endl;
0112 }
0113 if (testDisc) {
0114 std::cout << "- Disc: " << intersectionTest<DiscSurface>(*aDisc, phi, theta)
0115 << std::endl;
0116 }
0117 if (testCylinder) {
0118 std::cout << "- Cylinder: "
0119 << intersectionTest<CylinderSurface>(*aCylinder, phi, theta)
0120 << std::endl;
0121 }
0122 if (testStraw) {
0123 std::cout << "- Straw: "
0124 << intersectionTest<StrawSurface>(*aStraw, phi,
0125 theta + std::numbers::pi)
0126 << std::endl;
0127 }
0128 }
0129
0130
0131
0132
0133
0134 BOOST_AUTO_TEST_CASE(benchmark_curvature_intersections) {
0135 const auto plane = Surface::makeShared<PlaneSurface>(
0136 Transform3(Translation3(0., 0., 200.)),
0137 std::make_shared<RectangleBounds>(100., 100.));
0138 const auto disc = Surface::makeShared<DiscSurface>(
0139 Transform3(Translation3(0., 0., 200.)),
0140 std::make_shared<RadialBounds>(0., 100.));
0141 const auto cylinder =
0142 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 200., 100.);
0143 const auto measure = [&](const Surface& surface, const Vector3& direction,
0144 const Vector3& curvature) {
0145 const auto bounds = BoundaryTolerance::None();
0146 std::cout << "surface=" << surface.name() << '\n';
0147 std::cout << " ray: "
0148 << microBenchmark(
0149 [&] {
0150 return surface.intersect(tgContext, origin, direction,
0151 bounds);
0152 },
0153 1000, 2000, std::chrono::milliseconds(200))
0154 << '\n';
0155 std::cout << " zero curvature: "
0156 << microBenchmark(
0157 [&] {
0158 return surface.intersect(tgContext, origin, direction,
0159 Vector3::Zero(), bounds);
0160 },
0161 1000, 2000, std::chrono::milliseconds(200))
0162 << '\n';
0163 std::cout << (detail::s_useQuadraticCurvatureCorrection ? " quadratic: "
0164 : " first order: ")
0165 << microBenchmark(
0166 [&] {
0167 return surface.intersect(tgContext, origin, direction,
0168 curvature, bounds);
0169 },
0170 1000, 2000, std::chrono::milliseconds(200))
0171 << '\n';
0172 };
0173 measure(*plane, Vector3::UnitZ(), Vector3(0.0005, 0., 0.));
0174 measure(*disc, Vector3::UnitZ(), Vector3(0.0005, 0., 0.));
0175 measure(*cylinder, Vector3::UnitX(), Vector3(0., 0.0005, 0.));
0176 std::cout << "Oblique crossings (nonzero normal curvature):\n";
0177 const Vector3 tilted = Vector3(0.3, 0., 1.).normalized();
0178 const Vector3 bend = 0.0005 * Vector3(1., 0., -0.3).normalized();
0179 measure(*plane, tilted, bend);
0180 measure(*disc, tilted, bend);
0181 measure(*cylinder, Vector3(1., 0., 0.3).normalized(),
0182 0.0005 * Vector3(-0.3, 0., 1.).normalized());
0183 }
0184
0185 }