Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:42

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://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 <numbers>
0024 #include <utility>
0025 #include <vector>
0026 
0027 namespace Acts::Test {
0028 
0029 BOOST_AUTO_TEST_SUITE(Volumes)
0030 
0031 BOOST_AUTO_TEST_CASE(bounding_box_creation) {
0032   float tol = 1e-4;
0033 
0034   TrapezoidVolumeBounds tvb(5, 10, 8, 4);
0035 
0036   auto bb = tvb.boundingBox();
0037   CHECK_CLOSE_ABS(bb.max(), Vector3(10, 8, 4), tol);
0038   CHECK_CLOSE_ABS(bb.min(), Vector3(-10, -8, -4), tol);
0039 
0040   Transform3 trf;
0041 
0042   trf = Translation3(Vector3(0, 30, 20));
0043 
0044   bb = tvb.boundingBox(&trf);
0045   CHECK_CLOSE_ABS(bb.max(), Vector3(10, 38, 24), tol);
0046   CHECK_CLOSE_ABS(bb.min(), Vector3(-10, 22, 16), tol);
0047 
0048   trf = AngleAxis3(std::numbers::pi / 2., Vector3(-2, 4, 5).normalized());
0049 
0050   bb = tvb.boundingBox(&trf);
0051   CHECK_CLOSE_ABS(bb.max(), Vector3(9.32577, 11.4906, 11.5777), tol);
0052   CHECK_CLOSE_ABS(bb.min(), Vector3(-9.77021, -8.65268, -9.23688), tol);
0053 }
0054 
0055 BOOST_AUTO_TEST_CASE(TrapezoidVolumeBoundarySurfaces) {
0056   TrapezoidVolumeBounds tvb(5, 10, 8, 4);
0057 
0058   auto tvbOrientedSurfaces = tvb.orientedSurfaces(Transform3::Identity());
0059   BOOST_CHECK_EQUAL(tvbOrientedSurfaces.size(), 6);
0060 
0061   auto geoCtx = GeometryContext();
0062 
0063   for (auto& os : tvbOrientedSurfaces) {
0064     auto osCenter = os.surface->center(geoCtx);
0065     const auto* pSurface =
0066         dynamic_cast<const Acts::PlaneSurface*>(os.surface.get());
0067     BOOST_REQUIRE_MESSAGE(pSurface != nullptr,
0068                           "The surface is not a plane surface");
0069     auto osNormal = pSurface->normal(geoCtx);
0070     // Check if you step inside the volume with the oriented normal
0071     Vector3 insideTvb = osCenter + os.direction * osNormal;
0072     Vector3 outsideTvb = osCenter - os.direction * osNormal;
0073     BOOST_CHECK(tvb.inside(insideTvb));
0074     BOOST_CHECK(!tvb.inside(outsideTvb));
0075   }
0076 
0077   Vector3 xaxis(1., 0., 0.);
0078   Vector3 yaxis(0., 1., 0.);
0079   Vector3 zaxis(0., 0., 1.);
0080 
0081   // Test the orientation of the boundary surfaces
0082   auto nFaceXY =
0083       tvbOrientedSurfaces[negativeFaceXY].surface->transform(geoCtx).rotation();
0084   BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
0085   BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
0086   BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
0087 
0088   auto pFaceXY =
0089       tvbOrientedSurfaces[positiveFaceXY].surface->transform(geoCtx).rotation();
0090   BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
0091   BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
0092   BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
0093 
0094   auto nFaceZX =
0095       tvbOrientedSurfaces[negativeFaceZX].surface->transform(geoCtx).rotation();
0096   BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
0097   BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
0098   BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
0099 
0100   auto pFaceZX =
0101       tvbOrientedSurfaces[positiveFaceZX].surface->transform(geoCtx).rotation();
0102   BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
0103   BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
0104   BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
0105 }
0106 
0107 BOOST_AUTO_TEST_SUITE_END()
0108 
0109 }  // namespace Acts::Test