Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CutoutCylinderVolumeBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CutoutCylinderVolumeBoundsTests.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 
19 
20 #include <algorithm>
21 #include <array>
22 #include <iostream>
23 #include <memory>
24 #include <stdexcept>
25 #include <utility>
26 #include <vector>
27 
28 namespace Acts {
29 namespace Test {
30 
31 BOOST_AUTO_TEST_SUITE(Geometry)
32 
33 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsConstruction) {
34  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
35  ccvb.toStream(std::cout);
36 
37  // Test copy construction
38  CutoutCylinderVolumeBounds copied(ccvb);
39  BOOST_CHECK_EQUAL(ccvb, copied);
40 
41  // Test assigned
42  CutoutCylinderVolumeBounds assigned = ccvb;
43  BOOST_CHECK_EQUAL(ccvb, assigned);
44 }
45 
46 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsRecreation) {
47  CutoutCylinderVolumeBounds original(5, 10, 15, 30, 25);
48  std::array<double, CutoutCylinderVolumeBounds::eSize> values{};
49  std::vector<double> valvector = original.values();
50  std::copy_n(valvector.begin(), CutoutCylinderVolumeBounds::eSize,
51  values.begin());
53  BOOST_CHECK_EQUAL(original, recreated);
54 }
55 
56 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsExceptions) {
57  double rmin{5}, rmed{10}, rmax{15}, hz{30}, hzc{25};
58 
59  // Test negative rmin
60  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(-rmin, rmed, rmax, hz, hzc),
61  std::logic_error);
62 
63  // Test negative rmed
64  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, -rmed, rmax, hz, hzc),
65  std::logic_error);
66 
67  // Test negative rmax
68  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmed, -rmax, hz, hzc),
69  std::logic_error);
70 
71  // Test swapped rmin / rmed
72  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmed, rmin, rmax, hz, hzc),
73  std::logic_error);
74 
75  // Test swapped rmin / rmax
76  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmax, rmed, rmin, hz, hzc),
77  std::logic_error);
78 
79  // Test swapped rmed / rmax
80  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmax, rmed, hz, hzc),
81  std::logic_error);
82 
83  // Test negative hz
84  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmed, rmax, -hz, hzc),
85  std::logic_error);
86 
87  // Test negative hzc
88  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmed, rmax, hz, -hzc),
89  std::logic_error);
90 }
91 
92 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsAccess) {
93  double rmin{5}, rmed{10}, rmax{15}, hz{30}, hzc{25};
94  CutoutCylinderVolumeBounds ccvb(rmin, rmed, rmax, hz, hzc);
95 
96  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eMinR), rmin);
97  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eMedR), rmed);
98  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eMaxR), rmax);
99  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eHalfLengthZ), hz);
100  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eHalfLengthZcutout),
101  hzc);
102 }
103 
104 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsInside) {
105  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
106 
107  BOOST_CHECK(!ccvb.inside({0, 0, 0}));
108  BOOST_CHECK(!ccvb.inside({0, 3, 0}));
109  BOOST_CHECK(!ccvb.inside({3, 0, 0}));
110  BOOST_CHECK(!ccvb.inside({0, 7, 0}));
111  BOOST_CHECK(!ccvb.inside({7, 0, 0}));
112  BOOST_CHECK(ccvb.inside({0, 13, 0}));
113  BOOST_CHECK(ccvb.inside({13, 0, 0}));
114  BOOST_CHECK(!ccvb.inside({0, 17, 0}));
115  BOOST_CHECK(!ccvb.inside({17, 0, 0}));
116 
117  // outside in z
118  BOOST_CHECK(!ccvb.inside({0, 0, 35}));
119  BOOST_CHECK(!ccvb.inside({0, 0, -35}));
120  BOOST_CHECK(!ccvb.inside({0, 3, 35}));
121  BOOST_CHECK(!ccvb.inside({0, 3, -35}));
122  BOOST_CHECK(!ccvb.inside({3, 0, 35}));
123  BOOST_CHECK(!ccvb.inside({3, 0, -35}));
124  BOOST_CHECK(!ccvb.inside({0, 10, 35}));
125  BOOST_CHECK(!ccvb.inside({0, 10, -35}));
126  BOOST_CHECK(!ccvb.inside({10, 0, 35}));
127  BOOST_CHECK(!ccvb.inside({10, 0, -35}));
128  BOOST_CHECK(!ccvb.inside({0, 20, 35}));
129  BOOST_CHECK(!ccvb.inside({0, 20, -35}));
130  BOOST_CHECK(!ccvb.inside({20, 0, 35}));
131  BOOST_CHECK(!ccvb.inside({20, 0, -35}));
132 
133  // in the choke point in z
134  BOOST_CHECK(!ccvb.inside({0, 0, 27}));
135  BOOST_CHECK(!ccvb.inside({0, 0, -27}));
136  BOOST_CHECK(!ccvb.inside({0, 3, 27}));
137  BOOST_CHECK(!ccvb.inside({0, 3, -27}));
138  BOOST_CHECK(!ccvb.inside({3, 0, 27}));
139  BOOST_CHECK(!ccvb.inside({3, 0, -27}));
140  BOOST_CHECK(ccvb.inside({0, 7, 27}));
141  BOOST_CHECK(ccvb.inside({0, 7, -27}));
142  BOOST_CHECK(ccvb.inside({7, 0, 27}));
143  BOOST_CHECK(ccvb.inside({7, 0, -27}));
144  BOOST_CHECK(ccvb.inside({0, 13, 27}));
145  BOOST_CHECK(ccvb.inside({0, 13, -27}));
146  BOOST_CHECK(ccvb.inside({13, 0, 27}));
147  BOOST_CHECK(ccvb.inside({13, 0, -27}));
148  BOOST_CHECK(!ccvb.inside({0, 17, 27}));
149  BOOST_CHECK(!ccvb.inside({0, 17, -27}));
150  BOOST_CHECK(!ccvb.inside({17, 0, 27}));
151  BOOST_CHECK(!ccvb.inside({17, 0, -27}));
152 
153  // right inside the choke point in z
154  BOOST_CHECK(!ccvb.inside({0, 0, 23}));
155  BOOST_CHECK(!ccvb.inside({0, 0, -23}));
156  BOOST_CHECK(!ccvb.inside({0, 3, 23}));
157  BOOST_CHECK(!ccvb.inside({0, 3, -23}));
158  BOOST_CHECK(!ccvb.inside({3, 0, 23}));
159  BOOST_CHECK(!ccvb.inside({3, 0, -23}));
160  BOOST_CHECK(!ccvb.inside({0, 7, 23}));
161  BOOST_CHECK(!ccvb.inside({0, 7, -23}));
162  BOOST_CHECK(!ccvb.inside({7, 0, 23}));
163  BOOST_CHECK(!ccvb.inside({7, 0, -23}));
164  BOOST_CHECK(ccvb.inside({0, 13, 23}));
165  BOOST_CHECK(ccvb.inside({0, 13, -23}));
166  BOOST_CHECK(ccvb.inside({13, 0, 23}));
167  BOOST_CHECK(ccvb.inside({13, 0, -23}));
168  BOOST_CHECK(!ccvb.inside({0, 17, 23}));
169  BOOST_CHECK(!ccvb.inside({0, 17, -23}));
170  BOOST_CHECK(!ccvb.inside({17, 0, 23}));
171  BOOST_CHECK(!ccvb.inside({17, 0, -23}));
172 }
173 
174 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsBoundingBox) {
176  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
177  auto box = ccvb.boundingBox();
178  CHECK_CLOSE_ABS(box.min(), Vector3(-15, -15, -30), 1e-6);
179  CHECK_CLOSE_ABS(box.max(), Vector3(15, 15, 30), 1e-6);
180 
181  auto ccvbSurfaces = ccvb.orientedSurfaces(Transform3::Identity());
182 }
183 
184 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeOrientedBoundaries) {
186 
187  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
188 
189  auto ccvbOrientedSurfaces = ccvb.orientedSurfaces(Transform3::Identity());
190  BOOST_CHECK_EQUAL(ccvbOrientedSurfaces.size(), 8);
191 
192  auto geoCtx = GeometryContext();
193  Vector3 xaxis(1., 0., 0.);
194  Vector3 yaxis(0., 1., 0.);
195  Vector3 zaxis(0., 0., 1.);
196 
197  for (auto& os : ccvbOrientedSurfaces) {
198  auto onSurface = os.first->binningPosition(geoCtx, binR);
199  auto osNormal = os.first->normal(geoCtx, onSurface);
200  // Check if you step inside the volume with the oriented normal
201  Vector3 insideCcvb = onSurface + os.second * osNormal;
202  Vector3 outsideCCvb = onSurface - os.second * osNormal;
203 
204  BOOST_CHECK(ccvb.inside(insideCcvb));
205  BOOST_CHECK(!ccvb.inside(outsideCCvb));
206 
207  // Test the orientation of the boundary surfaces
208  auto rot = os.first->transform(geoCtx).rotation();
209  BOOST_CHECK(rot.col(0).isApprox(xaxis));
210  BOOST_CHECK(rot.col(1).isApprox(yaxis));
211  BOOST_CHECK(rot.col(2).isApprox(zaxis));
212  }
213 }
214 
215 BOOST_AUTO_TEST_SUITE_END()
216 } // namespace Test
217 } // namespace Acts