Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtentTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExtentTests.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/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
15 #include "Acts/Geometry/Extent.hpp"
18 
19 #include <array>
20 #include <cmath>
21 #include <string>
22 #include <vector>
23 
24 namespace Acts {
25 
26 using namespace UnitLiterals;
27 
28 namespace Test {
29 
30 BOOST_AUTO_TEST_SUITE(Geometry)
31 
32 
33 BOOST_AUTO_TEST_CASE(ExtentTest) {
34  std::vector<Vector3> vertices = {
35  Vector3(15_mm, -3_mm, -10_mm), Vector3(18_mm, 0_mm, -10_mm),
36  Vector3(15_mm, 3_mm, -10_mm), Vector3(15_mm, -3_mm, 10_mm),
37  Vector3(18_mm, 0_mm, 10_mm), Vector3(15_mm, 3_mm, 10_mm)};
38 
39  // Create an Extent / without envelope
40  Extent gExt;
41  for (const auto& v : vertices) {
42  gExt.extend(v);
43  }
44 
45  double phiMin = std::atan2(-3_mm, 15_mm);
46  double phiMax = std::atan2(3_mm, 15_mm);
47  double rMin = std::hypot(15_mm, 3_mm);
48 
49  CHECK_CLOSE_ABS(gExt.min(binX), 15_mm, 1e-6);
50  CHECK_CLOSE_ABS(gExt.max(binX), 18_mm, 1e-6);
51  CHECK_CLOSE_ABS(gExt.min(binY), -3_mm, 1e-6);
52  CHECK_CLOSE_ABS(gExt.max(binY), 3_mm, 1e-6);
53  CHECK_CLOSE_ABS(gExt.min(binZ), -10_mm, 1e-6);
54  CHECK_CLOSE_ABS(gExt.max(binZ), 10_mm, 1e-6);
55  CHECK_CLOSE_ABS(gExt.min(binR), rMin, 1e-6);
56  CHECK_CLOSE_ABS(gExt.max(binR), 18_mm, 1e-6);
57  CHECK_CLOSE_ABS(gExt.min(binPhi), phiMin, 1e-6);
58  CHECK_CLOSE_ABS(gExt.max(binPhi), phiMax, 1e-6);
59 
60  // Call with histogram filling
61  Extent gExtHist;
62  for (const auto& v : vertices) {
63  gExtHist.extend(v, {binX}, false, true);
64  }
65  const auto& vHist = gExtHist.valueHistograms();
66  auto xVals = vHist[binX];
67 
68  BOOST_CHECK(xVals.size() == 6u);
69  std::vector<ActsScalar> reference = {15_mm, 18_mm, 15_mm,
70  15_mm, 18_mm, 15_mm};
71  BOOST_CHECK(xVals == reference);
72 
73  // Call with ieterator range
74  Extent gExtItr;
75  gExtItr.extend(vertices.begin(), vertices.end());
76  CHECK_CLOSE_ABS(gExtItr.min(binX), 15_mm, 1e-6);
77  CHECK_CLOSE_ABS(gExtItr.max(binX), 18_mm, 1e-6);
78  CHECK_CLOSE_ABS(gExtItr.min(binY), -3_mm, 1e-6);
79  CHECK_CLOSE_ABS(gExtItr.max(binY), 3_mm, 1e-6);
80  CHECK_CLOSE_ABS(gExtItr.min(binZ), -10_mm, 1e-6);
81  CHECK_CLOSE_ABS(gExtItr.max(binZ), 10_mm, 1e-6);
82  CHECK_CLOSE_ABS(gExtItr.min(binR), rMin, 1e-6);
83  CHECK_CLOSE_ABS(gExtItr.max(binR), 18_mm, 1e-6);
84  CHECK_CLOSE_ABS(gExtItr.min(binPhi), phiMin, 1e-6);
85  CHECK_CLOSE_ABS(gExtItr.max(binPhi), phiMax, 1e-6);
86 
87  // Create a second Extent
88  Extent gExtCopy;
89  gExtCopy.extend(gExt);
90 
91  CHECK_CLOSE_ABS(gExtCopy.min(binX), 15_mm, 1e-6);
92  CHECK_CLOSE_ABS(gExtCopy.max(binX), 18_mm, 1e-6);
93  CHECK_CLOSE_ABS(gExtCopy.min(binY), -3_mm, 1e-6);
94  CHECK_CLOSE_ABS(gExtCopy.max(binY), 3_mm, 1e-6);
95  CHECK_CLOSE_ABS(gExtCopy.min(binZ), -10_mm, 1e-6);
96  CHECK_CLOSE_ABS(gExtCopy.max(binZ), 10_mm, 1e-6);
97  CHECK_CLOSE_ABS(gExtCopy.min(binR), rMin, 1e-6);
98  CHECK_CLOSE_ABS(gExtCopy.max(binR), 18_mm, 1e-6);
99  CHECK_CLOSE_ABS(gExtCopy.min(binPhi), phiMin, 1e-6);
100  CHECK_CLOSE_ABS(gExtCopy.max(binPhi), phiMax, 1e-6);
101 
102  // Check containment
103  Extent unbound;
104  BOOST_CHECK(unbound.contains(gExt));
105  BOOST_CHECK(unbound.contains(gExtCopy));
106 
107  // Check application of an envelope on it
108  ExtentEnvelope xEnvelopes = zeroEnvelopes;
109  xEnvelopes[binX] = {1., 2.};
110 
111  // Take the extent and extend by an envelope
112  Extent envelope(xEnvelopes);
113  gExt.extend(envelope);
114  // Changed ones
115  CHECK_CLOSE_ABS(gExt.min(binX), 14_mm, 1e-6);
116  CHECK_CLOSE_ABS(gExt.max(binX), 20_mm, 1e-6);
117  // Unchanged ones
118  CHECK_CLOSE_ABS(gExt.min(binY), -3_mm, 1e-6);
119  CHECK_CLOSE_ABS(gExt.max(binY), 3_mm, 1e-6);
120  CHECK_CLOSE_ABS(gExt.min(binZ), -10_mm, 1e-6);
121  CHECK_CLOSE_ABS(gExt.max(binZ), 10_mm, 1e-6);
122  CHECK_CLOSE_ABS(gExt.min(binR), rMin, 1e-6);
123  CHECK_CLOSE_ABS(gExt.max(binR), 18_mm, 1e-6);
124  CHECK_CLOSE_ABS(gExt.min(binPhi), phiMin, 1e-6);
125  CHECK_CLOSE_ABS(gExt.max(binPhi), phiMax, 1e-6);
126 
127  // Fill it with envelope
128  Extent gExtEnv(envelope);
129  gExtEnv.extend(vertices.begin(), vertices.end());
130  // Changed ones
131  CHECK_CLOSE_ABS(gExtEnv.min(binX), 14_mm, 1e-6);
132  CHECK_CLOSE_ABS(gExtEnv.max(binX), 20_mm, 1e-6);
133 
134  // Check the set method
135  gExt.set(binX, 2_mm, 8_mm);
136  CHECK_CLOSE_ABS(gExt.min(binX), 2_mm, 1e-6);
137  CHECK_CLOSE_ABS(gExt.max(binX), 8_mm, 1e-6);
138 
139  // Radius can not go below 0
140  gExt.set(binR, -2_mm, 18_mm);
141  CHECK_CLOSE_ABS(gExt.min(binR), 0_mm, 1e-6);
142  CHECK_CLOSE_ABS(gExt.max(binR), 18_mm, 1e-6);
143 
144  // Take an Extent and add a constraint
145  Extent gExtConst;
146  gExtConst.set(binR, 0., 5.);
147  Extent gExtNonConst;
148  BOOST_CHECK(not gExtNonConst.constrains(binR));
149  gExtNonConst.addConstrain(gExtConst);
150  BOOST_CHECK(gExtNonConst.constrains(binR));
151 
152  std::string tString = gExtConst.toString();
153  BOOST_CHECK(not tString.empty());
154 }
155 
156 BOOST_AUTO_TEST_SUITE_END()
157 
158 } // namespace Test
159 } // namespace Acts