Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:09

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/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Surfaces/detail/LineHelper.hpp"
0015 #include "Acts/Surfaces/detail/PlanarHelper.hpp"
0016 #include "Acts/Utilities/UnitVectors.hpp"
0017 
0018 #include <format>
0019 
0020 using namespace Acts;
0021 
0022 namespace ActsTests {
0023 
0024 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0025 
0026 BOOST_AUTO_TEST_CASE(checkPlaneIsection) {
0027   using namespace PlanarHelper;
0028 
0029   const Vector3 pointInPlane{561., 0., 0.};
0030   const Vector3 planeNormal{Vector3::UnitX()};
0031 
0032   const Vector3 extPoint = pointInPlane + 50. * planeNormal;
0033   const Vector3 lineDir = Vector3{1., 5., 0.}.normalized();
0034 
0035   const Vector3 crossPoint = intersectPlane(extPoint, lineDir, planeNormal,
0036                                             planeNormal.dot(pointInPlane))
0037                                  .position();
0038 
0039   BOOST_CHECK_LE(std::abs(pointInPlane.x() - crossPoint.x()),
0040                  std::numeric_limits<float>::epsilon());
0041   BOOST_CHECK_LE(std::abs(pointInPlane.y() - crossPoint.y() - 250.),
0042                  std::numeric_limits<float>::epsilon());
0043 }
0044 
0045 BOOST_AUTO_TEST_CASE(lineDistance) {
0046   using namespace detail::LineHelper;
0047   using namespace UnitLiterals;
0048   const Vector3 posA{100, 0., 0.};
0049   const Vector3 posB{100, 50, 0.};
0050   constexpr double tolerance = 1.e-12;
0051 
0052   const double parallelTest =
0053       signedDistance(posA, Vector3::UnitZ(), posB, Vector3::UnitZ());
0054   BOOST_CHECK_LE(std::abs(parallelTest - 50), tolerance);
0055   std::cout << __FILE__ << ":" << __LINE__
0056             << " - Passed test between two parallel crossing lines: "
0057             << parallelTest << std::endl;
0058 
0059   const double orthogonalTest =
0060       std::abs(signedDistance(posA, Vector3::UnitX(), posB, Vector3::UnitZ()));
0061   BOOST_CHECK_LE(std::abs(orthogonalTest - 50), tolerance);
0062   std::cout << __FILE__ << ":" << __LINE__
0063             << " - Passed test between two orthogonal lines: " << orthogonalTest
0064             << std::endl;
0065 
0066   constexpr double angleXY = 36. * 1_degree;
0067   const Vector3 dirInXY{makeDirectionFromPhiTheta(0., angleXY)};
0068   const double planeXYTest = signedDistance(posA, dirInXY, posB, dirInXY);
0069   BOOST_CHECK_LE(std::abs(planeXYTest - 50.), tolerance);
0070   const double planeXYTest1 = signedDistance(posA, dirInXY, posB, dirInXY);
0071   BOOST_CHECK_LE(std::abs(std::abs(planeXYTest1) - 50.), tolerance);
0072   std::cout << __FILE__ << ":" << __LINE__
0073             << " - Passed test between two parallel lines in the x-y plane: "
0074             << planeXYTest << std::endl;
0075   /// Generate a plumb-line
0076   const Vector3 plumbDir{-dirInXY.z(), 0., dirInXY.x()};
0077   /// Another vector that's perpendicular to the plumb but not parallel to the
0078   /// original line
0079   const Vector3 extDir =
0080       (5. * dirInXY + 21. * plumbDir.cross(dirInXY)).normalized();
0081 
0082   BOOST_CHECK_LE(extDir.dot(plumbDir), tolerance);
0083   BOOST_CHECK_LE(plumbDir.dot(dirInXY), tolerance);
0084   /// Create a random external point that's used as reference for the second
0085   /// test line
0086   const Vector3 extPoint =
0087       posA + 50. * dirInXY + 50. * plumbDir + 400. * extDir;
0088   /// Recuperate the external point that's closest to the primary line
0089   const Vector3 closePointExt =
0090       lineIntersect(posA, dirInXY, extPoint, extDir).position();
0091   BOOST_CHECK_LE((posA + 50. * dirInXY + 50. * plumbDir - closePointExt).norm(),
0092                  tolerance);
0093   /// Let's get the second closest point
0094   const Vector3 closePointXY =
0095       lineIntersect(extPoint, extDir, posA, dirInXY).position();
0096   BOOST_CHECK_LE((posA + 50. * dirInXY - closePointXY).norm(), tolerance);
0097   /// Calculate the distance between the two close points
0098   BOOST_CHECK_LE(std::abs((closePointXY - closePointExt).norm() - 50.),
0099                  tolerance);
0100 
0101   const double extLineDist = signedDistance(posA, dirInXY, extPoint, extDir);
0102   BOOST_CHECK_LE(std::abs(extLineDist - 50.), tolerance);
0103   const double extLineDist1 = signedDistance(posA, dirInXY, extPoint, extDir);
0104   BOOST_CHECK_LE(std::abs(extLineDist1 - 50.), tolerance);
0105   /// Finally the case when both lines are crossing
0106   const double crossLines =
0107       signedDistance(extPoint + 525. * dirInXY, dirInXY, extPoint, extDir);
0108   // Use a larger tolerance here.  This is the result of the sqrt of the
0109   // difference of numbers O(1e-5), so even with double precision, we can't
0110   // expect much better than this.
0111   BOOST_CHECK_LE(std::abs(crossLines), 1e-5);
0112 }
0113 BOOST_AUTO_TEST_SUITE_END()
0114 
0115 }  // namespace ActsTests