Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:11

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