ECCE @ EIC 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 
13 #include <limits>
14 
18 
19 namespace Acts {
20 
21 namespace Test {
22 BOOST_AUTO_TEST_SUITE(Surfaces)
24 
25 BOOST_AUTO_TEST_CASE(CylinderBoundsConstruction) {
27  // CylinderBounds defaultConstructedCylinderBounds; // deleted
28  double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0);
29  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz).type(),
31  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi).type(),
33  BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi, averagePhi).type(),
35  //
37  CylinderBounds cylinderBounds(radius, halfz);
38  CylinderBounds copyConstructedCylinderBounds(cylinderBounds);
39  BOOST_CHECK_EQUAL(copyConstructedCylinderBounds, cylinderBounds);
40 }
41 
42 BOOST_AUTO_TEST_CASE(CylinderBoundsRecreation) {
44  // CylinderBounds defaultConstructedCylinderBounds; // deleted
45  double radius(0.5), halfz(10.);
46  // Test construction with radii and default sector
47  auto original = CylinderBounds(radius, halfz);
48  auto valvector = original.values();
49  std::array<double, CylinderBounds::eSize> values;
50  std::copy_n(valvector.begin(), CylinderBounds::eSize, values.begin());
51  CylinderBounds recreated(values);
52  BOOST_CHECK_EQUAL(original, recreated);
53 }
54 
55 BOOST_AUTO_TEST_CASE(CylinderBoundsException) {
56  double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0);
57 
58  // Negative radius
59  BOOST_CHECK_THROW(CylinderBounds(-radius, halfz, halfphi, averagePhi),
60  std::logic_error);
61 
62  // Negative half length in z
63  BOOST_CHECK_THROW(CylinderBounds(radius, -halfz, halfphi, averagePhi),
64  std::logic_error);
65 
66  // Negative half sector in phi
67  BOOST_CHECK_THROW(CylinderBounds(radius, halfz, -halfphi, averagePhi),
68  std::logic_error);
69 
70  // Half sector in phi out of bounds
71  BOOST_CHECK_THROW(CylinderBounds(radius, halfz, 4., averagePhi),
72  std::logic_error);
73 
74  // Phi position out of bounds
75  BOOST_CHECK_THROW(CylinderBounds(radius, halfz, halfphi, 4.),
76  std::logic_error);
77 }
78 
80 BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CylinderBoundsProperties, 4)
81 BOOST_AUTO_TEST_CASE(CylinderBoundsProperties) {
82  // CylinderBounds object of radius 0.5 and halfz 20
83  double nominalRadius{0.5};
84  double nominalHalfLength{20.};
85  double halfphi(M_PI / 4.0);
86  double averagePhi(0.0);
87  CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
88  CylinderBounds cylinderBoundsSegment(nominalRadius, nominalHalfLength,
89  halfphi, averagePhi);
90 
92  BOOST_CHECK_EQUAL(cylinderBoundsObject.type(), SurfaceBounds::eCylinder);
93 
95  const Vector2D origin{0., 0.};
96  const Vector2D atPiBy2{M_PI / 2., 0.0};
97  const Vector2D atPi{M_PI, 0.0};
98  const Vector2D beyondEnd{0, 30.0};
99  const Vector2D unitZ{0.0, 1.0};
100  const Vector2D unitPhi{1.0, 0.0};
101  const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
102  BOOST_CHECK(
103  cylinderBoundsObject.inside(atPiBy2, trueBoundaryCheckWithTolerance));
104  BOOST_CHECK(
105  !cylinderBoundsSegment.inside(unitPhi, trueBoundaryCheckWithTolerance));
106  BOOST_CHECK(
107  cylinderBoundsObject.inside(origin, trueBoundaryCheckWithTolerance));
108 
110  const Vector3D origin3D{0., 0., 0.};
111  BOOST_CHECK(
112  !cylinderBoundsObject.inside3D(origin3D, trueBoundaryCheckWithTolerance));
113 
115  CHECK_CLOSE_REL(cylinderBoundsObject.distanceToBoundary(origin), 0.5,
116  1e-6); // fail
117  CHECK_CLOSE_REL(cylinderBoundsObject.distanceToBoundary(beyondEnd), 10.0,
118  1e-6); // pass
119  double sinPiBy8 = std::sin(M_PI / 8.);
120  CHECK_CLOSE_REL(cylinderBoundsSegment.distanceToBoundary(atPi), sinPiBy8,
121  1e-6); // pass
122  CHECK_CLOSE_REL(cylinderBoundsSegment.distanceToBoundary(origin), 0.5,
123  1e-6); // fail
124 
126  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eR), nominalRadius,
127  1e-6);
128 
130  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eAveragePhi),
131  averagePhi, 1e-6);
132 
134  CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
135  halfphi,
136  1e-6); // fail
137 
139  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ),
140  nominalHalfLength, 1e-6);
141 
143  boost::test_tools::output_test_stream dumpOuput;
144  cylinderBoundsObject.toStream(dumpOuput);
145  BOOST_CHECK(dumpOuput.is_equal(
146  "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
147  "averagePhi) = (0.5000000, 20.0000000, 3.1415927, 0.0000000)"));
148 }
150 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
151  double nominalRadius{0.5};
152  double nominalHalfLength{20.};
153  CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
154  CylinderBounds assignedCylinderBounds(10.5, 6.6);
155  assignedCylinderBounds = cylinderBoundsObject;
156  BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
157  cylinderBoundsObject.get(CylinderBounds::eR));
158  BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
159 }
160 
161 BOOST_AUTO_TEST_SUITE_END()
162 
163 } // namespace Test
164 
165 } // namespace Acts