ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConeBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ConeBoundsTests.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 /* Note on nomenclature:
20  alpha = cone opening half angle
21  z is the axis of symmetry
22  zmin, zmax define limits for truncated cone
23  phi is clock angle around cone, with x axis corresponding to phi=0
24  Cone segments may be defined with the avphi (central position of segment) and
25  halfphi (extent in phi of cone segment either side of the avphi)
26  Local coords are z, rphi
27 */
28 namespace Acts {
29 
30 namespace Test {
31 
32 BOOST_AUTO_TEST_SUITE(Surfaces)
33 
34 
35 BOOST_AUTO_TEST_CASE(ConeBoundsConstruction) {
36  // test default construction
37  // ConeBounds defaultConstructedConeBounds; // deleted
38  double alpha(M_PI / 8.0), zMin(3.), zMax(6.), halfPhi(M_PI / 4.0),
39  averagePhi(0.);
40  const bool symmetric(false);
41  BOOST_TEST_CHECKPOINT("Four parameter constructor (last two at default)");
42  ConeBounds defaultConeBounds(alpha, symmetric);
43  BOOST_CHECK_EQUAL(defaultConeBounds.type(), SurfaceBounds::eCone);
44  BOOST_TEST_CHECKPOINT("Four parameter constructor");
45  ConeBounds fourParameterConstructed(alpha, symmetric, halfPhi, averagePhi);
46  BOOST_CHECK_EQUAL(fourParameterConstructed.type(), SurfaceBounds::eCone);
47  BOOST_TEST_CHECKPOINT("Five parameter constructor (last two at default)");
48  ConeBounds defaulted5ParamConeBounds(alpha, zMin, zMax);
49  BOOST_CHECK_EQUAL(defaulted5ParamConeBounds.type(), SurfaceBounds::eCone);
50  BOOST_TEST_CHECKPOINT("Five parameter constructor)");
51  ConeBounds fiveParamConstructedConeBounds(alpha, zMin, zMax, halfPhi,
52  averagePhi);
53  BOOST_CHECK_EQUAL(fiveParamConstructedConeBounds.type(),
55  BOOST_TEST_CHECKPOINT("Copy constructor");
56  ConeBounds copyConstructedConeBounds(fiveParamConstructedConeBounds);
57  BOOST_CHECK_EQUAL(copyConstructedConeBounds, fiveParamConstructedConeBounds);
58 }
59 
60 // Streaning and recreation test
61 BOOST_AUTO_TEST_CASE(ConeBoundsRecreation) {
62  double alpha(M_PI / 8.0), zMin(3.), zMax(6.), halfPhi(M_PI / 4.0),
63  averagePhi(0.);
64  // const bool symmetric(false);
65  ConeBounds original(alpha, zMin, zMax, halfPhi, averagePhi);
66  auto valvector = original.values();
67  std::array<double, ConeBounds::eSize> values;
68  std::copy_n(valvector.begin(), ConeBounds::eSize, values.begin());
69  ConeBounds recreated(values);
70  BOOST_CHECK_EQUAL(recreated, original);
71 }
72 
73 // Unit tests for AnnulusBounds exception throwing
74 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
75  double alpha(M_PI / 8.0), zMin(3.), zMax(6.), halfPhi(M_PI / 4.0),
76  averagePhi(0.);
77 
78  // Exception for opening angle smaller 0
79  BOOST_CHECK_THROW(ConeBounds(-alpha, zMin, zMax, halfPhi, averagePhi),
80  std::logic_error);
81  // Exception for opening angle bigger M_PI
82  BOOST_CHECK_THROW(ConeBounds(M_PI, zMin, zMax, halfPhi, averagePhi),
83  std::logic_error);
84  // Exception for swapped zMin and zMax
85  BOOST_CHECK_THROW(ConeBounds(alpha, zMax, zMin, halfPhi, averagePhi),
86  std::logic_error);
87  // Exception for negative half sector phi
88  BOOST_CHECK_THROW(ConeBounds(alpha, zMin, zMax, -halfPhi, averagePhi),
89  std::logic_error);
90  // Exception for out of range phi positioning
91  BOOST_CHECK_THROW(ConeBounds(alpha, zMin, zMax, halfPhi, 2 * M_PI),
92  std::logic_error);
93 }
94 
96 BOOST_AUTO_TEST_CASE(ConeBoundsProperties) {
97  double alpha(M_PI / 8.0), zMin(3.), zMax(6.), halfPhi(M_PI / 4.0),
98  averagePhi(0.);
99  // const bool symmetric(false);
100  const Vector2D origin(0, 0);
101  const Vector2D somewhere(4., 4.);
102  ConeBounds coneBoundsObject(alpha, zMin, zMax, halfPhi, averagePhi);
103  //
105  BOOST_CHECK_EQUAL(coneBoundsObject.type(), SurfaceBounds::eCone);
106  //
108  BOOST_CHECK(!coneBoundsObject.inside(origin));
109  //
111  // std::cout << coneBoundsObject.distanceToBoundary(origin) << std::endl;
112  //
114  CHECK_CLOSE_REL(coneBoundsObject.r(zMin), zMin * std::tan(alpha), 1e-6);
115  //
117  CHECK_CLOSE_REL(coneBoundsObject.tanAlpha(), std::tan(alpha), 1e-6);
118  //
120  CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eAlpha), alpha, 1e-6);
121  //
123  CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMinZ), zMin, 1e-6);
124  //
126  CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMaxZ), zMax, 1e-6);
127  //
129  CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eHalfPhiSector), halfPhi,
130  1e-6);
132  boost::test_tools::output_test_stream dumpOuput;
133  coneBoundsObject.toStream(dumpOuput);
134  BOOST_CHECK(dumpOuput.is_equal(
135  "Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, averagePhi) = "
136  "(0.4142136, 3.0000000, 6.0000000, 0.7853982, 0.0000000)"));
137 }
138 
139 // Unit test for testing ConeBounds assignment
140 BOOST_AUTO_TEST_CASE(ConeBoundsAssignment) {
141  double alpha(M_PI / 8.0), zMin(3.), zMax(6.), halfPhi(M_PI / 4.0),
142  averagePhi(0.);
143  // const bool symmetric(false);
144  ConeBounds originalConeBounds(alpha, zMin, zMax, halfPhi, averagePhi);
145  ConeBounds assignedConeBounds(0.1, 2.3, 4.5, 1.2, 2.1);
146  assignedConeBounds = originalConeBounds;
147  BOOST_CHECK_EQUAL(assignedConeBounds, originalConeBounds);
148 }
149 
150 BOOST_AUTO_TEST_SUITE_END()
151 
152 } // namespace Test
153 
154 } // namespace Acts