Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-19 09:45:32

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/Alignment.hpp"
0015 #include "Acts/Definitions/Tolerance.hpp"
0016 #include "Acts/Definitions/TrackParametrization.hpp"
0017 #include "Acts/Geometry/Extent.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/Geometry/Polyhedron.hpp"
0020 #include "Acts/Material/BinnedSurfaceMaterial.hpp"
0021 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0022 #include "Acts/Material/Material.hpp"
0023 #include "Acts/Material/MaterialSlab.hpp"
0024 #include "Acts/Surfaces/ConeBounds.hpp"
0025 #include "Acts/Surfaces/ConeSurface.hpp"
0026 #include "Acts/Surfaces/Surface.hpp"
0027 #include "Acts/Surfaces/SurfaceBounds.hpp"
0028 #include "Acts/Utilities/AxisDefinitions.hpp"
0029 #include "Acts/Utilities/BinUtility.hpp"
0030 #include "Acts/Utilities/BinningType.hpp"
0031 #include "Acts/Utilities/Diagnostics.hpp"
0032 #include "Acts/Utilities/Result.hpp"
0033 #include "Acts/Utilities/ThrowAssert.hpp"
0034 #include "Acts/Utilities/TransformHelpers.hpp"
0035 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0036 #include "ActsTests/CommonHelpers/SurfaceDerivatives.hpp"
0037 
0038 #include <cmath>
0039 #include <memory>
0040 #include <numbers>
0041 #include <string>
0042 
0043 using namespace Acts;
0044 namespace ActsTests {
0045 
0046 // Create a test context
0047 GeometryContext tgContext = GeometryContext::dangerouslyDefaultConstruct();
0048 
0049 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0050 
0051 /// Unit test for creating compliant/non-compliant ConeSurface object
0052 BOOST_AUTO_TEST_CASE(ConeSurfaceConstruction) {
0053   /// Test default construction
0054   // default construction is deleted
0055 
0056   /// Constructor with transform, alpha and symmetry indicator
0057   const double alpha = std::numbers::pi / 8.;
0058   const double halfPhiSector = std::numbers::pi / 16.;
0059   const double zMin = 1.;
0060   const double zMax = 10.;
0061   const bool symmetric = false;
0062   const Translation3 translation{0., 1., 2.};
0063 
0064   auto pTransform = Transform3(translation);
0065   BOOST_CHECK_EQUAL(
0066       Surface::makeShared<ConeSurface>(Transform3::Identity(), alpha, symmetric)
0067           ->type(),
0068       Surface::Cone);
0069   BOOST_CHECK_EQUAL(
0070       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric)->type(),
0071       Surface::Cone);
0072 
0073   /// Constructor with transform pointer, alpha,z min and max, halfPhiSector
0074   BOOST_CHECK_EQUAL(Surface::makeShared<ConeSurface>(pTransform, alpha, zMin,
0075                                                      zMax, halfPhiSector)
0076                         ->type(),
0077                     Surface::Cone);
0078 
0079   /// Constructor with transform and ConeBounds pointer
0080   auto pConeBounds =
0081       std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
0082   BOOST_CHECK_EQUAL(
0083       Surface::makeShared<ConeSurface>(pTransform, pConeBounds)->type(),
0084       Surface::Cone);
0085 
0086   /// Copy constructor
0087   auto coneSurfaceObject =
0088       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0089   auto copiedConeSurface = Surface::makeShared<ConeSurface>(*coneSurfaceObject);
0090   BOOST_CHECK_EQUAL(copiedConeSurface->type(), Surface::Cone);
0091   BOOST_CHECK(*copiedConeSurface == *coneSurfaceObject);
0092 
0093   /// Copied and transformed
0094   auto copiedTransformedConeSurface = Surface::makeShared<ConeSurface>(
0095       tgContext, *coneSurfaceObject, pTransform);
0096   BOOST_CHECK_EQUAL(copiedTransformedConeSurface->type(), Surface::Cone);
0097 
0098   /// Construct with nullptr bounds
0099   BOOST_CHECK_THROW(auto nullBounds = Surface::makeShared<ConeSurface>(
0100                         Transform3::Identity(), nullptr),
0101                     AssertionFailureException);
0102 }
0103 
0104 /// Unit test for testing ConeSurface properties
0105 BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
0106   /// Test clone method
0107   const double alpha = std::numbers::pi / 8.;
0108   const bool symmetric = false;
0109   const Translation3 translation{0., 1., 2.};
0110 
0111   auto pTransform = Transform3(translation);
0112   auto coneSurfaceObject =
0113       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0114 
0115   /// Test type (redundant)
0116   BOOST_CHECK_EQUAL(coneSurfaceObject->type(), Surface::Cone);
0117 
0118   /// Test referencePosition
0119   Vector3 referencePosition{0., 1., 2.};
0120   CHECK_CLOSE_ABS(
0121       coneSurfaceObject->referencePosition(tgContext, AxisDirection::AxisPhi),
0122       referencePosition, 1e-6);
0123 
0124   /// Test referenceFrame: (e_phi, n x e_phi, n) with the cone normal
0125   Vector3 globalPosition{2., 2., 2.};
0126   Vector3 momentum{1.e6, 1.e6, 1.e6};
0127   const Vector3 frameLocal = globalPosition - Vector3(0., 1., 2.);
0128   const double framePhi = std::atan2(frameLocal.y(), frameLocal.x());
0129   const double cosAlpha = std::cos(alpha);
0130   const double sinAlpha = std::sin(alpha);
0131   const double frameSgn = -std::copysign(1., frameLocal.z());
0132   const Vector3 frameNormal{std::cos(framePhi) * cosAlpha,
0133                             std::sin(framePhi) * cosAlpha, frameSgn * sinAlpha};
0134   const Vector3 framePhiAxis{-std::sin(framePhi), std::cos(framePhi), 0.};
0135   RotationMatrix3 expectedFrame;
0136   expectedFrame.col(0) = framePhiAxis;
0137   expectedFrame.col(1) = frameNormal.cross(framePhiAxis);
0138   expectedFrame.col(2) = frameNormal;
0139   CHECK_CLOSE_OR_SMALL(
0140       coneSurfaceObject->referenceFrame(tgContext, globalPosition, momentum),
0141       expectedFrame, 1e-6, 1e-9);
0142 
0143   /// Test normal, given 3D position. Local position of the origin is (0, -1,
0144   /// -2).
0145   Vector3 origin{0., 0., 0.};
0146   const double originPhi = std::atan2(-1., 0.);
0147   const double originSgn = -std::copysign(1., -2.);
0148   Vector3 normal3D{std::cos(originPhi) * cosAlpha,
0149                    std::sin(originPhi) * cosAlpha, originSgn * sinAlpha};
0150   CHECK_CLOSE_ABS(coneSurfaceObject->normal(tgContext, origin), normal3D, 1e-6);
0151 
0152   /// Test normal given 2D rphi position
0153   Vector2 positionPiBy2(1., std::numbers::pi / 2.);
0154   Vector3 normalAtPiBy2{0.0312768, 0.92335, -0.382683};
0155 
0156   CHECK_CLOSE_OR_SMALL(coneSurfaceObject->normal(tgContext, positionPiBy2),
0157                        normalAtPiBy2, 1e-2, 1e-9);
0158 
0159   /// Test rotational symmetry axis
0160   Vector3 symmetryAxis{0., 0., 1.};
0161   CHECK_CLOSE_ABS(coneSurfaceObject->rotSymmetryAxis(tgContext), symmetryAxis,
0162                   1e-6);
0163 
0164   /// Test bounds
0165   BOOST_CHECK_EQUAL(coneSurfaceObject->bounds().type(), SurfaceBounds::eCone);
0166 
0167   /// Test localToGlobal
0168   Vector2 localPosition{1., std::numbers::pi / 2.};
0169   globalPosition =
0170       coneSurfaceObject->localToGlobal(tgContext, localPosition, momentum);
0171   Vector3 expectedPosition{0.0220268, 1.65027, 3.5708};
0172 
0173   CHECK_CLOSE_REL(globalPosition, expectedPosition, 1e-2);
0174 
0175   /// Testing globalToLocal
0176   localPosition =
0177       coneSurfaceObject->globalToLocal(tgContext, globalPosition, momentum)
0178           .value();
0179   Vector2 expectedLocalPosition{1., std::numbers::pi / 2.};
0180 
0181   CHECK_CLOSE_REL(localPosition, expectedLocalPosition, 1e-6);
0182 
0183   /// Test isOnSurface
0184   Vector3 offSurface{100, 1, 2};
0185   BOOST_CHECK(coneSurfaceObject->isOnSurface(
0186       tgContext, globalPosition, momentum, BoundaryTolerance::None()));
0187   BOOST_CHECK(!coneSurfaceObject->isOnSurface(tgContext, offSurface, momentum,
0188                                               BoundaryTolerance::None()));
0189 
0190   /// Test pathCorrection
0191   CHECK_CLOSE_REL(coneSurfaceObject->pathCorrection(tgContext, offSurface,
0192                                                     momentum.normalized()),
0193                   3.20041, 0.01);
0194 
0195   /// Test name
0196   BOOST_CHECK_EQUAL(coneSurfaceObject->name(),
0197                     std::string("Acts::ConeSurface"));
0198 
0199   /// Test dump
0200   boost::test_tools::output_test_stream dumpOutput;
0201   dumpOutput << coneSurfaceObject->toStream(tgContext);
0202   BOOST_CHECK(dumpOutput.is_equal(
0203       "Acts::ConeSurface\n"
0204       "     Center position  (x, y, z) = (0.0000, 1.0000, 2.0000)\n"
0205       "     Rotation:             colX = (1.000000, 0.000000, 0.000000)\n"
0206       "                           colY = (0.000000, 1.000000, 0.000000)\n"
0207       "                           colZ = (0.000000, 0.000000, 1.000000)\n"
0208       "     Bounds  : Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, "
0209       "averagePhi) = (0.4142136, 0.0000000, inf, 3.1415927, 0.0000000)"
0210 
0211       ));
0212 }
0213 
0214 BOOST_AUTO_TEST_CASE(ConeSurfaceEqualityOperators) {
0215   const double alpha = std::numbers::pi / 8.;
0216   const bool symmetric = false;
0217   const Translation3 translation{0., 1., 2.};
0218 
0219   auto pTransform = Transform3(translation);
0220   auto coneSurfaceObject =
0221       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0222 
0223   auto coneSurfaceObject2 =
0224       Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
0225 
0226   /// Test equality operator
0227   BOOST_CHECK(*coneSurfaceObject == *coneSurfaceObject2);
0228 
0229   BOOST_TEST_CHECKPOINT(
0230       "Create and then assign a ConeSurface object to the existing one");
0231   /// Test assignment
0232   auto assignedConeSurface =
0233       Surface::makeShared<ConeSurface>(Transform3::Identity(), 0.1, true);
0234   // TODO: surface copy-assignment is deprecated; switch to a makeShared copy
0235   // when it is removed (SonarCloud cpp:S3624).
0236   ACTS_PUSH_IGNORE_DEPRECATED()
0237   *assignedConeSurface = *coneSurfaceObject;
0238   ACTS_POP_IGNORE_DEPRECATED()
0239   /// Test equality of assigned to original
0240   BOOST_CHECK(*assignedConeSurface == *coneSurfaceObject);
0241 }
0242 
0243 BOOST_AUTO_TEST_CASE(ConeSurfaceExtent) {
0244   const double alpha = std::numbers::pi / 8.;
0245   const double halfPhiSector = std::numbers::pi / 8.;  // != pi/16
0246   const double zMin = 0.;                              // != 1.
0247   const double zMax = 10.;
0248   const Translation3 translation{0., 0., 0.};  // != {0., 1., 2.}
0249 
0250   /// Testing a Full cone
0251   auto pTransform = Transform3(translation);
0252   auto pConeBounds = std::make_shared<const ConeBounds>(alpha, zMin, zMax);
0253   auto pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
0254   auto pConeExtent = pCone->polyhedronRepresentation(tgContext, 1).extent();
0255 
0256   double rMax = zMax * std::tan(alpha);
0257   CHECK_CLOSE_ABS(zMin, pConeExtent.min(AxisDirection::AxisZ),
0258                   s_onSurfaceTolerance);
0259   CHECK_CLOSE_ABS(zMax, pConeExtent.max(AxisDirection::AxisZ),
0260                   s_onSurfaceTolerance);
0261   CHECK_CLOSE_ABS(0., pConeExtent.min(AxisDirection::AxisR),
0262                   s_onSurfaceTolerance);
0263   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisR),
0264                   s_onSurfaceTolerance);
0265   CHECK_CLOSE_ABS(-rMax, pConeExtent.min(AxisDirection::AxisX),
0266                   s_onSurfaceTolerance);
0267   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisX),
0268                   s_onSurfaceTolerance);
0269   CHECK_CLOSE_ABS(-rMax, pConeExtent.min(AxisDirection::AxisY),
0270                   s_onSurfaceTolerance);
0271   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisY),
0272                   s_onSurfaceTolerance);
0273 
0274   /// Now a sector
0275   pConeBounds =
0276       std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
0277   pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
0278   pConeExtent = pCone->polyhedronRepresentation(tgContext, 1).extent();
0279 
0280   CHECK_CLOSE_ABS(zMin, pConeExtent.min(AxisDirection::AxisZ),
0281                   s_onSurfaceTolerance);
0282   CHECK_CLOSE_ABS(zMax, pConeExtent.max(AxisDirection::AxisZ),
0283                   s_onSurfaceTolerance);
0284   CHECK_CLOSE_ABS(0., pConeExtent.min(AxisDirection::AxisR),
0285                   s_onSurfaceTolerance);
0286   CHECK_CLOSE_ABS(rMax, pConeExtent.max(AxisDirection::AxisR),
0287                   s_onSurfaceTolerance);
0288 }
0289 
0290 /// Unit test for testing ConeSurface alignment derivatives
0291 BOOST_AUTO_TEST_CASE(ConeSurfaceAlignment) {
0292   const double alpha = std::numbers::pi / 8.;
0293   const bool symmetric = false;
0294   const Translation3 translation{0., 1., 2.};
0295   // Rotate by 90 degrees about global z. The cone axis stays global z, so the
0296   // point below stays on the surface. The center columns are then the
0297   // local-frame components, not the global center derivative.
0298   const AngleAxis3 rotationAngle(std::numbers::pi / 2., Vector3::UnitZ());
0299   Transform3 transform =
0300       makeTransform3(rotationAngle.toRotationMatrix(), translation.vector());
0301   auto coneSurfaceObject =
0302       Surface::makeShared<ConeSurface>(transform, alpha, symmetric);
0303 
0304   const auto& rotation = transform.rotation();
0305   // The local frame z axis
0306   const Vector3 localZAxis = rotation.col(2);
0307   // Check the local z axis is aligned to global z axis
0308   CHECK_CLOSE_ABS(localZAxis, Vector3(0., 0., 1.), 1e-15);
0309 
0310   // On the cone, along the rotated local x axis. Local z is 1.
0311   Vector3 globalPosition{0, 1. + std::tan(alpha), 3};
0312 
0313   // Test the derivative of bound track parameters local position w.r.t.
0314   // position in local 3D Cartesian coordinates
0315   const auto& loc3DToLocBound =
0316       coneSurfaceObject->localCartesianToBoundLocalDerivative(
0317           tgContext, globalPosition, Vector3::UnitZ());
0318   // Local position is (tan(alpha), 0, 1), so local phi is 0.
0319   Matrix<2, 3> expLoc3DToLocBound = Matrix<2, 3>::Zero();
0320   expLoc3DToLocBound << 0, 1, 0, 0, 0, 1;
0321   CHECK_CLOSE_ABS(loc3DToLocBound, expLoc3DToLocBound, 1e-10);
0322 
0323   // Local hit (tan(alpha), 0, 1) and local direction (1, 0, 0). With
0324   // tau = tan^2(alpha) the local path derivative is (1, 0, -tan(alpha), 0,
0325   // 1 + tau, 0).
0326   const double tanAlpha = std::tan(alpha);
0327   const double tanAlpha2 = tanAlpha * tanAlpha;
0328   const Vector3 hit = transform * Vector3{tanAlpha, 0., 1.};
0329   const Vector3 direction = rotation * Vector3{1., 0., 0.};
0330   const AlignmentToPathMatrix alignToPath =
0331       coneSurfaceObject->alignmentToPathDerivative(tgContext, hit, direction);
0332   AlignmentToPathMatrix expected = AlignmentToPathMatrix::Zero();
0333   expected << 1., 0., -tanAlpha, 0., 1. + tanAlpha2, 0.;
0334   CHECK_CLOSE_ABS(alignToPath, expected, 1e-10);
0335 
0336   // A hit off the local x axis, checked against finite differences.
0337   const double z = 2.;
0338   const double phi = 0.4;
0339   const double radius = z * tanAlpha;
0340   const Vector3 skewedHit =
0341       transform * Vector3{radius * std::cos(phi), radius * std::sin(phi), z};
0342   const Vector3 skewedDir = rotation * Vector3{0.2, -0.3, 0.5};
0343   checkSurfaceDerivatives(tgContext, *coneSurfaceObject, transform, skewedHit,
0344                           skewedDir, [&](const Transform3& tf) {
0345                             return Surface::makeShared<ConeSurface>(tf, alpha,
0346                                                                     symmetric);
0347                           });
0348 }
0349 
0350 BOOST_AUTO_TEST_CASE(ConeSurfaceJacobianRoundTrip) {
0351   const double alpha = std::numbers::pi / 8.;
0352   const AngleAxis3 rotationAngle(std::numbers::pi / 2., Vector3::UnitZ());
0353   const Transform3 transform =
0354       makeTransform3(rotationAngle.toRotationMatrix(), Vector3(0., 1., 2.));
0355   auto cone = Surface::makeShared<ConeSurface>(transform, alpha, false);
0356 
0357   // Nonzero local phi, so d(global)/dz carries the phi*tan(alpha) term, on a
0358   // cone rotated away from the global axes.
0359   const double z = 1.7;
0360   const double localPhi = 0.6;
0361   const double radius = z * std::tan(alpha);
0362   const Vector2 local(radius * localPhi, z);
0363   const Vector3 direction = Vector3(0.25, -0.4, 0.88).normalized();
0364   const Vector3 position = cone->localToGlobal(tgContext, local, direction);
0365 
0366   const FreeToBoundMatrix freeToBound =
0367       cone->freeToBoundJacobian(tgContext, position, direction);
0368   const BoundToFreeMatrix boundToFree =
0369       cone->boundToFreeJacobian(tgContext, position, direction);
0370   CHECK_CLOSE_ABS(freeToBound * boundToFree, SquareMatrix<6>::Identity(),
0371                   1e-10);
0372 
0373   constexpr double step = 1e-6;
0374   const Vector3 du =
0375       (cone->localToGlobal(tgContext, local + Vector2(step, 0.), direction) -
0376        cone->localToGlobal(tgContext, local - Vector2(step, 0.), direction)) /
0377       (2. * step);
0378   const Vector3 dv =
0379       (cone->localToGlobal(tgContext, local + Vector2(0., step), direction) -
0380        cone->localToGlobal(tgContext, local - Vector2(0., step), direction)) /
0381       (2. * step);
0382   const Vector3 loc0Column = boundToFree.block<3, 1>(eFreePos0, eBoundLoc0);
0383   const Vector3 loc1Column = boundToFree.block<3, 1>(eFreePos0, eBoundLoc1);
0384   CHECK_CLOSE_ABS(loc0Column, du, 1e-8);
0385   CHECK_CLOSE_ABS(loc1Column, dv, 1e-8);
0386 }
0387 
0388 /// Full free-to-bound transport: perturb, intersect, globalToLocal.
0389 /// f2b * b2f == 1 does not see a wrong path derivative.
0390 BOOST_AUTO_TEST_CASE(ConeSurfaceFreeToBoundTransport) {
0391   const double alpha = std::numbers::pi / 8.;
0392   const AngleAxis3 tilt(0.4, Vector3::UnitX());
0393   const AngleAxis3 yaw(std::numbers::pi / 2., Vector3::UnitZ());
0394   const Transform3 transform =
0395       makeTransform3((tilt * yaw).toRotationMatrix(), Vector3(0., 1., 2.));
0396   auto cone = Surface::makeShared<ConeSurface>(transform, alpha, false);
0397 
0398   const double z = 1.7;
0399   const double localPhi = 0.6;
0400   const double radius = z * std::tan(alpha);
0401   const Vector2 local(radius * localPhi, z);
0402   const Vector3 direction = Vector3(0.25, -0.4, 0.88).normalized();
0403   const Vector3 position = cone->localToGlobal(tgContext, local, direction);
0404 
0405   const Vector3 surfaceNormal = cone->normal(tgContext, position);
0406   const RotationMatrix3 frame =
0407       cone->referenceFrame(tgContext, position, direction);
0408   CHECK_CLOSE_ABS(frame.col(2), surfaceNormal, 1e-12);
0409   CHECK_CLOSE_ABS(frame.col(1), surfaceNormal.cross(frame.col(0)), 1e-12);
0410 
0411   auto boundLocal = [&](const Vector3& pos, const Vector3& dir) {
0412     const auto hit = cone->intersect(tgContext, pos, dir).closest();
0413     BOOST_REQUIRE(hit.isValid());
0414     const auto onCone = cone->globalToLocal(tgContext, hit.position(), dir);
0415     BOOST_REQUIRE(onCone.ok());
0416     return onCone.value();
0417   };
0418 
0419   const FreeToBoundMatrix freeToBound =
0420       cone->freeToBoundJacobian(tgContext, position, direction);
0421   const FreeToPathMatrix freeToPath =
0422       cone->freeToPathDerivative(tgContext, position, direction);
0423   // Straight-line correction: the intersection moves along the direction.
0424   FreeVector correction = FreeVector::Zero();
0425   correction.segment<3>(eFreePos0) = direction;
0426   const FreeToBoundMatrix transport =
0427       freeToBound * (FreeMatrix::Identity() + correction * freeToPath);
0428 
0429   constexpr double step = 1e-6;
0430   for (int k = 0; k < 3; ++k) {
0431     Vector3 pp = position;
0432     Vector3 pm = position;
0433     pp[k] += step;
0434     pm[k] -= step;
0435     const Vector2 numeric =
0436         (boundLocal(pp, direction) - boundLocal(pm, direction)) / (2. * step);
0437     const Vector2 analytic = transport.block<2, 1>(eBoundLoc0, eFreePos0 + k);
0438     CHECK_CLOSE_ABS(numeric, analytic, 1e-6);
0439   }
0440   for (int k = 0; k < 3; ++k) {
0441     Vector3 dp = direction;
0442     Vector3 dm = direction;
0443     dp[k] += step;
0444     dm[k] -= step;
0445     const Vector2 numeric =
0446         (boundLocal(position, dp) - boundLocal(position, dm)) / (2. * step);
0447     const Vector2 analytic = transport.block<2, 1>(eBoundLoc0, eFreeDir0 + k);
0448     CHECK_CLOSE_ABS(numeric, analytic, 1e-6);
0449   }
0450 }
0451 
0452 BOOST_AUTO_TEST_CASE(ConeSurfaceMaterialAssignment) {
0453   const double alpha = 0.3;
0454   auto surface = Surface::makeShared<ConeSurface>(Transform3::Identity(), alpha,
0455                                                   true /*symmetric*/);
0456   MaterialSlab slab(Material::fromMolarDensity(1., 2., 3., 4., 5.), 0.1);
0457 
0458   // HomogeneousSurfaceMaterial is always valid
0459   auto homMat = std::make_shared<HomogeneousSurfaceMaterial>(slab);
0460   BOOST_CHECK_NO_THROW(surface->assignSurfaceMaterial(homMat));
0461   BOOST_CHECK_NE(surface->surfaceMaterial(), nullptr);
0462 
0463   // nullptr clears the material
0464   BOOST_CHECK_NO_THROW(surface->assignSurfaceMaterial(nullptr));
0465   BOOST_CHECK_EQUAL(surface->surfaceMaterial(), nullptr);
0466 
0467   // 1D AxisZ - valid for cone
0468   BinUtility buZ(10, -100.f, 100.f, Acts::open, AxisDirection::AxisZ);
0469   auto matZ = std::make_shared<BinnedSurfaceMaterial>(
0470       buZ, MaterialSlabVector(10, slab));
0471   BOOST_CHECK_NO_THROW(surface->assignSurfaceMaterial(matZ));
0472 
0473   // Wrong axis directions - should throw
0474   for (auto badDir : {AxisDirection::AxisR, AxisDirection::AxisPhi,
0475                       AxisDirection::AxisX, AxisDirection::AxisY}) {
0476     BinUtility buBad(10, 0.f, 10.f, Acts::open, badDir);
0477     auto matBad = std::make_shared<BinnedSurfaceMaterial>(
0478         buBad, MaterialSlabVector(10, slab));
0479     BOOST_CHECK_THROW(surface->assignSurfaceMaterial(matBad),
0480                       std::invalid_argument);
0481   }
0482 }
0483 
0484 /// A cone whose half sector is pi only up to rounding is still a full cone
0485 BOOST_AUTO_TEST_CASE(ConeSurfaceFullConeTolerance) {
0486   const double alpha = std::numbers::pi / 8.;
0487   auto pTransform = Transform3(Translation3{0., 0., 0.});
0488 
0489   // An average phi off the regular vertex grid, so that forcing it in as a
0490   // reference vertex would be visible in the vertex count
0491   const double avgPhi = 0.1;
0492   auto exact = Surface::makeShared<ConeSurface>(
0493       pTransform, std::make_shared<const ConeBounds>(alpha, 0., 10.,
0494                                                      std::numbers::pi, avgPhi));
0495   auto rounded = Surface::makeShared<ConeSurface>(
0496       pTransform, std::make_shared<const ConeBounds>(
0497                       alpha, 0., 10., std::numbers::pi - 1e-12, avgPhi));
0498 
0499   // Neither forces the average phi in as an extra reference vertex
0500   BOOST_CHECK_EQUAL(
0501       exact->polyhedronRepresentation(tgContext, 1).vertices.size(),
0502       rounded->polyhedronRepresentation(tgContext, 1).vertices.size());
0503 }
0504 
0505 BOOST_AUTO_TEST_SUITE_END()
0506 }  // namespace ActsTests