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