Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CuboidVolumeBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CuboidVolumeBoundsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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/unit_test.hpp>
10 
20 
21 #include <algorithm>
22 #include <array>
23 #include <memory>
24 #include <stdexcept>
25 #include <utility>
26 #include <vector>
27 
28 namespace Acts {
29 namespace Test {
30 
32 
33 double hx{10.}, hy{20.}, hz{30.};
34 
35 BOOST_AUTO_TEST_SUITE(Geometry)
36 
37 BOOST_AUTO_TEST_CASE(CuboidVolumeConstruction) {
38  // Test Construction
40 
41  // Test copy construction
42  CuboidVolumeBounds copied(box);
43  BOOST_CHECK_EQUAL(box, copied);
44 
45  // Test assigned
46  CuboidVolumeBounds assigned = box;
47  BOOST_CHECK_EQUAL(box, assigned);
48 }
49 
50 BOOST_AUTO_TEST_CASE(CuboidVolumeRecreation) {
51  CuboidVolumeBounds original(hx, hy, hz);
52  auto valvector = original.values();
53  std::array<double, CuboidVolumeBounds::eSize> values{};
54  std::copy_n(valvector.begin(), CuboidVolumeBounds::eSize, values.begin());
55  CuboidVolumeBounds recreated(values);
56  BOOST_CHECK_EQUAL(original, recreated);
57 }
58 
59 BOOST_AUTO_TEST_CASE(CuboidVolumeException) {
60  // Test exception negative x
61  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, hy, hz), std::logic_error);
62  // Test exception negative y
63  BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, hz), std::logic_error);
64  // Test exception negative z
65  BOOST_CHECK_THROW(CuboidVolumeBounds(hx, hy, -hz), std::logic_error);
66  // Other iterations 0
67  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, hy, -hz), std::logic_error);
68  // Other iterations 1
69  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, hz), std::logic_error);
70  // Other iterations 2
71  BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, -hz), std::logic_error);
72  // Other iterations : all
73  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, -hz), std::logic_error);
74 }
75 
76 BOOST_AUTO_TEST_CASE(CuboidVolumeProperties) {
78  // Test the type
79  BOOST_CHECK_EQUAL(box.type(), VolumeBounds::eCuboid);
80  // Test the halflength x
82  // Test the halflength y
84  // Test the halflength z
86  // Test the streaming
87  std::vector<double> actvalues = box.values();
88  std::vector<double> refvalues = {hx, hy, hz};
89  BOOST_CHECK_EQUAL_COLLECTIONS(actvalues.begin(), actvalues.end(),
90  refvalues.begin(), refvalues.end());
91 
92  // Inside position
93  Vector3 inside({5., 10., 8.});
94  // Outside positions in x, y, z
95  std::vector<Vector3> outsides = {
96  {20., 1., -2.}, {1., -30., 2.}, {-1., 2., 100.}};
97 
98  // Inside position
99  BOOST_CHECK(box.inside(inside, s_onSurfaceTolerance));
100 
101  // Outside position
102  for (const auto& outside : outsides) {
103  BOOST_CHECK(!box.inside(outside, s_onSurfaceTolerance));
104  }
105 
106  // Check the binning value positions
110  CHECK_CLOSE_ABS(box.binningBorder(Acts::binR), std::sqrt(hx * hx + hy * hy),
111  s_epsilon);
112 }
113 
114 BOOST_AUTO_TEST_CASE(CuboidVolumeBoundarySurfaces) {
115  CuboidVolumeBounds box(5, 8, 7);
116  auto cvbOrientedSurfaces = box.orientedSurfaces(Transform3::Identity());
117 
118  BOOST_CHECK_EQUAL(cvbOrientedSurfaces.size(), 6);
119 
120  auto geoCtx = GeometryContext();
121 
122  for (auto& os : cvbOrientedSurfaces) {
123  auto osCenter = os.first->center(geoCtx);
124  auto osNormal = os.first->normal(geoCtx);
125  // Check if you step inside the volume with the oriented normal
126  Vector3 insideBox = osCenter + os.second * osNormal;
127  Vector3 outsideBox = osCenter - os.second * osNormal;
128  BOOST_CHECK(box.inside(insideBox));
129  BOOST_CHECK(!box.inside(outsideBox));
130  }
131 
132  Vector3 xaxis(1., 0., 0.);
133  Vector3 yaxis(0., 1., 0.);
134  Vector3 zaxis(0., 0., 1.);
135 
136  // Test the orientation of the boundary surfaces
137  auto nFaceXY =
138  cvbOrientedSurfaces[negativeFaceXY].first->transform(geoCtx).rotation();
139  BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
140  BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
141  BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
142 
143  auto pFaceXY =
144  cvbOrientedSurfaces[positiveFaceXY].first->transform(geoCtx).rotation();
145  BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
146  BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
147  BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
148 
149  auto nFaceYZ =
150  cvbOrientedSurfaces[negativeFaceYZ].first->transform(geoCtx).rotation();
151  BOOST_CHECK(nFaceYZ.col(0).isApprox(yaxis));
152  BOOST_CHECK(nFaceYZ.col(1).isApprox(zaxis));
153  BOOST_CHECK(nFaceYZ.col(2).isApprox(xaxis));
154 
155  auto pFaceYZ =
156  cvbOrientedSurfaces[positiveFaceYZ].first->transform(geoCtx).rotation();
157  BOOST_CHECK(pFaceYZ.col(0).isApprox(yaxis));
158  BOOST_CHECK(pFaceYZ.col(1).isApprox(zaxis));
159  BOOST_CHECK(pFaceYZ.col(2).isApprox(xaxis));
160 
161  auto nFaceZX =
162  cvbOrientedSurfaces[negativeFaceZX].first->transform(geoCtx).rotation();
163  BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
164  BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
165  BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
166 
167  auto pFaceZX =
168  cvbOrientedSurfaces[positiveFaceZX].first->transform(geoCtx).rotation();
169  BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
170  BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
171  BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
172 }
173 
174 BOOST_AUTO_TEST_SUITE_END()
175 
176 } // namespace Test
177 } // namespace Acts