Back to home page

EIC code displayed by LXR

 
 

    


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

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/Definitions/Tolerance.hpp"
0014 #include "Acts/Geometry/BoundarySurfaceFace.hpp"
0015 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Geometry/VolumeBounds.hpp"
0018 #include "Acts/Surfaces/PlaneSurface.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0021 
0022 #include <algorithm>
0023 #include <array>
0024 #include <memory>
0025 #include <stdexcept>
0026 #include <utility>
0027 #include <vector>
0028 
0029 namespace Acts::Test {
0030 
0031 GeometryContext gctx = GeometryContext();
0032 
0033 double hx{10.}, hy{20.}, hz{30.};
0034 
0035 BOOST_AUTO_TEST_SUITE(Geometry)
0036 
0037 BOOST_AUTO_TEST_CASE(CuboidVolumeConstruction) {
0038   // Test Construction
0039   CuboidVolumeBounds box(hx, hy, hz);
0040 
0041   // Test copy construction
0042   CuboidVolumeBounds copied(box);
0043   BOOST_CHECK_EQUAL(box, copied);
0044 
0045   // Test assigned
0046   CuboidVolumeBounds assigned = box;
0047   BOOST_CHECK_EQUAL(box, assigned);
0048 }
0049 
0050 BOOST_AUTO_TEST_CASE(CuboidVolumeRecreation) {
0051   CuboidVolumeBounds original(hx, hy, hz);
0052   auto valvector = original.values();
0053   std::array<double, CuboidVolumeBounds::eSize> values{};
0054   std::copy_n(valvector.begin(), CuboidVolumeBounds::eSize, values.begin());
0055   CuboidVolumeBounds recreated(values);
0056   BOOST_CHECK_EQUAL(original, recreated);
0057 }
0058 
0059 BOOST_AUTO_TEST_CASE(CuboidVolumeException) {
0060   // Test exception negative x
0061   BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, hy, hz), std::logic_error);
0062   // Test exception negative y
0063   BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, hz), std::logic_error);
0064   // Test exception negative z
0065   BOOST_CHECK_THROW(CuboidVolumeBounds(hx, hy, -hz), std::logic_error);
0066   // Other iterations 0
0067   BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, hy, -hz), std::logic_error);
0068   // Other iterations 1
0069   BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, hz), std::logic_error);
0070   // Other iterations 2
0071   BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, -hz), std::logic_error);
0072   // Other iterations : all
0073   BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, -hz), std::logic_error);
0074 }
0075 
0076 BOOST_AUTO_TEST_CASE(CuboidVolumeProperties) {
0077   CuboidVolumeBounds box(hx, hy, hz);
0078   // Test the type
0079   BOOST_CHECK_EQUAL(box.type(), VolumeBounds::eCuboid);
0080   // Test the halflength x
0081   CHECK_CLOSE_ABS(box.get(CuboidVolumeBounds::eHalfLengthX), hx, s_epsilon);
0082   // Test the halflength y
0083   CHECK_CLOSE_ABS(box.get(CuboidVolumeBounds::eHalfLengthY), hy, s_epsilon);
0084   // Test the halflength z
0085   CHECK_CLOSE_ABS(box.get(CuboidVolumeBounds::eHalfLengthZ), hz, s_epsilon);
0086   // Test the streaming
0087   std::vector<double> actvalues = box.values();
0088   std::vector<double> refvalues = {hx, hy, hz};
0089   BOOST_CHECK_EQUAL_COLLECTIONS(actvalues.begin(), actvalues.end(),
0090                                 refvalues.begin(), refvalues.end());
0091 
0092   // Inside position
0093   Vector3 inside({5., 10., 8.});
0094   // Outside positions  in x, y, z
0095   std::vector<Vector3> outsides = {
0096       {20., 1., -2.}, {1., -30., 2.}, {-1., 2., 100.}};
0097 
0098   // Inside position
0099   BOOST_CHECK(box.inside(inside, s_onSurfaceTolerance));
0100 
0101   // Outside position
0102   for (const auto& outside : outsides) {
0103     BOOST_CHECK(!box.inside(outside, s_onSurfaceTolerance));
0104   }
0105 
0106   // Check the binning value positions
0107   CHECK_CLOSE_ABS(box.referenceBorder(Acts::AxisDirection::AxisX), hx,
0108                   s_epsilon);
0109   CHECK_CLOSE_ABS(box.referenceBorder(Acts::AxisDirection::AxisY), hy,
0110                   s_epsilon);
0111   CHECK_CLOSE_ABS(box.referenceBorder(Acts::AxisDirection::AxisZ), hz,
0112                   s_epsilon);
0113   CHECK_CLOSE_ABS(box.referenceBorder(Acts::AxisDirection::AxisR),
0114                   std::sqrt(hx * hx + hy * hy), s_epsilon);
0115 }
0116 
0117 BOOST_AUTO_TEST_CASE(CuboidVolumeBoundarySurfaces) {
0118   CuboidVolumeBounds box(5, 8, 7);
0119   auto cvbOrientedSurfaces = box.orientedSurfaces(Transform3::Identity());
0120 
0121   BOOST_CHECK_EQUAL(cvbOrientedSurfaces.size(), 6);
0122 
0123   auto geoCtx = GeometryContext();
0124 
0125   for (auto& os : cvbOrientedSurfaces) {
0126     auto osCenter = os.surface->center(geoCtx);
0127     const auto* pSurface =
0128         dynamic_cast<const Acts::PlaneSurface*>(os.surface.get());
0129     BOOST_REQUIRE_MESSAGE(pSurface != nullptr,
0130                           "The surface is not a plane surface");
0131     auto osNormal = pSurface->normal(geoCtx);
0132     // Check if you step inside the volume with the oriented normal
0133     Vector3 insideBox = osCenter + os.direction * osNormal;
0134     Vector3 outsideBox = osCenter - os.direction * osNormal;
0135     BOOST_CHECK(box.inside(insideBox));
0136     BOOST_CHECK(!box.inside(outsideBox));
0137   }
0138 
0139   Vector3 xaxis(1., 0., 0.);
0140   Vector3 yaxis(0., 1., 0.);
0141   Vector3 zaxis(0., 0., 1.);
0142 
0143   // Test the orientation of the boundary surfaces
0144   auto nFaceXY =
0145       cvbOrientedSurfaces[negativeFaceXY].surface->transform(geoCtx).rotation();
0146   BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
0147   BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
0148   BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
0149 
0150   auto pFaceXY =
0151       cvbOrientedSurfaces[positiveFaceXY].surface->transform(geoCtx).rotation();
0152   BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
0153   BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
0154   BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
0155 
0156   auto nFaceYZ =
0157       cvbOrientedSurfaces[negativeFaceYZ].surface->transform(geoCtx).rotation();
0158   BOOST_CHECK(nFaceYZ.col(0).isApprox(yaxis));
0159   BOOST_CHECK(nFaceYZ.col(1).isApprox(zaxis));
0160   BOOST_CHECK(nFaceYZ.col(2).isApprox(xaxis));
0161 
0162   auto pFaceYZ =
0163       cvbOrientedSurfaces[positiveFaceYZ].surface->transform(geoCtx).rotation();
0164   BOOST_CHECK(pFaceYZ.col(0).isApprox(yaxis));
0165   BOOST_CHECK(pFaceYZ.col(1).isApprox(zaxis));
0166   BOOST_CHECK(pFaceYZ.col(2).isApprox(xaxis));
0167 
0168   auto nFaceZX =
0169       cvbOrientedSurfaces[negativeFaceZX].surface->transform(geoCtx).rotation();
0170   BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
0171   BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
0172   BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
0173 
0174   auto pFaceZX =
0175       cvbOrientedSurfaces[positiveFaceZX].surface->transform(geoCtx).rotation();
0176   BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
0177   BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
0178   BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
0179 }
0180 
0181 BOOST_AUTO_TEST_CASE(CuboidVolumeBoundsSetValues) {
0182   CuboidVolumeBounds box(5, 8, 7);
0183 
0184   for (auto bValue :
0185        {CuboidVolumeBounds::eHalfLengthX, CuboidVolumeBounds::eHalfLengthY,
0186         CuboidVolumeBounds::eHalfLengthZ}) {
0187     double target = 0.5 * box.get(bValue);
0188     double previous = box.get(bValue);
0189     BOOST_CHECK_THROW(box.set(bValue, -1), std::logic_error);
0190     BOOST_CHECK_EQUAL(box.get(bValue), previous);
0191     box.set(bValue, target);
0192     BOOST_CHECK_EQUAL(box.get(bValue), target);
0193   }
0194 
0195   auto previous = box.values();
0196 
0197   BOOST_CHECK_THROW(box.set({
0198                         {CuboidVolumeBounds::eHalfLengthX, -1},
0199                         {CuboidVolumeBounds::eHalfLengthY, 1},
0200                     }),
0201                     std::logic_error);
0202   auto act = box.values();
0203   BOOST_CHECK_EQUAL_COLLECTIONS(previous.begin(), previous.end(), act.begin(),
0204                                 act.end());
0205 }
0206 
0207 BOOST_AUTO_TEST_SUITE_END()
0208 
0209 }  // namespace Acts::Test