EIC 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 namespace tt = boost::test_tools;
21 
22 namespace Acts {
23 
24 namespace Test {
25 BOOST_AUTO_TEST_SUITE(Volumes)
26 
27 BOOST_AUTO_TEST_CASE(bounding_box_creation) {
28  float tol = 1e-4;
29 
30  TrapezoidVolumeBounds tvb(5, 10, 8, 4);
31 
32  auto bb = tvb.boundingBox();
33  CHECK_CLOSE_ABS(bb.max(), Vector3D(10, 8, 4), tol);
34  CHECK_CLOSE_ABS(bb.min(), Vector3D(-10, -8, -4), tol);
35 
36  Transform3D trf;
37 
38  trf = Translation3D(Vector3D(0, 30, 20));
39 
40  bb = tvb.boundingBox(&trf);
41  CHECK_CLOSE_ABS(bb.max(), Vector3D(10, 38, 24), tol);
42  CHECK_CLOSE_ABS(bb.min(), Vector3D(-10, 22, 16), tol);
43 
44  trf = AngleAxis3D(M_PI / 2., Vector3D(-2, 4, 5).normalized());
45 
46  bb = tvb.boundingBox(&trf);
47  CHECK_CLOSE_ABS(bb.max(), Vector3D(9.32577, 11.4906, 11.5777), tol);
48  CHECK_CLOSE_ABS(bb.min(), Vector3D(-9.77021, -8.65268, -9.23688), tol);
49 }
50 
51 BOOST_AUTO_TEST_CASE(TrapezoidVolumeBoundarySurfaces) {
52  TrapezoidVolumeBounds tvb(5, 10, 8, 4);
53 
54  auto tvbOrientedSurfaces = tvb.orientedSurfaces(Transform3D::Identity());
55  BOOST_CHECK_EQUAL(tvbOrientedSurfaces.size(), 6);
56 
57  auto geoCtx = GeometryContext();
58 
59  for (auto& os : tvbOrientedSurfaces) {
60  auto osCenter = os.first->center(geoCtx);
61  auto osNormal = os.first->normal(geoCtx, osCenter);
62  double nDir = (double)os.second;
63  // Check if you step inside the volume with the oriented normal
64  auto insideTvb = osCenter + nDir * osNormal;
65  auto outsideTvb = osCenter - nDir * osNormal;
66  BOOST_CHECK(tvb.inside(insideTvb));
67  BOOST_CHECK(!tvb.inside(outsideTvb));
68  }
69 
70  Vector3D xaxis(1., 0., 0.);
71  Vector3D yaxis(0., 1., 0.);
72  Vector3D zaxis(0., 0., 1.);
73 
74  // Test the orientation of the boundary surfaces
75  auto nFaceXY =
76  tvbOrientedSurfaces[negativeFaceXY].first->transform(geoCtx).rotation();
77  BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
78  BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
79  BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
80 
81  auto pFaceXY =
82  tvbOrientedSurfaces[positiveFaceXY].first->transform(geoCtx).rotation();
83  BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
84  BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
85  BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
86 
87  auto nFaceZX =
88  tvbOrientedSurfaces[negativeFaceZX].first->transform(geoCtx).rotation();
89  BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
90  BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
91  BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
92 
93  auto pFaceZX =
94  tvbOrientedSurfaces[positiveFaceZX].first->transform(geoCtx).rotation();
95  BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
96  BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
97  BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
98 }
99 
100 BOOST_AUTO_TEST_SUITE_END()
101 
102 } // namespace Test
103 
104 } // namespace Acts