ECCE @ 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 
11 #include <fstream>
12 #include <iostream>
13 #include <memory>
14 
23 
24 namespace Acts {
25 namespace Test {
26 
27 BOOST_AUTO_TEST_SUITE(Geometry)
28 
29 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsConstruction) {
30  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
31  ccvb.toStream(std::cout);
32 
33  // Test copy construction
34  CutoutCylinderVolumeBounds copied(ccvb);
35  BOOST_CHECK_EQUAL(ccvb, copied);
36 
37  // Test assigned
38  CutoutCylinderVolumeBounds assigned = ccvb;
39  BOOST_CHECK_EQUAL(ccvb, assigned);
40 }
41 
42 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsRecreation) {
43  CutoutCylinderVolumeBounds original(5, 10, 15, 30, 25);
44  std::array<double, CutoutCylinderVolumeBounds::eSize> values;
45  std::vector<double> valvector = original.values();
46  std::copy_n(valvector.begin(), CutoutCylinderVolumeBounds::eSize,
47  values.begin());
48  CutoutCylinderVolumeBounds recreated(values);
49  BOOST_CHECK_EQUAL(original, recreated);
50 }
51 
52 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsExceptions) {
53  double rmin{5}, rmed{10}, rmax{15}, hz{30}, hzc{25};
54 
55  // Test negative rmin
56  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(-rmin, rmed, rmax, hz, hzc),
57  std::logic_error);
58 
59  // Test negative rmed
60  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, -rmed, rmax, hz, hzc),
61  std::logic_error);
62 
63  // Test negative rmax
64  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmed, -rmax, hz, hzc),
65  std::logic_error);
66 
67  // Test swapped rmin / rmed
68  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmed, rmin, rmax, hz, hzc),
69  std::logic_error);
70 
71  // Test swapped rmin / rmax
72  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmax, rmed, rmin, hz, hzc),
73  std::logic_error);
74 
75  // Test swapped rmed / rmax
76  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmax, rmed, hz, hzc),
77  std::logic_error);
78 
79  // Test negative hz
80  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmed, rmax, -hz, hzc),
81  std::logic_error);
82 
83  // Test negative hzc
84  BOOST_CHECK_THROW(CutoutCylinderVolumeBounds(rmin, rmed, rmax, hz, -hzc),
85  std::logic_error);
86 }
87 
88 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsAccess) {
89  double rmin{5}, rmed{10}, rmax{15}, hz{30}, hzc{25};
90  CutoutCylinderVolumeBounds ccvb(rmin, rmed, rmax, hz, hzc);
91 
92  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eMinR), rmin);
93  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eMedR), rmed);
94  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eMaxR), rmax);
95  BOOST_CHECK_EQUAL(ccvb.get(CutoutCylinderVolumeBounds::eHalfLengthZ), hz);
97  hzc);
98 }
99 
100 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsInside) {
101  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
102 
103  BOOST_CHECK(!ccvb.inside({0, 0, 0}));
104  BOOST_CHECK(!ccvb.inside({0, 3, 0}));
105  BOOST_CHECK(!ccvb.inside({3, 0, 0}));
106  BOOST_CHECK(!ccvb.inside({0, 7, 0}));
107  BOOST_CHECK(!ccvb.inside({7, 0, 0}));
108  BOOST_CHECK(ccvb.inside({0, 13, 0}));
109  BOOST_CHECK(ccvb.inside({13, 0, 0}));
110  BOOST_CHECK(!ccvb.inside({0, 17, 0}));
111  BOOST_CHECK(!ccvb.inside({17, 0, 0}));
112 
113  // outside in z
114  BOOST_CHECK(!ccvb.inside({0, 0, 35}));
115  BOOST_CHECK(!ccvb.inside({0, 0, -35}));
116  BOOST_CHECK(!ccvb.inside({0, 3, 35}));
117  BOOST_CHECK(!ccvb.inside({0, 3, -35}));
118  BOOST_CHECK(!ccvb.inside({3, 0, 35}));
119  BOOST_CHECK(!ccvb.inside({3, 0, -35}));
120  BOOST_CHECK(!ccvb.inside({0, 10, 35}));
121  BOOST_CHECK(!ccvb.inside({0, 10, -35}));
122  BOOST_CHECK(!ccvb.inside({10, 0, 35}));
123  BOOST_CHECK(!ccvb.inside({10, 0, -35}));
124  BOOST_CHECK(!ccvb.inside({0, 20, 35}));
125  BOOST_CHECK(!ccvb.inside({0, 20, -35}));
126  BOOST_CHECK(!ccvb.inside({20, 0, 35}));
127  BOOST_CHECK(!ccvb.inside({20, 0, -35}));
128 
129  // in the choke point in z
130  BOOST_CHECK(!ccvb.inside({0, 0, 27}));
131  BOOST_CHECK(!ccvb.inside({0, 0, -27}));
132  BOOST_CHECK(!ccvb.inside({0, 3, 27}));
133  BOOST_CHECK(!ccvb.inside({0, 3, -27}));
134  BOOST_CHECK(!ccvb.inside({3, 0, 27}));
135  BOOST_CHECK(!ccvb.inside({3, 0, -27}));
136  BOOST_CHECK(ccvb.inside({0, 7, 27}));
137  BOOST_CHECK(ccvb.inside({0, 7, -27}));
138  BOOST_CHECK(ccvb.inside({7, 0, 27}));
139  BOOST_CHECK(ccvb.inside({7, 0, -27}));
140  BOOST_CHECK(ccvb.inside({0, 13, 27}));
141  BOOST_CHECK(ccvb.inside({0, 13, -27}));
142  BOOST_CHECK(ccvb.inside({13, 0, 27}));
143  BOOST_CHECK(ccvb.inside({13, 0, -27}));
144  BOOST_CHECK(!ccvb.inside({0, 17, 27}));
145  BOOST_CHECK(!ccvb.inside({0, 17, -27}));
146  BOOST_CHECK(!ccvb.inside({17, 0, 27}));
147  BOOST_CHECK(!ccvb.inside({17, 0, -27}));
148 
149  // right inside the choke point in z
150  BOOST_CHECK(!ccvb.inside({0, 0, 23}));
151  BOOST_CHECK(!ccvb.inside({0, 0, -23}));
152  BOOST_CHECK(!ccvb.inside({0, 3, 23}));
153  BOOST_CHECK(!ccvb.inside({0, 3, -23}));
154  BOOST_CHECK(!ccvb.inside({3, 0, 23}));
155  BOOST_CHECK(!ccvb.inside({3, 0, -23}));
156  BOOST_CHECK(!ccvb.inside({0, 7, 23}));
157  BOOST_CHECK(!ccvb.inside({0, 7, -23}));
158  BOOST_CHECK(!ccvb.inside({7, 0, 23}));
159  BOOST_CHECK(!ccvb.inside({7, 0, -23}));
160  BOOST_CHECK(ccvb.inside({0, 13, 23}));
161  BOOST_CHECK(ccvb.inside({0, 13, -23}));
162  BOOST_CHECK(ccvb.inside({13, 0, 23}));
163  BOOST_CHECK(ccvb.inside({13, 0, -23}));
164  BOOST_CHECK(!ccvb.inside({0, 17, 23}));
165  BOOST_CHECK(!ccvb.inside({0, 17, -23}));
166  BOOST_CHECK(!ccvb.inside({17, 0, 23}));
167  BOOST_CHECK(!ccvb.inside({17, 0, -23}));
168 }
169 
170 BOOST_AUTO_TEST_CASE(CutoutCylinderVolumeBoundsBoundingBox) {
172  std::vector<IdentifiedPolyderon> tPolyhedrons;
173 
174  auto combineAndDecompose = [&](const SurfacePtrVector& surfaces,
175  const std::string& name) -> void {
176  std::string writeBase = std::string("CutoutCylinderVolumeBounds") + name;
177 
178  Polyhedron phCombined;
179  size_t is = 0;
180  for (const auto& sf : surfaces) {
181  Polyhedron phComponent = sf->polyhedronRepresentation(tgContext, 72);
182  phCombined.merge(phComponent);
183  tPolyhedrons.push_back(
184  {writeBase + std::string("_comp_") + std::to_string(is++), false,
185  phComponent});
186  }
187  tPolyhedrons.push_back({writeBase, false, phCombined});
188  };
189 
190  CutoutCylinderVolumeBounds ccvb(5, 10, 15, 30, 25);
191  auto box = ccvb.boundingBox();
192  CHECK_CLOSE_ABS(box.min(), Vector3D(-15, -15, -30), 1e-6);
193  CHECK_CLOSE_ABS(box.max(), Vector3D(15, 15, 30), 1e-6);
194 
195  auto ccvbSurfaces = ccvb.decomposeToSurfaces();
196  combineAndDecompose(ccvbSurfaces, "");
197  ObjTestWriter::writeObj("CutoutCylinderVolumeBounds_BB", box);
198  ObjTestWriter::writeObj(tPolyhedrons);
199 }
200 
201 BOOST_AUTO_TEST_SUITE_END()
202 } // namespace Test
203 } // namespace Acts