ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceIntersectionBenchmark.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceIntersectionBenchmark.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include <cmath>
14 
24 #include "Acts/Utilities/Units.hpp"
25 
26 namespace bdata = boost::unit_test::data;
27 namespace tt = boost::test_tools;
28 using namespace Acts::UnitLiterals;
29 
30 namespace Acts {
31 namespace Test {
32 
33 // Some randomness & number crunching
34 unsigned int ntests = 10;
35 unsigned int nrepts = 2000;
36 const bool boundaryCheck = false;
37 const bool testPlane = true;
38 const bool testDisc = true;
39 const bool testCylinder = true;
40 const bool testStraw = true;
41 
42 // Create a test context
44 
45 // Create a test plane in 10 m distance
46 // Some random transform
47 Transform3D at = Transform3D::Identity() * Translation3D(0_m, 0_m, 10_m) *
48  AngleAxis3D(0.15, Vector3D(1.2, 1.2, 0.12).normalized());
49 
50 // Define the Plane surface
51 auto rb = std::make_shared<RectangleBounds>(1_m, 1_m);
52 auto aPlane = Surface::makeShared<PlaneSurface>(
53  std::make_shared<Transform3D>(at), std::move(rb));
54 
55 // Define the Disc surface
56 auto db = std::make_shared<RadialBounds>(0.2_m, 1.2_m);
57 auto aDisc = Surface::makeShared<DiscSurface>(std::make_shared<Transform3D>(at),
58  std::move(db));
59 
60 // Define a Cylinder surface
61 auto cb = std::make_shared<CylinderBounds>(10_m, 100_m);
62 auto aCylinder = Surface::makeShared<CylinderSurface>(
63  std::make_shared<Transform3D>(at), std::move(cb));
64 
65 // Define a Straw surface
66 auto aStraw = Surface::makeShared<StrawSurface>(
67  std::make_shared<Transform3D>(at), 50_cm, 2_m);
68 
69 // The orgin of our attempts for plane, disc and cylinder
70 Vector3D origin(0., 0., 0.);
71 
72 // The origin for straw/line attempts
73 Vector3D originStraw(0.3_m, -0.2_m, 11_m);
74 
75 template <typename surface_t>
77  double theta) {
78  // Shoot at it
79  double cosPhi = std::cos(phi);
80  double sinPhi = std::sin(phi);
81  double cosTheta = std::cos(theta);
82  double sinTheta = std::sin(theta);
83 
84  Vector3D direction(cosPhi * sinTheta, sinPhi * sinTheta, cosTheta);
85 
87  [&] {
88  return surface.intersect(tgContext, origin, direction, boundaryCheck);
89  },
90  nrepts);
91 }
92 
94  benchmark_surface_intersections,
95  bdata::random(
96  (bdata::seed = 21,
97  bdata::distribution = std::uniform_real_distribution<>(-M_PI, M_PI))) ^
98  bdata::random((bdata::seed = 22,
99  bdata::distribution =
100  std::uniform_real_distribution<>(-0.3, 0.3))) ^
101  bdata::xrange(ntests),
102  phi, theta, index) {
103  (void)index;
104 
105  std::cout << std::endl
106  << "Benchmarking theta=" << theta << ", phi=" << phi << "..."
107  << std::endl;
108  if (testPlane) {
109  std::cout << "- Plane: "
110  << intersectionTest<PlaneSurface>(*aPlane, phi, theta)
111  << std::endl;
112  }
113  if (testDisc) {
114  std::cout << "- Disc: " << intersectionTest<DiscSurface>(*aDisc, phi, theta)
115  << std::endl;
116  }
117  if (testCylinder) {
118  std::cout << "- Cylinder: "
119  << intersectionTest<CylinderSurface>(*aCylinder, phi, theta)
120  << std::endl;
121  }
122  if (testStraw) {
123  std::cout << "- Straw: "
124  << intersectionTest<StrawSurface>(*aStraw, phi, theta + M_PI)
125  << std::endl;
126  }
127 }
128 
129 } // namespace Test
130 } // namespace Acts