Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RadialBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RadialBoundsTests.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 <cmath>
21 #include <stdexcept>
22 #include <vector>
23 
24 namespace Acts {
25 
26 namespace Test {
27 BOOST_AUTO_TEST_SUITE(Surfaces)
28 
29 
30 BOOST_AUTO_TEST_CASE(RadialBoundsConstruction) {
31  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
32  // test default construction
33  // RadialBounds defaultConstructedRadialBounds; should be deleted
34  //
36  BOOST_CHECK_EQUAL(RadialBounds(minRadius, maxRadius).type(),
38  //
40  BOOST_CHECK_EQUAL(RadialBounds(minRadius, maxRadius, halfPhiSector).type(),
42  //
44  RadialBounds original(minRadius, maxRadius);
45  RadialBounds copied(original);
46  BOOST_CHECK_EQUAL(copied, original);
47 }
48 
49 // Streaning and recreation test
50 BOOST_AUTO_TEST_CASE(RadialBoundsRecreation) {
51  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0), avgPhi(0.1);
52  RadialBounds original(minRadius, maxRadius, halfPhiSector, avgPhi);
53  // const bool symmetric(false);
54  auto valvector = original.values();
55  std::array<double, RadialBounds::eSize> values{};
56  std::copy_n(valvector.begin(), RadialBounds::eSize, values.begin());
57  RadialBounds recreated(values);
58  BOOST_CHECK_EQUAL(original, recreated);
59 }
60 
61 // Streaning and recreation test
62 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
63  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0), avgPhi(0.1);
64 
65  // Negative inner radius
66  BOOST_CHECK_THROW(RadialBounds(-minRadius, maxRadius, halfPhiSector, avgPhi),
67  std::logic_error);
68 
69  // Negative outer radius
70  BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, halfPhiSector, avgPhi),
71  std::logic_error);
72 
73  // Negative inner and outer radius
74  BOOST_CHECK_THROW(RadialBounds(-minRadius, -maxRadius, halfPhiSector, avgPhi),
75  std::logic_error);
76 
77  // Swapped radii
78  BOOST_CHECK_THROW(RadialBounds(maxRadius, minRadius, halfPhiSector, avgPhi),
79  std::logic_error);
80 
81  // Out of bound phi sector
82  BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, -5., avgPhi),
83  std::logic_error);
84 
85  // Out of bound phi position
86  BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, halfPhiSector, 5.),
87  std::logic_error);
88 }
89 
91 BOOST_AUTO_TEST_CASE(RadialBoundsProperties) {
92  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
94  RadialBounds radialBoundsObject(minRadius, maxRadius, halfPhiSector);
95  BOOST_CHECK_EQUAL(radialBoundsObject.type(), SurfaceBounds::eDisc);
96  //
98  Vector2 outside(30., 0.);
99  Vector2 inSurface(2., 0.0);
100 
102  boost::test_tools::output_test_stream dumpOuput;
103  radialBoundsObject.toStream(dumpOuput);
104  BOOST_CHECK(
105  dumpOuput.is_equal("Acts::RadialBounds: (innerRadius, outerRadius, "
106  "hPhiSector, averagePhi) = (1.0000000, "
107  "5.0000000, 0.3926991, 0.0000000)"));
108  //
110  BOOST_CHECK(radialBoundsObject.inside(inSurface, BoundaryCheck(true)));
111  BOOST_CHECK(!radialBoundsObject.inside(outside, BoundaryCheck(true)));
112  //
114  BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMinR), minRadius);
115  //
117  BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMaxR), maxRadius);
118  //
120  BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eAveragePhi), 0.0);
121  //
123  BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eHalfPhiSector),
124  halfPhiSector);
125 }
127 BOOST_AUTO_TEST_CASE(RadialBoundsAssignment) {
128  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
129  RadialBounds radialBoundsObject(minRadius, maxRadius, halfPhiSector);
130  // operator == not implemented in this class
131  //
133  RadialBounds assignedRadialBoundsObject(10.1, 123.);
134  assignedRadialBoundsObject = radialBoundsObject;
135  BOOST_CHECK_EQUAL(assignedRadialBoundsObject, radialBoundsObject);
136 }
137 
138 BOOST_AUTO_TEST_SUITE_END()
139 
140 } // namespace Test
141 
142 } // namespace Acts