Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:53:18

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