Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:50

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