Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrapezoidVolumeBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrapezoidVolumeBoundsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2020 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 
19 
20 #include <cmath>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 namespace tt = boost::test_tools;
26 
27 namespace Acts {
28 
29 namespace Test {
30 BOOST_AUTO_TEST_SUITE(Volumes)
31 
32 BOOST_AUTO_TEST_CASE(bounding_box_creation) {
33  float tol = 1e-4;
34 
35  TrapezoidVolumeBounds tvb(5, 10, 8, 4);
36 
37  auto bb = tvb.boundingBox();
38  CHECK_CLOSE_ABS(bb.max(), Vector3(10, 8, 4), tol);
39  CHECK_CLOSE_ABS(bb.min(), Vector3(-10, -8, -4), tol);
40 
41  Transform3 trf;
42 
43  trf = Translation3(Vector3(0, 30, 20));
44 
45  bb = tvb.boundingBox(&trf);
46  CHECK_CLOSE_ABS(bb.max(), Vector3(10, 38, 24), tol);
47  CHECK_CLOSE_ABS(bb.min(), Vector3(-10, 22, 16), tol);
48 
49  trf = AngleAxis3(M_PI / 2., Vector3(-2, 4, 5).normalized());
50 
51  bb = tvb.boundingBox(&trf);
52  CHECK_CLOSE_ABS(bb.max(), Vector3(9.32577, 11.4906, 11.5777), tol);
53  CHECK_CLOSE_ABS(bb.min(), Vector3(-9.77021, -8.65268, -9.23688), tol);
54 }
55 
56 BOOST_AUTO_TEST_CASE(TrapezoidVolumeBoundarySurfaces) {
57  TrapezoidVolumeBounds tvb(5, 10, 8, 4);
58 
59  auto tvbOrientedSurfaces = tvb.orientedSurfaces(Transform3::Identity());
60  BOOST_CHECK_EQUAL(tvbOrientedSurfaces.size(), 6);
61 
62  auto geoCtx = GeometryContext();
63 
64  for (auto& os : tvbOrientedSurfaces) {
65  auto osCenter = os.first->center(geoCtx);
66  auto osNormal = os.first->normal(geoCtx, osCenter);
67  // Check if you step inside the volume with the oriented normal
68  Vector3 insideTvb = osCenter + os.second * osNormal;
69  Vector3 outsideTvb = osCenter - os.second * osNormal;
70  BOOST_CHECK(tvb.inside(insideTvb));
71  BOOST_CHECK(!tvb.inside(outsideTvb));
72  }
73 
74  Vector3 xaxis(1., 0., 0.);
75  Vector3 yaxis(0., 1., 0.);
76  Vector3 zaxis(0., 0., 1.);
77 
78  // Test the orientation of the boundary surfaces
79  auto nFaceXY =
80  tvbOrientedSurfaces[negativeFaceXY].first->transform(geoCtx).rotation();
81  BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
82  BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
83  BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
84 
85  auto pFaceXY =
86  tvbOrientedSurfaces[positiveFaceXY].first->transform(geoCtx).rotation();
87  BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
88  BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
89  BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
90 
91  auto nFaceZX =
92  tvbOrientedSurfaces[negativeFaceZX].first->transform(geoCtx).rotation();
93  BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
94  BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
95  BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
96 
97  auto pFaceZX =
98  tvbOrientedSurfaces[positiveFaceZX].first->transform(geoCtx).rotation();
99  BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
100  BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
101  BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
102 }
103 
104 BOOST_AUTO_TEST_SUITE_END()
105 
106 } // namespace Test
107 
108 } // namespace Acts