Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SupportHelperTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SupportHelperTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
13 #include "Acts/Geometry/Extent.hpp"
19 
20 #include <array>
21 #include <cmath>
22 #include <cstddef>
23 #include <memory>
24 #include <optional>
25 #include <stdexcept>
26 #include <vector>
27 
29 
30 BOOST_AUTO_TEST_SUITE(Detector)
31 
32 BOOST_AUTO_TEST_CASE(CylindricalSupport) {
33  // As a single cylinder
34  auto singleSupport =
36  Acts::Transform3::Identity(), {100., 400., M_PI, 0., 0., 0.}, 1u);
37  BOOST_CHECK(singleSupport.size() == 1u);
38  BOOST_CHECK(singleSupport[0u]->type() ==
39  Acts::Surface::SurfaceType::Cylinder);
40 
41  // As a split cylinder
42  auto splitSupport =
44  Acts::Transform3::Identity(), {100., 400., M_PI, 0., 0., 0.}, 32u);
45  BOOST_CHECK(splitSupport.size() == 32u);
46  for (const auto& ss : splitSupport) {
47  BOOST_CHECK(ss->type() == Acts::Surface::SurfaceType::Plane);
48  }
49 
50  // As a split cylinder - sectoral
51  auto splitSectoralSupport =
53  Acts::Transform3::Identity(),
54  {100., 400., 0.25 * M_PI, 0.75 * M_PI, 0., 0.}, 128u);
55  BOOST_CHECK(splitSectoralSupport.size() == 128u);
56  for (const auto& ss : splitSectoralSupport) {
57  BOOST_CHECK(ss->type() == Acts::Surface::SurfaceType::Plane);
58  }
59 }
60 
61 BOOST_AUTO_TEST_CASE(DiscSupport) {
62  // As a single disc
64  Acts::Transform3::Identity(), {100., 400., M_PI, 0.}, 1u);
65  BOOST_CHECK(singleSupport.size() == 1u);
66  BOOST_CHECK(singleSupport[0u]->type() == Acts::Surface::SurfaceType::Disc);
67 
68  // As a split disc
70  Acts::Transform3::Identity(), {100., 400., M_PI, 0.}, 32u);
71  BOOST_CHECK(splitSupport.size() == 32u);
72  for (const auto& ss : splitSupport) {
73  BOOST_CHECK(ss->type() == Acts::Surface::SurfaceType::Plane);
74  }
75 
76  // As a split disc - sectoral
77  auto splitSectoralSupport =
79  Acts::Transform3::Identity(), {100., 400., 0.5 * M_PI, 0.}, 16u);
80  BOOST_CHECK(splitSectoralSupport.size() == 16u);
81  for (const auto& ss : splitSectoralSupport) {
82  BOOST_CHECK(ss->type() == Acts::Surface::SurfaceType::Plane);
83  }
84 }
85 
86 BOOST_AUTO_TEST_CASE(addCylinderSupport) {
87  std::vector<std::shared_ptr<Acts::Surface>> lSurfaces;
88  std::vector<size_t> assignToAll;
89 
90  // The Extent
91  Acts::Extent lExtent;
92  lExtent.set(Acts::binR, 100., 110.);
93  lExtent.set(Acts::binZ, -400., -400.);
94 
95  // Get the main support parameters:
96  // - doff .. offset (in r.z)
97  // - demin, demax .. envelop min, max (in z,r)
98  // - dphimin, dphimin .. envelop min, max (in phi)
99  std::array<Acts::ActsScalar, 5u> sValues = {10, 5, 5, 0., 0.};
100  // Add a single support cylinder
102  lSurfaces, assignToAll, lExtent, Acts::Surface::SurfaceType::Cylinder,
103  sValues, std::nullopt, 1u);
104  BOOST_CHECK(lSurfaces.size() == 1u);
105  BOOST_CHECK(assignToAll.size() == 1u);
106  BOOST_CHECK(assignToAll[0u] == 0u);
107  // The radius of the newly created support surface should be 10 out of the
108  // maximum
109  CHECK_CLOSE_ABS(lSurfaces[0u]->bounds().values()[0u], 120, 1e-3);
110 
111  // Clear up for the next test
112  lSurfaces.clear();
113  assignToAll.clear();
114  // Add split surfaces as support to already exisint surfaces
116  lSurfaces, assignToAll, lExtent, Acts::Surface::SurfaceType::Cylinder,
117  sValues, std::nullopt, 16u);
118  BOOST_CHECK(lSurfaces.size() == 16u);
119  BOOST_CHECK(assignToAll.empty());
120 }
121 
122 BOOST_AUTO_TEST_CASE(addDiscSupport) {
123  std::vector<std::shared_ptr<Acts::Surface>> lSurfaces;
124  std::vector<size_t> assignToAll;
125 
126  // The Extent
127  Acts::Extent lExtent;
128  lExtent.set(Acts::binR, 100., 400.);
129  lExtent.set(Acts::binZ, -110., -100.);
130 
131  // Get the main support parameters:
132  // - doff .. offset (in r.z)
133  // - demin, demax .. envelop min, max (in z,r)
134  // - dphimin, dphimin .. envelop min, max (in phi)
135  std::array<Acts::ActsScalar, 5u> sValues = {-10, 10, 20, 0., 0.};
136  // Add a single disc as a support cylinder
138  lSurfaces, assignToAll, lExtent, Acts::Surface::SurfaceType::Disc,
139  sValues, std::nullopt, 1u);
140  BOOST_CHECK(lSurfaces.size() == 1u);
141  BOOST_CHECK(assignToAll.size() == 1u);
142  BOOST_CHECK(assignToAll[0u] == 0u);
143  // The radius of the newly created support surface should be 10 out of the
144  // minimum
145  CHECK_CLOSE_ABS(lSurfaces[0u]->transform(tContext).translation().z(), -120,
146  1e-3);
147 
148  // Clear up for the next test
149  lSurfaces.clear();
150  assignToAll.clear();
151  // Add split surfaces as support disc
153  lSurfaces, assignToAll, lExtent, Acts::Surface::SurfaceType::Disc,
154  sValues, std::nullopt, 16u);
155  BOOST_CHECK(lSurfaces.size() == 16u);
156  BOOST_CHECK(assignToAll.empty());
157 }
158 
159 BOOST_AUTO_TEST_CASE(addMisconfiguredSupport) {
160  std::vector<std::shared_ptr<Acts::Surface>> lSurfaces;
161  std::vector<size_t> assignToAll;
162 
163  // Get the main support parameters:
164  // - doff .. offset (in r.z)
165  // - demin, demax .. envelop min, max (in z,r)
166  // - dphimin, dphimin .. envelop min, max (in phi)
167  std::array<Acts::ActsScalar, 5u> sValues = {-10, 10, 20, 0., 0.};
168 
169  // Unconstrainted extent
170  Acts::Extent lExtent;
171 
172  // R - Z are not constrained
173  // Add a single disc as a support cylinder
174  BOOST_CHECK_THROW(
176  lSurfaces, assignToAll, lExtent, Acts::Surface::SurfaceType::Cylinder,
177  sValues, std::nullopt, 1u),
178  std::runtime_error);
179 
180  // The Extent
181  lExtent.set(Acts::binR, 100., 400.);
182  lExtent.set(Acts::binZ, -110., -100.);
183 
184  // Add a single disc as a support cylinder
185  BOOST_CHECK_THROW(
187  lSurfaces, assignToAll, lExtent, Acts::Surface::SurfaceType::Cone,
188  sValues, std::nullopt, 1u),
189  std::invalid_argument);
190 }
191 
192 BOOST_AUTO_TEST_SUITE_END()