ECCE @ EIC 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 
13 #include <limits>
14 
18 
19 namespace Acts {
20 
21 namespace Test {
22 BOOST_AUTO_TEST_SUITE(Surfaces)
23 
24 
25 BOOST_AUTO_TEST_CASE(RadialBoundsConstruction) {
26  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
27  // test default construction
28  // RadialBounds defaultConstructedRadialBounds; should be deleted
29  //
31  BOOST_CHECK_EQUAL(RadialBounds(minRadius, maxRadius).type(),
33  //
35  BOOST_CHECK_EQUAL(RadialBounds(minRadius, maxRadius, halfPhiSector).type(),
37  //
39  RadialBounds original(minRadius, maxRadius);
40  RadialBounds copied(original);
41  BOOST_CHECK_EQUAL(copied, original);
42 }
43 
44 // Streaning and recreation test
45 BOOST_AUTO_TEST_CASE(RadialBoundsRecreation) {
46  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0), avgPhi(0.1);
47  RadialBounds original(minRadius, maxRadius, halfPhiSector, avgPhi);
48  // const bool symmetric(false);
49  auto valvector = original.values();
50  std::array<double, RadialBounds::eSize> values;
51  std::copy_n(valvector.begin(), RadialBounds::eSize, values.begin());
52  RadialBounds recreated(values);
53  BOOST_CHECK_EQUAL(original, recreated);
54 }
55 
56 // Streaning and recreation test
57 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
58  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0), avgPhi(0.1);
59 
60  // Negative inner radius
61  BOOST_CHECK_THROW(RadialBounds(-minRadius, maxRadius, halfPhiSector, avgPhi),
62  std::logic_error);
63 
64  // Negative outer radius
65  BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, halfPhiSector, avgPhi),
66  std::logic_error);
67 
68  // Negative inner and outer radius
69  BOOST_CHECK_THROW(RadialBounds(-minRadius, -maxRadius, halfPhiSector, avgPhi),
70  std::logic_error);
71 
72  // Swapped radii
73  BOOST_CHECK_THROW(RadialBounds(maxRadius, minRadius, halfPhiSector, avgPhi),
74  std::logic_error);
75 
76  // Out of bound phi sector
77  BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, -5., avgPhi),
78  std::logic_error);
79 
80  // Out of bound phi position
81  BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, halfPhiSector, 5.),
82  std::logic_error);
83 }
84 
86 BOOST_AUTO_TEST_CASE(RadialBoundsProperties) {
87  double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
89  RadialBounds radialBoundsObject(minRadius, maxRadius, halfPhiSector);
90  BOOST_CHECK_EQUAL(radialBoundsObject.type(), SurfaceBounds::eDisc);
91  //
93  Vector2D origin(0., 0.);
94  Vector2D outside(30., 0.);
95  Vector2D inSurface(2., 0.0);
96  CHECK_CLOSE_REL(radialBoundsObject.distanceToBoundary(origin), 1.,
97  1e-6); // makes sense
98  CHECK_CLOSE_REL(radialBoundsObject.distanceToBoundary(outside), 25.,
99  1e-6); // ok
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