Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CylinderBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CylinderBoundsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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 
18 
19 #include <algorithm>
20 #include <array>
21 #include <cmath>
22 #include <stdexcept>
23 #include <vector>
24 
25 namespace Acts {
26 
27 namespace Test {
28 BOOST_AUTO_TEST_SUITE(Surfaces)
30 
31 BOOST_AUTO_TEST_CASE(CylinderBoundsConstruction) {
33  // CylinderBounds defaultConstructedCylinderBounds; // deleted
34  double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0),
35  minBevelZ(-M_PI / 4), maxBevelZ(M_PI / 6);
36  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz).type(),
38  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi).type(),
40  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi, averagePhi).type(),
42  BOOST_CHECK_EQUAL(
43  CylinderBounds(radius, halfz, (double)M_PI, (double)0., minBevelZ).type(),
45  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, (double)M_PI, (double)0.,
46  minBevelZ, maxBevelZ)
47  .type(),
49  //
51  CylinderBounds cylinderBounds(radius, halfz);
52  CylinderBounds copyConstructedCylinderBounds(cylinderBounds);
53  BOOST_CHECK_EQUAL(copyConstructedCylinderBounds, cylinderBounds);
54 }
55 
56 BOOST_AUTO_TEST_CASE(CylinderBoundsRecreation) {
58  // CylinderBounds defaultConstructedCylinderBounds; // deleted
59  double radius(0.5), halfz(10.);
60  // Test construction with radii and default sector
61  auto original = CylinderBounds(radius, halfz);
62  auto valvector = original.values();
63  std::array<double, CylinderBounds::eSize> values{};
64  std::copy_n(valvector.begin(), CylinderBounds::eSize, values.begin());
65  CylinderBounds recreated(values);
66  BOOST_CHECK_EQUAL(original, recreated);
67 }
68 
69 BOOST_AUTO_TEST_CASE(CylinderBoundsException) {
70  double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0);
71 
72  // Negative radius
73  BOOST_CHECK_THROW(CylinderBounds(-radius, halfz, halfphi, averagePhi),
74  std::logic_error);
75 
76  // Negative half length in z
77  BOOST_CHECK_THROW(CylinderBounds(radius, -halfz, halfphi, averagePhi),
78  std::logic_error);
79 
80  // Negative half sector in phi
81  BOOST_CHECK_THROW(CylinderBounds(radius, halfz, -halfphi, averagePhi),
82  std::logic_error);
83 
84  // Half sector in phi out of bounds
85  BOOST_CHECK_THROW(CylinderBounds(radius, halfz, 4., averagePhi),
86  std::logic_error);
87 
88  // Phi position out of bounds
89  BOOST_CHECK_THROW(CylinderBounds(radius, halfz, halfphi, 4.),
90  std::logic_error);
91 }
92 
94 BOOST_AUTO_TEST_CASE(CylinderBoundsProperties) {
95  // CylinderBounds object of radius 0.5 and halfz 20
96  double nominalRadius{0.5};
97  double nominalHalfLength{20.};
98  double halfphi(M_PI / 4.0);
99  double averagePhi(0.0);
100  double bevelMinZ(M_PI / 4);
101  double bevelMaxZ(M_PI / 6);
102  CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
103  CylinderBounds cylinderBoundsSegment(nominalRadius, nominalHalfLength,
104  halfphi, averagePhi);
105  CylinderBounds cylinderBoundsBeveledObject(nominalRadius, nominalHalfLength,
106  M_PI, 0., bevelMinZ, bevelMaxZ);
107 
109  BOOST_CHECK_EQUAL(cylinderBoundsObject.type(), SurfaceBounds::eCylinder);
110 
112  const Vector2 origin{0., 0.};
113  const Vector2 atPiBy2{M_PI / 2., 0.0};
114  const Vector2 atPi{M_PI, 0.0};
115  const Vector2 beyondEnd{0, 30.0};
116  const Vector2 unitZ{0.0, 1.0};
117  const Vector2 unitPhi{1.0, 0.0};
118  const Vector2 withinBevelMin{0.5, -20.012};
119  const Vector2 outsideBevelMin{0.5, -40.};
120  const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
121  const BoundaryCheck trueBoundaryCheckWithLessTolerance(true, true, 0.01,
122  0.01);
123  BOOST_CHECK(
124  cylinderBoundsObject.inside(atPiBy2, trueBoundaryCheckWithTolerance));
125  BOOST_CHECK(
126  !cylinderBoundsSegment.inside(unitPhi, trueBoundaryCheckWithTolerance));
127  BOOST_CHECK(
128  cylinderBoundsObject.inside(origin, trueBoundaryCheckWithTolerance));
129 
130  BOOST_CHECK(!cylinderBoundsObject.inside(withinBevelMin,
131  trueBoundaryCheckWithLessTolerance));
132  BOOST_CHECK(cylinderBoundsBeveledObject.inside(
133  withinBevelMin, trueBoundaryCheckWithLessTolerance));
134  BOOST_CHECK(!cylinderBoundsBeveledObject.inside(
135  outsideBevelMin, trueBoundaryCheckWithLessTolerance));
136 
138  const Vector3 origin3D{0., 0., 0.};
139  BOOST_CHECK(
140  !cylinderBoundsObject.inside3D(origin3D, trueBoundaryCheckWithTolerance));
141 
143  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eR), nominalRadius,
144  1e-6);
145 
148  averagePhi, 1e-6, 1e-6);
149 
151  CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
152  halfphi,
153  1e-6); // fail
154 
156  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ),
157  nominalHalfLength, 1e-6);
158 
160  CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMinZ),
161  bevelMinZ, 1e-6);
162  CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMaxZ),
163  bevelMaxZ, 1e-6);
164 
166  boost::test_tools::output_test_stream dumpOuput;
167  cylinderBoundsObject.toStream(dumpOuput);
168  BOOST_CHECK(dumpOuput.is_equal(
169  "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
170  "averagePhi, bevelMinZ, bevelMaxZ) = (0.5000000, 20.0000000, 3.1415927, "
171  "0.0000000, 0.0000000, 0.0000000)"));
172 }
174 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
175  double nominalRadius{0.5};
176  double nominalHalfLength{20.};
177  CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
178  CylinderBounds assignedCylinderBounds(10.5, 6.6);
179  assignedCylinderBounds = cylinderBoundsObject;
180  BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
181  cylinderBoundsObject.get(CylinderBounds::eR));
182  BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
183 }
184 
185 BOOST_AUTO_TEST_SUITE_END()
186 
187 } // namespace Test
188 
189 } // namespace Acts