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