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 
16 
17 #include <limits>
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.get(CylinderBounds::eR), nominalRadius,
116  1e-6);
117 
119  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eAveragePhi),
120  averagePhi, 1e-6);
121 
123  CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
124  halfphi,
125  1e-6); // fail
126 
128  CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ),
129  nominalHalfLength, 1e-6);
130 
132  boost::test_tools::output_test_stream dumpOuput;
133  cylinderBoundsObject.toStream(dumpOuput);
134  BOOST_CHECK(dumpOuput.is_equal(
135  "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
136  "averagePhi) = (0.5000000, 20.0000000, 3.1415927, 0.0000000)"));
137 }
139 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
140  double nominalRadius{0.5};
141  double nominalHalfLength{20.};
142  CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
143  CylinderBounds assignedCylinderBounds(10.5, 6.6);
144  assignedCylinderBounds = cylinderBoundsObject;
145  BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
146  cylinderBoundsObject.get(CylinderBounds::eR));
147  BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
148 }
149 
150 BOOST_AUTO_TEST_SUITE_END()
151 
152 } // namespace Test
153 
154 } // namespace Acts