File indexing completed on 2025-01-18 09:12:28
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/Tests/CommonHelpers/BenchmarkTools.hpp"
0022
0023 #include <cmath>
0024 #include <numbers>
0025 #include <random>
0026
0027 namespace bdata = boost::unit_test::data;
0028 using namespace Acts::UnitLiterals;
0029
0030 namespace Acts::Test {
0031
0032
0033 unsigned int ntests = 10;
0034 unsigned int nrepts = 2000;
0035 const BoundaryTolerance boundaryTolerance = BoundaryTolerance::Infinite();
0036 const bool testPlane = true;
0037 const bool testDisc = true;
0038 const bool testCylinder = true;
0039 const bool testStraw = true;
0040
0041
0042 GeometryContext tgContext = GeometryContext();
0043
0044
0045
0046 Transform3 at = Transform3::Identity() * Translation3(0_m, 0_m, 10_m) *
0047 AngleAxis3(0.15, Vector3(1.2, 1.2, 0.12).normalized());
0048
0049
0050 auto rb = std::make_shared<RectangleBounds>(1_m, 1_m);
0051 auto aPlane = Surface::makeShared<PlaneSurface>(at, std::move(rb));
0052
0053
0054 auto db = std::make_shared<RadialBounds>(0.2_m, 1.2_m);
0055 auto aDisc = Surface::makeShared<DiscSurface>(at, std::move(db));
0056
0057
0058 auto cb = std::make_shared<CylinderBounds>(10_m, 100_m);
0059 auto aCylinder = Surface::makeShared<CylinderSurface>(at, std::move(cb));
0060
0061
0062 auto aStraw = Surface::makeShared<StrawSurface>(at, 50_cm, 2_m);
0063
0064
0065 Vector3 origin(0., 0., 0.);
0066
0067
0068 Vector3 originStraw(0.3_m, -0.2_m, 11_m);
0069
0070 template <typename surface_t>
0071 MicroBenchmarkResult intersectionTest(const surface_t& surface, double phi,
0072 double theta) {
0073
0074 double cosPhi = std::cos(phi);
0075 double sinPhi = std::sin(phi);
0076 double cosTheta = std::cos(theta);
0077 double sinTheta = std::sin(theta);
0078
0079 Vector3 direction(cosPhi * sinTheta, sinPhi * sinTheta, cosTheta);
0080
0081 return Acts::Test::microBenchmark(
0082 [&] {
0083 return surface.intersect(tgContext, origin, direction,
0084 boundaryTolerance);
0085 },
0086 nrepts);
0087 }
0088
0089 BOOST_DATA_TEST_CASE(
0090 benchmark_surface_intersections,
0091 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 21,
0092 bdata::distribution = std::uniform_real_distribution<double>(
0093 -std::numbers::pi, std::numbers::pi))) ^
0094 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
0095 bdata::distribution =
0096 std::uniform_real_distribution<double>(-0.3, 0.3))) ^
0097 bdata::xrange(ntests),
0098 phi, theta, index) {
0099 (void)index;
0100
0101 std::cout << std::endl
0102 << "Benchmarking theta=" << theta << ", phi=" << phi << "..."
0103 << std::endl;
0104 if (testPlane) {
0105 std::cout << "- Plane: "
0106 << intersectionTest<PlaneSurface>(*aPlane, phi, theta)
0107 << std::endl;
0108 }
0109 if (testDisc) {
0110 std::cout << "- Disc: " << intersectionTest<DiscSurface>(*aDisc, phi, theta)
0111 << std::endl;
0112 }
0113 if (testCylinder) {
0114 std::cout << "- Cylinder: "
0115 << intersectionTest<CylinderSurface>(*aCylinder, phi, theta)
0116 << std::endl;
0117 }
0118 if (testStraw) {
0119 std::cout << "- Straw: "
0120 << intersectionTest<StrawSurface>(*aStraw, phi,
0121 theta + std::numbers::pi)
0122 << std::endl;
0123 }
0124 }
0125
0126 }