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 
22 #include "Acts/Utilities/Units.hpp"
23 
24 #include <cmath>
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>(at, std::move(rb));
53 
54 // Define the Disc surface
55 auto db = std::make_shared<RadialBounds>(0.2_m, 1.2_m);
56 auto aDisc = Surface::makeShared<DiscSurface>(at, std::move(db));
57 
58 // Define a Cylinder surface
59 auto cb = std::make_shared<CylinderBounds>(10_m, 100_m);
60 auto aCylinder = Surface::makeShared<CylinderSurface>(at, std::move(cb));
61 
62 // Define a Straw surface
63 auto aStraw = Surface::makeShared<StrawSurface>(at, 50_cm, 2_m);
64 
65 // The orgin of our attempts for plane, disc and cylinder
66 Vector3D origin(0., 0., 0.);
67 
68 // The origin for straw/line attempts
69 Vector3D originStraw(0.3_m, -0.2_m, 11_m);
70 
71 template <typename surface_t>
73  double theta) {
74  // Shoot at it
75  double cosPhi = std::cos(phi);
76  double sinPhi = std::sin(phi);
77  double cosTheta = std::cos(theta);
78  double sinTheta = std::sin(theta);
79 
80  Vector3D direction(cosPhi * sinTheta, sinPhi * sinTheta, cosTheta);
81 
83  [&] {
84  return surface.intersect(tgContext, origin, direction, boundaryCheck);
85  },
86  nrepts);
87 }
88 
90  benchmark_surface_intersections,
91  bdata::random(
92  (bdata::seed = 21,
93  bdata::distribution = std::uniform_real_distribution<>(-M_PI, M_PI))) ^
94  bdata::random((bdata::seed = 22,
95  bdata::distribution =
96  std::uniform_real_distribution<>(-0.3, 0.3))) ^
98  phi, theta, index) {
99  (void)index;
100 
101  std::cout << std::endl
102  << "Benchmarking theta=" << theta << ", phi=" << phi << "..."
103  << std::endl;
104  if (testPlane) {
105  std::cout << "- Plane: "
106  << intersectionTest<PlaneSurface>(*aPlane, phi, theta)
107  << std::endl;
108  }
109  if (testDisc) {
110  std::cout << "- Disc: " << intersectionTest<DiscSurface>(*aDisc, phi, theta)
111  << std::endl;
112  }
113  if (testCylinder) {
114  std::cout << "- Cylinder: "
115  << intersectionTest<CylinderSurface>(*aCylinder, phi, theta)
116  << std::endl;
117  }
118  if (testStraw) {
119  std::cout << "- Straw: "
120  << intersectionTest<StrawSurface>(*aStraw, phi, theta + M_PI)
121  << std::endl;
122  }
123 }
124 
125 } // namespace Test
126 } // namespace Acts