Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EllipseBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EllipseBoundsTests.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 
18 
19 #include <algorithm>
20 #include <array>
21 #include <cmath>
22 #include <stdexcept>
23 #include <vector>
24 
25 namespace Acts {
26 
27 namespace Test {
28 BOOST_AUTO_TEST_SUITE(Surfaces)
29 
30 
31 BOOST_AUTO_TEST_CASE(EllipseBoundsConstruction) {
32  double innerRx(10.), innerRy(15.), outerRx(25.), outerRy(30.),
33  phiSector(M_PI / 2.), averagePhi(0.);
34 
35  // test default construction
36  // EllipseBounds defaultConstructedEllipseBounds; //deleted
37  //
39  BOOST_CHECK_EQUAL(
40  EllipseBounds(innerRx, innerRy, outerRx, outerRy, phiSector, averagePhi)
41  .type(),
43  //
45  EllipseBounds original(innerRx, innerRy, outerRx, outerRy, phiSector,
46  averagePhi);
47  EllipseBounds copied(original);
48  BOOST_CHECK_EQUAL(copied, original);
49 }
50 
51 // Streaning and recreation test
52 BOOST_AUTO_TEST_CASE(EllipseBoundsRecreation) {
53  double innerRx(10.), innerRy(15.), outerRx(25.), outerRy(30.),
54  phiSector(M_PI / 2.), averagePhi(0.);
55  // const bool symmetric(false);
56  EllipseBounds original(innerRx, innerRy, outerRx, outerRy, phiSector,
57  averagePhi);
58  auto valvector = original.values();
59  std::array<double, EllipseBounds::eSize> values{};
60  std::copy_n(valvector.begin(), EllipseBounds::eSize, values.begin());
61  EllipseBounds recreated(values);
62  BOOST_CHECK_EQUAL(recreated, original);
63 }
64 
65 // Unit tests for AnnulusBounds exception throwing
66 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
67  double innerRx(10.), innerRy(15.), outerRx(25.), outerRy(30.),
68  phiSector(M_PI / 2.), averagePhi(0.);
69  // Exception for innerRx < 0
70  BOOST_CHECK_THROW(
71  EllipseBounds(-innerRx, innerRy, outerRx, outerRy, phiSector, averagePhi),
72  std::logic_error);
73  // Exception for innerRy < 0
74  BOOST_CHECK_THROW(
75  EllipseBounds(innerRx, -innerRy, outerRx, outerRy, phiSector, averagePhi),
76  std::logic_error);
77  // Exception for innerRx < 0 and innerRy < 0
78  BOOST_CHECK_THROW(EllipseBounds(-innerRx, -innerRy, outerRx, outerRy,
79  phiSector, averagePhi),
80  std::logic_error);
81  // Exception for opening outerRx <= 0
82  BOOST_CHECK_THROW(
83  EllipseBounds(innerRx, innerRy, 0., outerRy, phiSector, averagePhi),
84  std::logic_error);
85  // Exception for opening outerRy <= 0
86  BOOST_CHECK_THROW(
87  EllipseBounds(innerRx, innerRy, outerRx, 0., phiSector, averagePhi),
88  std::logic_error);
89  // Exception for iouterRx < 0 and outerRy < 0
90  BOOST_CHECK_THROW(EllipseBounds(innerRx, innerRy, -outerRx, -outerRy,
91  phiSector, averagePhi),
92  std::logic_error);
93  // Exception for innerRx > outerRx
94  BOOST_CHECK_THROW(
95  EllipseBounds(outerRx, innerRy, innerRx, outerRy, phiSector, averagePhi),
96  std::logic_error);
97  // Exception for innerRxy > outerRy
98  BOOST_CHECK_THROW(
99  EllipseBounds(innerRx, outerRy, outerRx, innerRy, phiSector, averagePhi),
100  std::logic_error);
101  // Exception for negative phiSector
102  BOOST_CHECK_THROW(
103  EllipseBounds(innerRx, innerRy, outerRx, outerRy, -phiSector, averagePhi),
104  std::logic_error);
105  // Exception for average phi out of bound
106  BOOST_CHECK_THROW(
107  EllipseBounds(innerRx, innerRy, outerRx, outerRy, phiSector, 4.),
108  std::logic_error);
109 }
110 
112 BOOST_AUTO_TEST_CASE(EllipseBoundsProperties) {
113  double innerRx(10.), outerRx(15.), innerRy(15.), outerRy(20.), averagePhi(0.),
114  phiSector(M_PI / 2.);
116  EllipseBounds ellipseBoundsObject(innerRx, innerRy, outerRx, outerRy,
117  phiSector, averagePhi);
118  //
120  BOOST_CHECK_EQUAL(ellipseBoundsObject.type(), SurfaceBounds::eEllipse);
121  //
122  // clone already tested
123  //
125  Vector2 origin(0., 0.);
126  Vector2 outsideBy15(0., 30.);
127  Vector2 inRectangle(17., 11.);
128  //
130  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRx), innerRx);
131  //
133  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRx), outerRx);
134  //
136  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRy), innerRy);
137  //
139  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRy), outerRy);
140  //
142  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eAveragePhi),
143  averagePhi);
144  //
146  // std::vector<Vector2> expectedVertices{{15, 0}, {0, 20}, {-15, 0}, {0,
147  // -20}}; const auto& actualVertices = ellipseBoundsObject.vertices(4);
148  // BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(),
149  // actualVertices.cend(),
150  // expectedVertices.cbegin(),
151  // expectedVertices.cend());
152  //
154  BOOST_CHECK_EQUAL(ellipseBoundsObject.boundingBox(),
155  RectangleBounds(15., 20.));
156  //
158  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eHalfPhiSector),
159  M_PI / 2.);
160  //
162  boost::test_tools::output_test_stream dumpOuput;
163  ellipseBoundsObject.toStream(dumpOuput);
164  BOOST_CHECK(dumpOuput.is_equal(
165  "Acts::EllipseBounds: (innerRadius0, outerRadius0, innerRadius1, "
166  "outerRadius1, hPhiSector, averagePhi) = (10.0000000, 15.0000000, "
167  "15.0000000, "
168  "20.0000000, 0.0000000, 1.5707963, 0.0000000)"));
169  //
171  BOOST_CHECK(!ellipseBoundsObject.inside(inRectangle, BoundaryCheck(true)));
172  // dont understand why this is so:
173  BOOST_CHECK(!ellipseBoundsObject.inside(outsideBy15, BoundaryCheck(true)));
174 }
176 BOOST_AUTO_TEST_CASE(EllipseBoundsAssignment) {
177  double innerRx(10.), outerRx(15.), innerRy(15.), outerRy(20.), averagePhi(0.),
178  phiSector(M_PI / 2.);
179  EllipseBounds ellipseBoundsObject(innerRx, outerRx, innerRy, outerRy,
180  averagePhi, phiSector);
181  EllipseBounds similarlyConstructeEllipseBoundsObject(
182  innerRx, outerRx, innerRy, outerRy, averagePhi, phiSector);
184  BOOST_CHECK_EQUAL(ellipseBoundsObject,
185  similarlyConstructeEllipseBoundsObject);
186  //
188  EllipseBounds assignedEllipseBoundsObject(11., 12., 17., 18., 1.);
189  // object, in some sense
190  assignedEllipseBoundsObject = ellipseBoundsObject;
191  BOOST_CHECK_EQUAL(assignedEllipseBoundsObject, ellipseBoundsObject);
192 }
193 
194 BOOST_AUTO_TEST_SUITE_END()
195 
196 } // namespace Test
197 
198 } // namespace Acts