Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12: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/data/test_case.hpp>
0010 #include <boost/test/tools/output_test_stream.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/Definitions/Tolerance.hpp"
0015 #include "Acts/Geometry/Extent.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Geometry/Polyhedron.hpp"
0018 #include "Acts/Surfaces/ConeBounds.hpp"
0019 #include "Acts/Surfaces/ConeSurface.hpp"
0020 #include "Acts/Surfaces/Surface.hpp"
0021 #include "Acts/Surfaces/SurfaceBounds.hpp"
0022 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0023 #include "Acts/Utilities/BinningType.hpp"
0024 #include "Acts/Utilities/Result.hpp"
0025 #include "Acts/Utilities/ThrowAssert.hpp"
0026 
0027 #include <cmath>
0028 #include <memory>
0029 #include <numbers>
0030 #include <string>
0031 
0032 namespace Acts::Test {
0033 
0034 // Create a test context
0035 GeometryContext tgContext = GeometryContext();
0036 
0037 BOOST_AUTO_TEST_SUITE(ConeSurfaces)
0038 
0039 /// Unit test for creating compliant/non-compliant ConeSurface object
0040 BOOST_AUTO_TEST_CASE(ConeSurfaceConstruction) {
0041   /// Test default construction
0042   // default construction is deleted
0043 
0044   /// Constructor with transform, alpha and symmetry indicator
0045   const double alpha = std::numbers::pi / 8.;
0046   const double halfPhiSector = std::numbers::pi / 16.;
0047   const double zMin = 1.;
0048   const double zMax = 10.;
0049   const bool symmetric = false;
0050   const Translation3 translation{0., 1., 2.};
0051 
0052   auto pTransform = Transform3(translation);
0053   BOOST_CHECK_EQUAL(
0054       Surface::makeShared<ConeSurface>(Transform3::Identity(), alpha, symmetric)
0055           ->type(),
0056       Surface::Cone);
0057   BOOST_CHECK_EQUAL(
0058       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric)->type(),
0059       Surface::Cone);
0060 
0061   /// Constructor with transform pointer, alpha,z min and max, halfPhiSector
0062   BOOST_CHECK_EQUAL(Surface::makeShared<ConeSurface>(pTransform, alpha, zMin,
0063                                                      zMax, halfPhiSector)
0064                         ->type(),
0065                     Surface::Cone);
0066 
0067   /// Constructor with transform and ConeBounds pointer
0068   auto pConeBounds =
0069       std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
0070   BOOST_CHECK_EQUAL(
0071       Surface::makeShared<ConeSurface>(pTransform, pConeBounds)->type(),
0072       Surface::Cone);
0073 
0074   /// Copy constructor
0075   auto coneSurfaceObject =
0076       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0077   auto copiedConeSurface = Surface::makeShared<ConeSurface>(*coneSurfaceObject);
0078   BOOST_CHECK_EQUAL(copiedConeSurface->type(), Surface::Cone);
0079   BOOST_CHECK(*copiedConeSurface == *coneSurfaceObject);
0080 
0081   /// Copied and transformed
0082   auto copiedTransformedConeSurface = Surface::makeShared<ConeSurface>(
0083       tgContext, *coneSurfaceObject, pTransform);
0084   BOOST_CHECK_EQUAL(copiedTransformedConeSurface->type(), Surface::Cone);
0085 
0086   /// Construct with nullptr bounds
0087   BOOST_CHECK_THROW(auto nullBounds = Surface::makeShared<ConeSurface>(
0088                         Transform3::Identity(), nullptr),
0089                     AssertionFailureException);
0090 }
0091 
0092 /// Unit test for testing ConeSurface properties
0093 BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
0094   /// Test clone method
0095   const double alpha = std::numbers::pi / 8.;
0096   const bool symmetric = false;
0097   const Translation3 translation{0., 1., 2.};
0098 
0099   auto pTransform = Transform3(translation);
0100   auto coneSurfaceObject =
0101       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0102 
0103   /// Test type (redundant)
0104   BOOST_CHECK_EQUAL(coneSurfaceObject->type(), Surface::Cone);
0105 
0106   /// Test referencePosition
0107   Vector3 referencePosition{0., 1., 2.};
0108   CHECK_CLOSE_ABS(
0109       coneSurfaceObject->referencePosition(tgContext, AxisDirection::AxisPhi),
0110       referencePosition, 1e-6);
0111 
0112   /// Test referenceFrame
0113   Vector3 globalPosition{2., 2., 2.};
0114   Vector3 momentum{1.e6, 1.e6, 1.e6};
0115   double rootHalf = std::sqrt(0.5);
0116   RotationMatrix3 expectedFrame;
0117   expectedFrame << -rootHalf, 0., rootHalf, rootHalf, 0., rootHalf, 0., 1., 0.;
0118   CHECK_CLOSE_OR_SMALL(
0119       coneSurfaceObject->referenceFrame(tgContext, globalPosition, momentum),
0120       expectedFrame, 1e-6, 1e-9);
0121 
0122   /// Test normal, given 3D position
0123   Vector3 origin{0., 0., 0.};
0124   Vector3 normal3D = {0., -1., 0.};
0125   CHECK_CLOSE_ABS(coneSurfaceObject->normal(tgContext, origin), normal3D, 1e-6);
0126 
0127   /// Test normal given 2D rphi position
0128   Vector2 positionPiBy2(1., std::numbers::pi / 2.);
0129   Vector3 normalAtPiBy2{0.0312768, 0.92335, -0.382683};
0130 
0131   CHECK_CLOSE_OR_SMALL(coneSurfaceObject->normal(tgContext, positionPiBy2),
0132                        normalAtPiBy2, 1e-2, 1e-9);
0133 
0134   /// Test rotational symmetry axis
0135   Vector3 symmetryAxis{0., 0., 1.};
0136   CHECK_CLOSE_ABS(coneSurfaceObject->rotSymmetryAxis(tgContext), symmetryAxis,
0137                   1e-6);
0138 
0139   /// Test bounds
0140   BOOST_CHECK_EQUAL(coneSurfaceObject->bounds().type(), SurfaceBounds::eCone);
0141 
0142   /// Test localToGlobal
0143   Vector2 localPosition{1., std::numbers::pi / 2.};
0144   globalPosition =
0145       coneSurfaceObject->localToGlobal(tgContext, localPosition, momentum);
0146   Vector3 expectedPosition{0.0220268, 1.65027, 3.5708};
0147 
0148   CHECK_CLOSE_REL(globalPosition, expectedPosition, 1e-2);
0149 
0150   /// Testing globalToLocal
0151   localPosition =
0152       coneSurfaceObject->globalToLocal(tgContext, globalPosition, momentum)
0153           .value();
0154   Vector2 expectedLocalPosition{1., std::numbers::pi / 2.};
0155 
0156   CHECK_CLOSE_REL(localPosition, expectedLocalPosition, 1e-6);
0157 
0158   /// Test isOnSurface
0159   Vector3 offSurface{100, 1, 2};
0160   BOOST_CHECK(coneSurfaceObject->isOnSurface(
0161       tgContext, globalPosition, momentum, BoundaryTolerance::None()));
0162   BOOST_CHECK(!coneSurfaceObject->isOnSurface(tgContext, offSurface, momentum,
0163                                               BoundaryTolerance::None()));
0164 
0165   /// Test pathCorrection
0166   CHECK_CLOSE_REL(coneSurfaceObject->pathCorrection(tgContext, offSurface,
0167                                                     momentum.normalized()),
0168                   0.40218866453252877, 0.01);
0169 
0170   /// Test name
0171   BOOST_CHECK_EQUAL(coneSurfaceObject->name(),
0172                     std::string("Acts::ConeSurface"));
0173 
0174   /// Test dump
0175   boost::test_tools::output_test_stream dumpOutput;
0176   dumpOutput << coneSurfaceObject->toStream(tgContext);
0177   BOOST_CHECK(dumpOutput.is_equal(
0178       "Acts::ConeSurface\n"
0179       "     Center position  (x, y, z) = (0.0000, 1.0000, 2.0000)\n"
0180       "     Rotation:             colX = (1.000000, 0.000000, 0.000000)\n"
0181       "                           colY = (0.000000, 1.000000, 0.000000)\n"
0182       "                           colZ = (0.000000, 0.000000, 1.000000)\n"
0183       "     Bounds  : Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, "
0184       "averagePhi) = (0.4142136, 0.0000000, inf, 3.1415927, 0.0000000)"
0185 
0186       ));
0187 }
0188 
0189 BOOST_AUTO_TEST_CASE(ConeSurfaceEqualityOperators) {
0190   const double alpha = std::numbers::pi / 8.;
0191   const bool symmetric = false;
0192   const Translation3 translation{0., 1., 2.};
0193 
0194   auto pTransform = Transform3(translation);
0195   auto coneSurfaceObject =
0196       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0197 
0198   auto coneSurfaceObject2 =
0199       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0200 
0201   /// Test equality operator
0202   BOOST_CHECK(*coneSurfaceObject == *coneSurfaceObject2);
0203 
0204   BOOST_TEST_CHECKPOINT(
0205       "Create and then assign a ConeSurface object to the existing one");
0206   /// Test assignment
0207   auto assignedConeSurface =
0208       Surface::makeShared<ConeSurface>(Transform3::Identity(), 0.1, true);
0209   *assignedConeSurface = *coneSurfaceObject;
0210   /// Test equality of assigned to original
0211   BOOST_CHECK(*assignedConeSurface == *coneSurfaceObject);
0212 }
0213 
0214 BOOST_AUTO_TEST_CASE(ConeSurfaceExtent) {
0215   const double alpha = std::numbers::pi / 8.;
0216   const double halfPhiSector = std::numbers::pi / 8.;  // != pi/16
0217   const double zMin = 0.;                              // != 1.
0218   const double zMax = 10.;
0219   const Translation3 translation{0., 0., 0.};  // != {0., 1., 2.}
0220 
0221   /// Testing a Full cone
0222   auto pTransform = Transform3(translation);
0223   auto pConeBounds = std::make_shared<const ConeBounds>(alpha, zMin, zMax);
0224   auto pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
0225   auto pConeExtent = pCone->polyhedronRepresentation(tgContext, 1).extent();
0226 
0227   double rMax = zMax * std::tan(alpha);
0228   CHECK_CLOSE_ABS(zMin, pConeExtent.min(AxisDirection::AxisZ),
0229                   s_onSurfaceTolerance);
0230   CHECK_CLOSE_ABS(zMax, pConeExtent.max(AxisDirection::AxisZ),
0231                   s_onSurfaceTolerance);
0232   CHECK_CLOSE_ABS(0., pConeExtent.min(AxisDirection::AxisR),
0233                   s_onSurfaceTolerance);
0234   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisR),
0235                   s_onSurfaceTolerance);
0236   CHECK_CLOSE_ABS(-rMax, pConeExtent.min(AxisDirection::AxisX),
0237                   s_onSurfaceTolerance);
0238   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisX),
0239                   s_onSurfaceTolerance);
0240   CHECK_CLOSE_ABS(-rMax, pConeExtent.min(AxisDirection::AxisY),
0241                   s_onSurfaceTolerance);
0242   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisY),
0243                   s_onSurfaceTolerance);
0244 
0245   /// Now a sector
0246   pConeBounds =
0247       std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
0248   pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
0249   pConeExtent = pCone->polyhedronRepresentation(tgContext, 1).extent();
0250 
0251   CHECK_CLOSE_ABS(zMin, pConeExtent.min(AxisDirection::AxisZ),
0252                   s_onSurfaceTolerance);
0253   CHECK_CLOSE_ABS(zMax, pConeExtent.max(AxisDirection::AxisZ),
0254                   s_onSurfaceTolerance);
0255   CHECK_CLOSE_ABS(0., pConeExtent.min(AxisDirection::AxisR),
0256                   s_onSurfaceTolerance);
0257   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisR),
0258                   s_onSurfaceTolerance);
0259 }
0260 
0261 /// Unit test for testing ConeSurface alignment derivatives
0262 BOOST_AUTO_TEST_CASE(ConeSurfaceAlignment) {
0263   const double alpha = std::numbers::pi / 8.;
0264   const bool symmetric = false;
0265   const Translation3 translation{0., 1., 2.};
0266 
0267   auto pTransform = Transform3(translation);
0268   auto coneSurfaceObject =
0269       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0270 
0271   const auto& rotation = pTransform.rotation();
0272   // The local frame z axis
0273   const Vector3 localZAxis = rotation.col(2);
0274   // Check the local z axis is aligned to global z axis
0275   CHECK_CLOSE_ABS(localZAxis, Vector3(0., 0., 1.), 1e-15);
0276 
0277   /// Define the track (global) position and direction
0278   Vector3 globalPosition{0, 1. + std::tan(alpha), 3};
0279 
0280   // Test the derivative of bound track parameters local position w.r.t.
0281   // position in local 3D Cartesian coordinates
0282   const auto& loc3DToLocBound =
0283       coneSurfaceObject->localCartesianToBoundLocalDerivative(tgContext,
0284                                                               globalPosition);
0285   // Check if the result is as expected
0286   ActsMatrix<2, 3> expLoc3DToLocBound = ActsMatrix<2, 3>::Zero();
0287   expLoc3DToLocBound << -1, 0, std::numbers::pi / 2. * std::tan(alpha), 0, 0, 1;
0288   CHECK_CLOSE_ABS(loc3DToLocBound, expLoc3DToLocBound, 1e-10);
0289 }
0290 
0291 BOOST_AUTO_TEST_SUITE_END()
0292 }  // namespace Acts::Test