ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DiscTrapezoidBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DiscTrapezoidBoundsTests.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(DiscTrapezoidBoundsConstruction) {
26  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
27  stereo(0.1);
28  // test default construction
29  // DiscTrapezoidBounds defaultConstructedDiscTrapezoidBounds; should be
30  // deleted
31  //
33  BOOST_CHECK_EQUAL(
34  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, averagePhi).type(),
36  //
38  BOOST_CHECK_EQUAL(
39  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, averagePhi, stereo)
40  .type(),
42  //
44  DiscTrapezoidBounds original(minHalfX, maxHalfX, rMin, rMax, averagePhi);
45  DiscTrapezoidBounds copied(original);
46  BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiscTrapezoid);
47 }
48 
49 // Streaning and recreation test
50 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsRecreation) {
51  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
52  stereo(0.1);
53 
54  DiscTrapezoidBounds original(minHalfX, maxHalfX, rMin, rMax, averagePhi,
55  stereo);
56  auto valvector = original.values();
57  std::array<double, DiscTrapezoidBounds::eSize> values;
58  std::copy_n(valvector.begin(), DiscTrapezoidBounds::eSize, values.begin());
59  DiscTrapezoidBounds recreated(values);
60  BOOST_CHECK_EQUAL(recreated, original);
61 }
62 
63 // Unit tests for AnnulusBounds exception throwing
64 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsExceptions) {
65  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
66  stereo(0.1);
67 
68  // Exception for opening neg min half x < 0
69  BOOST_CHECK_THROW(
70  DiscTrapezoidBounds(-minHalfX, maxHalfX, rMin, rMax, averagePhi, stereo),
71  std::logic_error);
72 
73  // Exception for opening neg max half x < 0
74  BOOST_CHECK_THROW(
75  DiscTrapezoidBounds(minHalfX, -maxHalfX, rMin, rMax, averagePhi, stereo),
76  std::logic_error);
77 
78  // Exception for opening neg min and max half x < 0
79  BOOST_CHECK_THROW(
80  DiscTrapezoidBounds(-minHalfX, -maxHalfX, rMin, rMax, averagePhi, stereo),
81  std::logic_error);
82 
83  // Exception for opening neg r min
84  BOOST_CHECK_THROW(
85  DiscTrapezoidBounds(minHalfX, maxHalfX, -rMin, rMax, averagePhi, stereo),
86  std::logic_error);
87 
88  // Exception for opening neg r max
89  BOOST_CHECK_THROW(
90  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, -rMax, averagePhi, stereo),
91  std::logic_error);
92 
93  // Exception for opening neg r min and r max
94  BOOST_CHECK_THROW(
95  DiscTrapezoidBounds(minHalfX, maxHalfX, -rMin, -rMax, averagePhi, stereo),
96  std::logic_error);
97 
98  // Exception for out of bound average phi
99  BOOST_CHECK_THROW(
100  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, 4., stereo),
101  std::logic_error);
102 }
103 
105 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsProperties) {
106  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0),
107  averagePhi(0.0) /*, stereo(0.1)*/;
109  DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
110  averagePhi);
111  //
113  BOOST_CHECK_EQUAL(DiscTrapezoidBoundsObject.type(),
115  //
117  Vector2D origin(0., 0.);
118  Vector2D outside(30., 0.);
119  Vector2D inSurface(2., 0.0);
120  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.distanceToBoundary(origin), 2.0,
121  1e-6);
122  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.distanceToBoundary(outside), 24.0,
123  1e-6);
124  //
126  boost::test_tools::output_test_stream dumpOuput;
127  DiscTrapezoidBoundsObject.toStream(dumpOuput);
128  BOOST_CHECK(dumpOuput.is_equal(
129  "Acts::DiscTrapezoidBounds: (innerRadius, outerRadius, halfLengthXminR, "
130  "halfLengthXmaxR, halfLengthY, halfPhiSector, averagePhi, rCenter, "
131  "stereo) = "
132  "(2.0000000, 6.0000000, 1.0000000, 5.0000000, 0.7922870, 0.9851108, "
133  "0.0000000, 2.5243378, 0.0000000)"));
134  //
136  BOOST_CHECK(DiscTrapezoidBoundsObject.inside(inSurface, BoundaryCheck(true)));
137  BOOST_CHECK(!DiscTrapezoidBoundsObject.inside(outside, BoundaryCheck(true)));
138  //
140  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMin(), rMin, 1e-6);
141  //
143  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMax(), rMax, 1e-6);
144  //
146  CHECK_SMALL(DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eAveragePhi),
147  1e-9);
148  //
150  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rCenter(), 2.524337798, 1e-6);
151  //
153  CHECK_SMALL(DiscTrapezoidBoundsObject.stereo(), 1e-6);
154  //
157  DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXminR),
158  minHalfX, 1e-6);
159  //
162  DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXmaxR),
163  maxHalfX, 1e-6);
164  //
166  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.halfLengthY(), 0.792286991, 1e-6);
167 }
169 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsAssignment) {
170  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
171  stereo(0.1);
172  DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
173  averagePhi, stereo);
174  // operator == not implemented in this class
175  //
177  DiscTrapezoidBounds assignedDiscTrapezoidBoundsObject(2.1, 6.6, 3.4, 4.2, 0.3,
178  0.);
179  assignedDiscTrapezoidBoundsObject = DiscTrapezoidBoundsObject;
180  BOOST_CHECK_EQUAL(assignedDiscTrapezoidBoundsObject,
181  DiscTrapezoidBoundsObject);
182 }
183 
184 BOOST_AUTO_TEST_SUITE_END()
185 
186 } // namespace Test
187 
188 } // namespace Acts