Analysis Software
Documentation for sPHENIX simulation 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 
18 
19 #include <algorithm>
20 #include <array>
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(DiscTrapezoidBoundsConstruction) {
31  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
32  stereo(0.1);
33  //
35  BOOST_CHECK_EQUAL(
36  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, averagePhi).type(),
38  //
40  BOOST_CHECK_EQUAL(
41  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, averagePhi, stereo)
42  .type(),
44  //
46  DiscTrapezoidBounds original(minHalfX, maxHalfX, rMin, rMax, averagePhi);
47  DiscTrapezoidBounds copied(original);
48  BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiscTrapezoid);
49 }
50 
51 // Streaning and recreation test
52 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsRecreation) {
53  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
54  stereo(0.1);
55 
56  DiscTrapezoidBounds original(minHalfX, maxHalfX, rMin, rMax, averagePhi,
57  stereo);
58  auto valvector = original.values();
59  std::array<double, DiscTrapezoidBounds::eSize> values{};
60  std::copy_n(valvector.begin(), DiscTrapezoidBounds::eSize, values.begin());
61  DiscTrapezoidBounds recreated(values);
62  BOOST_CHECK_EQUAL(recreated, original);
63 }
64 
65 // Unit tests for AnnulusBounds exception throwing
66 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsExceptions) {
67  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
68  stereo(0.1);
69 
70  // Exception for opening neg min half x < 0
71  BOOST_CHECK_THROW(
72  DiscTrapezoidBounds(-minHalfX, maxHalfX, rMin, rMax, averagePhi, stereo),
73  std::logic_error);
74 
75  // Exception for opening neg max half x < 0
76  BOOST_CHECK_THROW(
77  DiscTrapezoidBounds(minHalfX, -maxHalfX, rMin, rMax, averagePhi, stereo),
78  std::logic_error);
79 
80  // Exception for opening neg min and max half x < 0
81  BOOST_CHECK_THROW(
82  DiscTrapezoidBounds(-minHalfX, -maxHalfX, rMin, rMax, averagePhi, stereo),
83  std::logic_error);
84 
85  // Exception for opening neg r min
86  BOOST_CHECK_THROW(
87  DiscTrapezoidBounds(minHalfX, maxHalfX, -rMin, rMax, averagePhi, stereo),
88  std::logic_error);
89 
90  // Exception for opening neg r max
91  BOOST_CHECK_THROW(
92  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, -rMax, averagePhi, stereo),
93  std::logic_error);
94 
95  // Exception for opening neg r min and r max
96  BOOST_CHECK_THROW(
97  DiscTrapezoidBounds(minHalfX, maxHalfX, -rMin, -rMax, averagePhi, stereo),
98  std::logic_error);
99 
100  // Exception for out of bound average phi
101  BOOST_CHECK_THROW(
102  DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, 4., stereo),
103  std::logic_error);
104 }
105 
107 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsProperties) {
108  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0),
109  averagePhi(0.0) /*, stereo(0.1)*/;
111  DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
112  averagePhi);
113  //
115  BOOST_CHECK_EQUAL(DiscTrapezoidBoundsObject.type(),
117  //
119  Vector2 origin(0., 0.);
120  Vector2 outside(30., 0.);
121  Vector2 inSurface(2.5, 0.0);
122  //
124  boost::test_tools::output_test_stream dumpOuput;
125  DiscTrapezoidBoundsObject.toStream(dumpOuput);
126  BOOST_CHECK(dumpOuput.is_equal(
127  "Acts::DiscTrapezoidBounds: (innerRadius, outerRadius, halfLengthXminR, "
128  "halfLengthXmaxR, halfLengthY, halfPhiSector, averagePhi, rCenter, "
129  "stereo) = "
130  "(2.0000000, 6.0000000, 1.0000000, 5.0000000, 0.7922870, 0.9851108, "
131  "0.0000000, 2.5243378, 0.0000000)"));
132  //
134  BOOST_CHECK(DiscTrapezoidBoundsObject.inside(inSurface, BoundaryCheck(true)));
135  BOOST_CHECK(!DiscTrapezoidBoundsObject.inside(outside, BoundaryCheck(true)));
136  //
138  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMin(), rMin, 1e-6);
139  //
141  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMax(), rMax, 1e-6);
142  //
144  CHECK_SMALL(DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eAveragePhi),
145  1e-9);
146  //
148  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rCenter(), 2.524337798, 1e-6);
149  //
151  CHECK_SMALL(DiscTrapezoidBoundsObject.stereo(), 1e-6);
152  //
155  DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXminR),
156  minHalfX, 1e-6);
157  //
160  DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXmaxR),
161  maxHalfX, 1e-6);
162  //
164  CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.halfLengthY(), 0.792286991, 1e-6);
165 }
167 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsAssignment) {
168  double minHalfX(1.0), maxHalfX(5.0), rMin(2.0), rMax(6.0), averagePhi(0.0),
169  stereo(0.1);
170  DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
171  averagePhi, stereo);
172  // operator == not implemented in this class
173  //
175  DiscTrapezoidBounds assignedDiscTrapezoidBoundsObject(2.1, 6.6, 3.4, 4.2, 0.3,
176  0.);
177  assignedDiscTrapezoidBoundsObject = DiscTrapezoidBoundsObject;
178  BOOST_CHECK_EQUAL(assignedDiscTrapezoidBoundsObject,
179  DiscTrapezoidBoundsObject);
180 }
181 
182 BOOST_AUTO_TEST_SUITE_END()
183 
184 } // namespace Test
185 
186 } // namespace Acts