Analysis Software
Documentation for sPHENIX simulation 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 
17 
18 #include <algorithm>
19 #include <array>
20 #include <stdexcept>
21 #include <vector>
22 
23 namespace Acts {
24 
25 namespace Test {
26 BOOST_AUTO_TEST_SUITE(Surfaces)
28 BOOST_AUTO_TEST_CASE(LineBoundsConstruction) {
30  double radius(0.5), halfz(10.);
31  LineBounds lineBounds(radius, halfz);
32  BOOST_CHECK_EQUAL(lineBounds.type(), SurfaceBounds::eLine);
34  LineBounds copyConstructedLineBounds(lineBounds); // implicit
35  BOOST_CHECK_EQUAL(copyConstructedLineBounds.type(), SurfaceBounds::eLine);
36 }
37 
39 BOOST_AUTO_TEST_CASE(LineBoundsRecreation) {
40  double nominalRadius{0.5};
41  double nominalHalfLength{20.};
42  LineBounds original(nominalRadius, nominalHalfLength);
43  LineBounds recreated(original);
44  auto valvector = original.values();
45  std::array<double, LineBounds::eSize> values{};
46  std::copy_n(valvector.begin(), LineBounds::eSize, values.begin());
47  BOOST_CHECK_EQUAL(original, recreated);
48 }
49 
51 BOOST_AUTO_TEST_CASE(LineBoundsExceptions) {
52  double nominalRadius{0.5};
53  double nominalHalfLength{20.};
54  // Negative radius
55  BOOST_CHECK_THROW(LineBounds(-nominalRadius, nominalHalfLength),
56  std::logic_error);
57  // Negative half length
58  BOOST_CHECK_THROW(LineBounds(nominalRadius, -nominalHalfLength),
59  std::logic_error);
60 
61  // Negative radius and half length
62  BOOST_CHECK_THROW(LineBounds(-nominalRadius, -nominalHalfLength),
63  std::logic_error);
64 }
65 
67 BOOST_AUTO_TEST_CASE(LineBoundsAssignment) {
68  double nominalRadius{0.5};
69  double nominalHalfLength{20.};
70  LineBounds lineBoundsObject(nominalRadius, nominalHalfLength);
71  LineBounds assignedLineBounds = lineBoundsObject;
72  BOOST_CHECK_EQUAL(assignedLineBounds, lineBoundsObject);
73 }
74 
76 BOOST_AUTO_TEST_CASE(LineBoundsProperties) {
77  // LineBounds object of radius 0.5 and halfz 20
78  double nominalRadius{0.5};
79  double nominalHalfLength{20.};
80  LineBounds lineBoundsObject(nominalRadius, nominalHalfLength);
81 
83  BOOST_CHECK_EQUAL(lineBoundsObject.type(), SurfaceBounds::eLine);
84 
86  const Vector2 origin{0., 0.};
87  const Vector2 atRadius{0.5, 10.};
88  const Vector2 beyondEnd{0.0, 30.0};
89  const Vector2 unitZ{0.0, 1.0};
90  const Vector2 unitR{1.0, 0.0};
91  const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
92  // This fails because the bounds are not inclusive.
93  BOOST_CHECK(
94  !lineBoundsObject.inside(atRadius, trueBoundaryCheckWithTolerance));
95  BOOST_CHECK(
96  !lineBoundsObject.inside(beyondEnd, trueBoundaryCheckWithTolerance));
97  BOOST_CHECK(lineBoundsObject.inside(unitZ, trueBoundaryCheckWithTolerance));
98  BOOST_CHECK(!lineBoundsObject.inside(unitR, trueBoundaryCheckWithTolerance));
99 
101 
102  BOOST_CHECK(lineBoundsObject.inside(Vector2{-0.2, 10},
103  trueBoundaryCheckWithTolerance));
104  BOOST_CHECK(!lineBoundsObject.inside(Vector2{-0.8, 10},
105  trueBoundaryCheckWithTolerance));
106 
108  BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eR), nominalRadius);
109 
111  BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eHalfLengthZ),
112  nominalHalfLength);
113 
115  boost::test_tools::output_test_stream dumpOuput;
116  lineBoundsObject.toStream(dumpOuput);
117  BOOST_CHECK(dumpOuput.is_equal(
118  "Acts::LineBounds: (radius, halflengthInZ) = (0.5000000, 20.0000000)"));
119 }
120 
121 BOOST_AUTO_TEST_SUITE_END()
122 
123 } // namespace Test
124 
125 } // namespace Acts