Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:22

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019-2020 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Geometry/BoundarySurfaceFace.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0016 #include "Acts/Surfaces/PlaneSurface.hpp"
0017 #include "Acts/Surfaces/Surface.hpp"
0018 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0019 #include "Acts/Utilities/BoundingBox.hpp"
0020 
0021 #include <cmath>
0022 #include <memory>
0023 #include <utility>
0024 #include <vector>
0025 
0026 namespace Acts {
0027 namespace Test {
0028 BOOST_AUTO_TEST_SUITE(Volumes)
0029 
0030 BOOST_AUTO_TEST_CASE(bounding_box_creation) {
0031   float tol = 1e-4;
0032 
0033   TrapezoidVolumeBounds tvb(5, 10, 8, 4);
0034 
0035   auto bb = tvb.boundingBox();
0036   CHECK_CLOSE_ABS(bb.max(), Vector3(10, 8, 4), tol);
0037   CHECK_CLOSE_ABS(bb.min(), Vector3(-10, -8, -4), tol);
0038 
0039   Transform3 trf;
0040 
0041   trf = Translation3(Vector3(0, 30, 20));
0042 
0043   bb = tvb.boundingBox(&trf);
0044   CHECK_CLOSE_ABS(bb.max(), Vector3(10, 38, 24), tol);
0045   CHECK_CLOSE_ABS(bb.min(), Vector3(-10, 22, 16), tol);
0046 
0047   trf = AngleAxis3(M_PI / 2., Vector3(-2, 4, 5).normalized());
0048 
0049   bb = tvb.boundingBox(&trf);
0050   CHECK_CLOSE_ABS(bb.max(), Vector3(9.32577, 11.4906, 11.5777), tol);
0051   CHECK_CLOSE_ABS(bb.min(), Vector3(-9.77021, -8.65268, -9.23688), tol);
0052 }
0053 
0054 BOOST_AUTO_TEST_CASE(TrapezoidVolumeBoundarySurfaces) {
0055   TrapezoidVolumeBounds tvb(5, 10, 8, 4);
0056 
0057   auto tvbOrientedSurfaces = tvb.orientedSurfaces(Transform3::Identity());
0058   BOOST_CHECK_EQUAL(tvbOrientedSurfaces.size(), 6);
0059 
0060   auto geoCtx = GeometryContext();
0061 
0062   for (auto& os : tvbOrientedSurfaces) {
0063     auto osCenter = os.surface->center(geoCtx);
0064     const auto* pSurface =
0065         dynamic_cast<const Acts::PlaneSurface*>(os.surface.get());
0066     BOOST_REQUIRE_MESSAGE(pSurface != nullptr,
0067                           "The surface is not a plane surface");
0068     auto osNormal = pSurface->normal(geoCtx);
0069     // Check if you step inside the volume with the oriented normal
0070     Vector3 insideTvb = osCenter + os.direction * osNormal;
0071     Vector3 outsideTvb = osCenter - os.direction * osNormal;
0072     BOOST_CHECK(tvb.inside(insideTvb));
0073     BOOST_CHECK(!tvb.inside(outsideTvb));
0074   }
0075 
0076   Vector3 xaxis(1., 0., 0.);
0077   Vector3 yaxis(0., 1., 0.);
0078   Vector3 zaxis(0., 0., 1.);
0079 
0080   // Test the orientation of the boundary surfaces
0081   auto nFaceXY =
0082       tvbOrientedSurfaces[negativeFaceXY].surface->transform(geoCtx).rotation();
0083   BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
0084   BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
0085   BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
0086 
0087   auto pFaceXY =
0088       tvbOrientedSurfaces[positiveFaceXY].surface->transform(geoCtx).rotation();
0089   BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
0090   BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
0091   BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
0092 
0093   auto nFaceZX =
0094       tvbOrientedSurfaces[negativeFaceZX].surface->transform(geoCtx).rotation();
0095   BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
0096   BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
0097   BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
0098 
0099   auto pFaceZX =
0100       tvbOrientedSurfaces[positiveFaceZX].surface->transform(geoCtx).rotation();
0101   BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
0102   BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
0103   BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
0104 }
0105 
0106 BOOST_AUTO_TEST_SUITE_END()
0107 }  // namespace Test
0108 }  // namespace Acts