Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeStructureBuilderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeStructureBuilderTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
14 
15 #include <memory>
16 #include <vector>
17 
18 using namespace Acts;
19 using namespace Acts::Experimental;
20 
22 
23 BOOST_AUTO_TEST_SUITE(Detector)
24 
25 // Test misconfiguration exception
26 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderMisconfigured) {
28 
29  BOOST_CHECK_THROW(
30  VolumeStructureBuilder builder1(
31  misConfig, getDefaultLogger("Builder1", Logging::VERBOSE)),
32  std::invalid_argument);
33 
34  misConfig.boundValues = {0., 1., 2., 3.};
35  BOOST_CHECK_THROW(
36  VolumeStructureBuilder builder2(
37  misConfig, getDefaultLogger("Builder2", Logging::VERBOSE)),
38  std::invalid_argument);
39 }
40 
41 // Test the creation of conical bounds
42 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCone) {
43  // Conical volume from parameters
44  VolumeStructureBuilder::Config coneValsConfig;
45  coneValsConfig.boundValues = {0.2, -200., 0.3, -300., 100.};
46  coneValsConfig.boundsType = VolumeBounds::BoundsType::eCone;
47 
48  VolumeStructureBuilder coneBuilderVals(
49  coneValsConfig,
50  getDefaultLogger("ConeStructureBuilderVals", Logging::VERBOSE));
51 
52  auto [transformVals, boundsVals, portalGeneratorVals] =
53  coneBuilderVals.construct(tContext);
54  BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
55  BOOST_CHECK(boundsVals != nullptr);
56  BOOST_CHECK(boundsVals->type() == VolumeBounds::BoundsType::eCone);
57  BOOST_CHECK(boundsVals->values().size() == 7u);
58  BOOST_CHECK(boundsVals->values().at(0u) == 0.2);
59  BOOST_CHECK(boundsVals->values().at(1u) == -200.);
60  BOOST_CHECK(boundsVals->values().at(2u) == 0.3);
61  BOOST_CHECK(boundsVals->values().at(3u) == -300.);
62  BOOST_CHECK(boundsVals->values().at(4u) == 100.);
63 
64  // Misconfigured - values not complete
65  VolumeStructureBuilder::Config coneMis1Config;
66  coneMis1Config.boundValues = {100., 200.};
67  coneMis1Config.boundsType = VolumeBounds::BoundsType::eCone;
68 
69  VolumeStructureBuilder coneBuilderMis1(
70  coneMis1Config,
71  getDefaultLogger("ConeStructureBuilderMis1", Logging::VERBOSE));
72 
73  BOOST_CHECK_THROW(coneBuilderMis1.construct(tContext), std::runtime_error);
74 
75  // Misconfigured - tried with extent
76  VolumeStructureBuilder::Config coneMis2Config;
77  coneMis2Config.extent = Extent{};
78  coneMis2Config.boundsType = VolumeBounds::BoundsType::eCone;
79 
80  VolumeStructureBuilder coneBuilderMis2(
81  coneMis2Config,
82  getDefaultLogger("ConeStructureBuilderMis2", Logging::VERBOSE));
83 
84  BOOST_CHECK_THROW(coneBuilderMis2.construct(tContext), std::runtime_error);
85 }
86 
87 // Test the creation of a cubic bounds
88 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCuboid) {
89  // Cuboid volume from parameters
90  VolumeStructureBuilder::Config cuboidValsConfig;
91  cuboidValsConfig.boundValues = {100., 200., 300.};
92  cuboidValsConfig.boundsType = VolumeBounds::BoundsType::eCuboid;
93 
94  VolumeStructureBuilder cuboidBuilderVals(
95  cuboidValsConfig,
96  getDefaultLogger("CuboidStructureBuilderVals", Logging::VERBOSE));
97 
98  auto [transformVals, boundsVals, portalGeneratorVals] =
99  cuboidBuilderVals.construct(tContext);
100  BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
101  BOOST_CHECK(boundsVals != nullptr);
102  BOOST_CHECK(boundsVals->type() == VolumeBounds::BoundsType::eCuboid);
103  BOOST_CHECK(boundsVals->values().size() == 3u);
104  BOOST_CHECK(boundsVals->values().at(0u) == 100.);
105  BOOST_CHECK(boundsVals->values().at(1u) == 200.);
106  BOOST_CHECK(boundsVals->values().at(2u) == 300.);
107 
108  // Cuboid volume from extent
109  Extent cuboidExtent;
110  cuboidExtent.set(binX, -100, 100);
111  cuboidExtent.set(binY, -200, 200);
112  cuboidExtent.set(binZ, -300, 300);
113 
114  VolumeStructureBuilder::Config cuboidExtentConfig;
115  cuboidExtentConfig.boundsType = VolumeBounds::BoundsType::eCuboid;
116  cuboidExtentConfig.extent = cuboidExtent;
117 
118  VolumeStructureBuilder cuboidBuilderExtent(
119  cuboidExtentConfig,
120  getDefaultLogger("CuboidStructureBuilderExtent", Logging::VERBOSE));
121 
122  auto [transformExtent, boundsExtent, portalGeneratorExtent] =
123  cuboidBuilderExtent.construct(tContext);
124 
125  BOOST_CHECK(transformExtent.isApprox(Transform3::Identity()));
126  BOOST_CHECK(boundsExtent != nullptr);
127  BOOST_CHECK(boundsExtent->type() == VolumeBounds::BoundsType::eCuboid);
128  BOOST_CHECK(boundsExtent->values().size() == 3u);
129  BOOST_CHECK(boundsExtent->values().at(0u) == 100.);
130  BOOST_CHECK(boundsExtent->values().at(1u) == 200.);
131  BOOST_CHECK(boundsExtent->values().at(2u) == 300.);
132 
133  // Misconfigured - values not correct
134  VolumeStructureBuilder::Config cuboidMis1Config;
135  cuboidMis1Config.boundValues = {100., 200.};
136  cuboidMis1Config.boundsType = VolumeBounds::BoundsType::eCuboid;
137 
138  VolumeStructureBuilder cuboidBuilderMis1(
139  cuboidMis1Config,
140  getDefaultLogger("CuboidStructureBuilderMis1", Logging::VERBOSE));
141 
142  BOOST_CHECK_THROW(cuboidBuilderMis1.construct(tContext), std::runtime_error);
143 
144  // Misconfigured - extent not correct
145  VolumeStructureBuilder::Config cuboidMis2Config;
146  cuboidMis2Config.extent = Extent{};
147  cuboidMis2Config.boundsType = VolumeBounds::BoundsType::eCuboid;
148 
149  VolumeStructureBuilder cuboidBuilderMis2(
150  cuboidMis2Config,
151  getDefaultLogger("CuboidStructureBuilderMis2", Logging::VERBOSE));
152 
153  BOOST_CHECK_THROW(cuboidBuilderMis2.construct(tContext), std::runtime_error);
154 }
155 
156 // Test the creation of cutout cylinder bounds
157 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCutoutCylinder) {
158  // Cutout Cylinder volume from parameters
159  VolumeStructureBuilder::Config ccylValsConfig;
160  ccylValsConfig.boundValues = {100, 120., 200, 300., 280.};
161  ccylValsConfig.boundsType = VolumeBounds::BoundsType::eCutoutCylinder;
162 
163  VolumeStructureBuilder ccylBuilderVals(
164  ccylValsConfig,
165  getDefaultLogger("CutoutCylinderStructureBuilderVals", Logging::VERBOSE));
166 
167  auto [transformVals, boundsVals, portalGeneratorVals] =
168  ccylBuilderVals.construct(tContext);
169  BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
170  BOOST_CHECK(boundsVals != nullptr);
171  BOOST_CHECK(boundsVals->type() == VolumeBounds::BoundsType::eCutoutCylinder);
172  BOOST_CHECK(boundsVals->values().size() == 5u);
173  BOOST_CHECK(boundsVals->values().at(0u) == 100.);
174  BOOST_CHECK(boundsVals->values().at(1u) == 120.);
175  BOOST_CHECK(boundsVals->values().at(2u) == 200.);
176  BOOST_CHECK(boundsVals->values().at(3u) == 300.);
177  BOOST_CHECK(boundsVals->values().at(4u) == 280.);
178 
179  // Misconfigured - values not complete
180  VolumeStructureBuilder::Config ccylMis1Config;
181  ccylMis1Config.boundValues = {100., 200.};
182  ccylMis1Config.boundsType = VolumeBounds::BoundsType::eCutoutCylinder;
183 
184  VolumeStructureBuilder ccylBuilderMis1(
185  ccylMis1Config,
186  getDefaultLogger("CutoutCylinderStructureBuilderMis1", Logging::VERBOSE));
187 
188  BOOST_CHECK_THROW(ccylBuilderMis1.construct(tContext), std::runtime_error);
189 
190  // Misconfigured - trying from extent
191  VolumeStructureBuilder::Config ccylMis2Config;
192  ccylMis2Config.extent = Extent{};
193  ccylMis2Config.boundsType = VolumeBounds::BoundsType::eCutoutCylinder;
194 
195  VolumeStructureBuilder ccylBuilderMis2(
196  ccylMis2Config,
197  getDefaultLogger("CutoutCylinderStructureBuilderMis2", Logging::VERBOSE));
198 
199  BOOST_CHECK_THROW(ccylBuilderMis2.construct(tContext), std::runtime_error);
200 }
201 
202 // Test the creation of cylindrical bounds
203 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCylinder) {
204  // Cylinder volume from parameters
205  VolumeStructureBuilder::Config cylValsConfig;
206  cylValsConfig.boundValues = {100, 200, 400., 0.3, 0.};
207  cylValsConfig.boundsType = VolumeBounds::BoundsType::eCylinder;
208 
209  VolumeStructureBuilder cylBuilderVals(
210  cylValsConfig,
211  getDefaultLogger("CylinderStructureBuilderVals", Logging::VERBOSE));
212 
213  auto [transformVals, boundsVals, portalGeneratorVals] =
214  cylBuilderVals.construct(tContext);
215  BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
216  BOOST_CHECK(boundsVals != nullptr);
217  BOOST_CHECK(boundsVals->type() == VolumeBounds::BoundsType::eCylinder);
218  BOOST_CHECK(boundsVals->values().size() == 7u);
219  BOOST_CHECK(boundsVals->values().at(0u) == 100.);
220  BOOST_CHECK(boundsVals->values().at(1u) == 200.);
221  BOOST_CHECK(boundsVals->values().at(2u) == 400.);
222  BOOST_CHECK(boundsVals->values().at(3u) == 0.3);
223 
224  // Cylinder volume from extent
225  Extent cylinderExtent;
226  cylinderExtent.set(binR, 100., 200.);
227  cylinderExtent.set(binZ, -800., 0.);
228 
229  VolumeStructureBuilder::Config cylExtentConfig;
230  cylExtentConfig.extent = cylinderExtent;
231  cylExtentConfig.boundsType = VolumeBounds::BoundsType::eCylinder;
232 
233  VolumeStructureBuilder cylBuilderExtent(
234  cylExtentConfig,
235  getDefaultLogger("CylinderStructureBuilderExtent", Logging::VERBOSE));
236 
237  auto [transformExtent, boundsExtent, portalGeneratorExtent] =
238  cylBuilderExtent.construct(tContext);
239 
240  Transform3 shifted = Transform3::Identity();
241  shifted.pretranslate(Vector3(0., 0., -400.));
242 
243  BOOST_CHECK(transformExtent.isApprox(shifted));
244  BOOST_CHECK(boundsExtent != nullptr);
245  BOOST_CHECK(boundsExtent->type() == VolumeBounds::BoundsType::eCylinder);
246  BOOST_CHECK(boundsExtent->values().size() == 7u);
247  BOOST_CHECK(boundsExtent->values().at(0u) == 100.);
248  BOOST_CHECK(boundsExtent->values().at(1u) == 200.);
249  BOOST_CHECK(boundsExtent->values().at(2u) == 400.);
250 
251  // Misconfigured - values not complete
252  VolumeStructureBuilder::Config cylMis1Config;
253  cylMis1Config.boundValues = {100., 200.};
254  cylMis1Config.boundsType = VolumeBounds::BoundsType::eCylinder;
255 
256  VolumeStructureBuilder cylBuilderMis1(
257  cylMis1Config,
258  getDefaultLogger("CylinderStructureBuilderMis1", Logging::VERBOSE));
259 
260  BOOST_CHECK_THROW(cylBuilderMis1.construct(tContext), std::runtime_error);
261 
262  // Misconfigured - trying from extent
263  VolumeStructureBuilder::Config cylMis2Config;
264  cylMis2Config.extent = Extent{};
265  cylMis2Config.boundsType = VolumeBounds::BoundsType::eCylinder;
266 
267  VolumeStructureBuilder cylBuilderMis2(
268  cylMis2Config,
269  getDefaultLogger("CylinderStructureBuilderMis2", Logging::VERBOSE));
270 
271  BOOST_CHECK_THROW(cylBuilderMis2.construct(tContext), std::runtime_error);
272 }
273 
274 // Test the creation of generic cuboid bounds
275 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderGenericCuboid) {
276  // Cuboid volume from parameters
277  VolumeStructureBuilder::Config gcubValsConfig;
278  gcubValsConfig.boundValues = {0, 0, 0, 2, 0, 0.4, 2, 1, 0.4, 0, 1, 0,
279  0, 0, 1, 1.8, 0, 1, 1.8, 1, 1, 0, 1, 1};
280  gcubValsConfig.boundsType = VolumeBounds::BoundsType::eGenericCuboid;
281 
282  VolumeStructureBuilder gcubBuilderVals(
283  gcubValsConfig,
284  getDefaultLogger("GenericCuboidStructureBuilderVals", Logging::VERBOSE));
285 
286  auto [transformVals, boundsVals, portalGeneratorVals] =
287  gcubBuilderVals.construct(tContext);
288  BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
289  BOOST_CHECK(boundsVals != nullptr);
290  BOOST_CHECK(boundsVals->type() == VolumeBounds::BoundsType::eGenericCuboid);
291  BOOST_CHECK(boundsVals->values().size() == 24u);
292 
293  // Misconfigured - values not complete
294  VolumeStructureBuilder::Config gcubMis1Config;
295  gcubMis1Config.boundsType = VolumeBounds::BoundsType::eGenericCuboid;
296  gcubMis1Config.boundValues = {100.};
297 
298  VolumeStructureBuilder gcubBuilderMis1(
299  gcubMis1Config,
300  getDefaultLogger("GenericCuboidStructureBuilderMis1", Logging::VERBOSE));
301 
302  BOOST_CHECK_THROW(gcubBuilderMis1.construct(tContext), std::runtime_error);
303 
304  // Misconfigured - tried with extent
305  VolumeStructureBuilder::Config gcubMis2Config;
306  gcubMis2Config.boundsType = VolumeBounds::BoundsType::eGenericCuboid;
307  gcubMis2Config.extent = Extent{};
308 
309  VolumeStructureBuilder gcubBuilderMis2(
310  gcubMis2Config,
311  getDefaultLogger("GenericCuboidStructureBuilderMis2", Logging::VERBOSE));
312 }
313 
314 // Test the creation of the trapezoidal bounds
315 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderTrapezoid) {
316  // Cuboid volume from parameters
317  VolumeStructureBuilder::Config trapValsConfig;
318  trapValsConfig.boundValues = {100., 200., 300., 10.};
319  trapValsConfig.boundsType = VolumeBounds::BoundsType::eTrapezoid;
320 
321  VolumeStructureBuilder trapBuilderVals(
322  trapValsConfig,
323  getDefaultLogger("TrapezoidStructureBuilderVals", Logging::VERBOSE));
324 
325  auto [transformVals, boundsVals, portalGeneratorVals] =
326  trapBuilderVals.construct(tContext);
327  BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
328  BOOST_CHECK(boundsVals != nullptr);
329  BOOST_CHECK(boundsVals->type() == VolumeBounds::BoundsType::eTrapezoid);
330  BOOST_CHECK(boundsVals->values().size() == 6u);
331  BOOST_CHECK(boundsVals->values().at(0u) == 100.);
332  BOOST_CHECK(boundsVals->values().at(1u) == 200.);
333  BOOST_CHECK(boundsVals->values().at(2u) == 300.);
334  BOOST_CHECK(boundsVals->values().at(3u) == 10.);
335 
336  // Misconfigured - values not complete
337  VolumeStructureBuilder::Config trapMis1Config;
338  trapMis1Config.boundsType = VolumeBounds::BoundsType::eTrapezoid;
339  trapMis1Config.boundValues = {100., 200.};
340 
341  VolumeStructureBuilder trapBuilderMis1(
342  trapMis1Config,
343  getDefaultLogger("TrapezoidStructureBuilderMis1", Logging::VERBOSE));
344 
345  BOOST_CHECK_THROW(trapBuilderMis1.construct(tContext), std::runtime_error);
346 
347  // Misconfigured - tried with extent
348  VolumeStructureBuilder::Config trapMis2Config;
349  trapMis2Config.boundsType = VolumeBounds::BoundsType::eTrapezoid;
350  trapMis2Config.extent = Extent{};
351 
352  VolumeStructureBuilder trapBuilderMis2(
353  trapMis2Config,
354  getDefaultLogger("TrapezoidStructureBuilderMis2", Logging::VERBOSE));
355 }
356 
357 BOOST_AUTO_TEST_SUITE_END()