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