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 
16 
17 #include <limits>
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  //
122  boost::test_tools::output_test_stream dumpOuput;
123  DiscTrapezoidBoundsObject.toStream(dumpOuput);
124  BOOST_CHECK(dumpOuput.is_equal(
125  "Acts::DiscTrapezoidBounds: (innerRadius, outerRadius, halfLengthXminR, "
126  "halfLengthXmaxR, halfLengthY, halfPhiSector, averagePhi, rCenter, "
127  "stereo) = "
128  "(2.0000000, 6.0000000, 1.0000000, 5.0000000, 0.7922870, 0.9851108, "
129  "0.0000000, 2.5243378, 0.0000000)"));
130  //
132  BOOST_CHECK(DiscTrapezoidBoundsObject.inside(inSurface, BoundaryCheck(true)));
133  BOOST_CHECK(!DiscTrapezoidBoundsObject.inside(outside, BoundaryCheck(true)));
134  //
136  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMin(), rMin, 1e-6);
137  //
139  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMax(), rMax, 1e-6);
140  //
142  CHECK_SMALL(DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eAveragePhi),
143  1e-9);
144  //
146  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rCenter(), 2.524337798, 1e-6);
147  //
149  CHECK_SMALL(DiscTrapezoidBoundsObject.stereo(), 1e-6);
150  //
153  DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXminR),
154  minHalfX, 1e-6);
155  //
158  DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXmaxR),
159  maxHalfX, 1e-6);
160  //
162  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.halfLengthY(), 0.792286991, 1e-6);
163 }
165 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsAssignment) {
166  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
167  stereo(0.1);
168  DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
169  averagePhi, stereo);
170  // operator == not implemented in this class
171  //
173  DiscTrapezoidBounds assignedDiscTrapezoidBoundsObject(2.1, 6.6, 3.4, 4.2, 0.3,
174  0.);
175  assignedDiscTrapezoidBoundsObject = DiscTrapezoidBoundsObject;
176  BOOST_CHECK_EQUAL(assignedDiscTrapezoidBoundsObject,
177  DiscTrapezoidBoundsObject);
178 }
179 
180 BOOST_AUTO_TEST_SUITE_END()
181 
182 } // namespace Test
183 
184 } // namespace Acts