ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LineBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LineBoundsTests.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 namespace Acts {
18 
19 namespace Test {
20 BOOST_AUTO_TEST_SUITE(Surfaces)
22 BOOST_AUTO_TEST_CASE(LineBoundsConstruction) {
24  double radius(0.5), halfz(10.);
25  LineBounds lineBounds(radius, halfz);
26  BOOST_CHECK_EQUAL(lineBounds.type(), SurfaceBounds::eLine);
28  LineBounds copyConstructedLineBounds(lineBounds); // implicit
29  BOOST_CHECK_EQUAL(copyConstructedLineBounds.type(), SurfaceBounds::eLine);
30 }
31 
33 BOOST_AUTO_TEST_CASE(LineBoundsRecreation) {
34  double nominalRadius{0.5};
35  double nominalHalfLength{20.};
36  LineBounds original(nominalRadius, nominalHalfLength);
37  LineBounds recreated(original);
38  auto valvector = original.values();
39  std::array<double, LineBounds::eSize> values;
40  std::copy_n(valvector.begin(), LineBounds::eSize, values.begin());
41  BOOST_CHECK_EQUAL(original, recreated);
42 }
43 
45 BOOST_AUTO_TEST_CASE(LineBoundsExceptions) {
46  double nominalRadius{0.5};
47  double nominalHalfLength{20.};
48  // Negative radius
49  BOOST_CHECK_THROW(LineBounds(-nominalRadius, nominalHalfLength),
50  std::logic_error);
51  // Negative half length
52  BOOST_CHECK_THROW(LineBounds(nominalRadius, -nominalHalfLength),
53  std::logic_error);
54 
55  // Negative radius and half length
56  BOOST_CHECK_THROW(LineBounds(-nominalRadius, -nominalHalfLength),
57  std::logic_error);
58 }
59 
61 BOOST_AUTO_TEST_CASE(LineBoundsAssignment) {
62  double nominalRadius{0.5};
63  double nominalHalfLength{20.};
64  LineBounds lineBoundsObject(nominalRadius, nominalHalfLength);
65  LineBounds assignedLineBounds = lineBoundsObject;
66  BOOST_CHECK_EQUAL(assignedLineBounds, lineBoundsObject);
67 }
68 
70 BOOST_AUTO_TEST_CASE(LineBoundsProperties) {
71  // LineBounds object of radius 0.5 and halfz 20
72  double nominalRadius{0.5};
73  double nominalHalfLength{20.};
74  LineBounds lineBoundsObject(nominalRadius, nominalHalfLength);
75 
77  BOOST_CHECK_EQUAL(lineBoundsObject.type(), SurfaceBounds::eLine);
78 
80  const Vector2D origin{0., 0.};
81  const Vector2D atRadius{0.5, 10.};
82  const Vector2D beyondEnd{0.0, 30.0};
83  const Vector2D unitZ{0.0, 1.0};
84  const Vector2D unitR{1.0, 0.0};
85  const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
86  // This fails because the bounds are not inclusive.
87  BOOST_CHECK(
88  !lineBoundsObject.inside(atRadius, trueBoundaryCheckWithTolerance));
89  BOOST_CHECK(
90  !lineBoundsObject.inside(beyondEnd, trueBoundaryCheckWithTolerance));
91  BOOST_CHECK(lineBoundsObject.inside(unitZ, trueBoundaryCheckWithTolerance));
92  BOOST_CHECK(!lineBoundsObject.inside(unitR, trueBoundaryCheckWithTolerance));
93 
95 
96  BOOST_CHECK(lineBoundsObject.inside(Vector2D{-0.2, 10},
97  trueBoundaryCheckWithTolerance));
98  BOOST_CHECK(!lineBoundsObject.inside(Vector2D{-0.8, 10},
99  trueBoundaryCheckWithTolerance));
100 
102  CHECK_CLOSE_REL(lineBoundsObject.distanceToBoundary(unitR), 1.,
103  1e-6); // why?
104 
106  BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eR), nominalRadius);
107 
109  BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eHalfLengthZ),
110  nominalHalfLength);
111 
113  boost::test_tools::output_test_stream dumpOuput;
114  lineBoundsObject.toStream(dumpOuput);
115  BOOST_CHECK(dumpOuput.is_equal(
116  "Acts::LineBounds: (radius, halflengthInZ) = (0.5000000, 20.0000000)"));
117 }
118 
119 BOOST_AUTO_TEST_SUITE_END()
120 
121 } // namespace Test
122 
123 } // namespace Acts