File indexing completed on 2025-09-12 08:14:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/PlaneLayer.hpp"
0014 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0015 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0016 #include "Acts/Surfaces/PlaneSurface.hpp"
0017 #include "Acts/Surfaces/RectangleBounds.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Surfaces/SurfaceArray.hpp"
0020 #include "Acts/Tests/CommonHelpers/DetectorElementStub.hpp"
0021 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0022 #include "Acts/Tests/CommonHelpers/PredefinedMaterials.hpp"
0023
0024 #include <memory>
0025
0026 #include "SurfaceStub.hpp"
0027
0028 namespace Acts {
0029
0030 class MockTrack {
0031 public:
0032 MockTrack(const Vector3& mom, const Vector3& pos) : m_mom(mom), m_pos(pos) {
0033
0034 }
0035
0036 Vector3 momentum() const { return m_mom; }
0037
0038 Vector3 position() const { return m_pos; }
0039
0040 private:
0041 Vector3 m_mom;
0042 Vector3 m_pos;
0043 };
0044 }
0045
0046 namespace Acts::Test {
0047
0048
0049 GeometryContext tgContext = GeometryContext();
0050
0051 BOOST_AUTO_TEST_SUITE(Surfaces)
0052
0053
0054
0055
0056 BOOST_AUTO_TEST_CASE(SurfaceConstruction) {
0057
0058 BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub().type());
0059 SurfaceStub original;
0060 BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(original).type());
0061 Translation3 translation{0., 1., 2.};
0062 Transform3 transform(translation);
0063 BOOST_CHECK_EQUAL(Surface::Other,
0064 SurfaceStub(tgContext, original, transform).type());
0065
0066 auto pTransform = Transform3(translation);
0067 std::shared_ptr<const Acts::PlanarBounds> p =
0068 std::make_shared<const RectangleBounds>(5., 10.);
0069 DetectorElementStub detElement{pTransform, p, 0.2, nullptr};
0070 BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(detElement).type());
0071 }
0072
0073
0074 BOOST_AUTO_TEST_CASE(SurfaceProperties) {
0075
0076 std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
0077 std::make_shared<const RectangleBounds>(5., 10.);
0078 Vector3 reference{0., 1., 2.};
0079 Translation3 translation{0., 1., 2.};
0080 auto pTransform = Transform3(translation);
0081 auto pLayer = PlaneLayer::create(pTransform, pPlanarBound);
0082 auto pMaterial =
0083 std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0084 DetectorElementStub detElement{pTransform, pPlanarBound, 0.2, pMaterial};
0085 SurfaceStub surface(detElement);
0086
0087
0088 BOOST_CHECK_EQUAL(surface.associatedDetectorElement(), &detElement);
0089
0090
0091 surface.associateLayer(*pLayer);
0092 BOOST_CHECK_EQUAL(surface.associatedLayer(), pLayer.get());
0093
0094
0095
0096 BOOST_CHECK_NE(surface.surfaceMaterial(), pMaterial.get());
0097
0098
0099 CHECK_CLOSE_OR_SMALL(reference, surface.center(tgContext), 1e-6, 1e-9);
0100
0101
0102 Vector2 localPosition{0.1, 3.};
0103 BOOST_CHECK(surface.insideBounds(localPosition));
0104 Vector2 outside{20., 20.};
0105 BOOST_CHECK(surface.insideBounds(
0106 outside));
0107
0108 Vector3 mom{100., 200., 300.};
0109
0110
0111 BOOST_CHECK(surface.isOnSurface(tgContext, reference, mom,
0112 BoundaryTolerance::Infinite()));
0113 BOOST_CHECK(surface.isOnSurface(
0114 tgContext, reference, mom,
0115 BoundaryTolerance::None()));
0116
0117
0118 RotationMatrix3 unitary;
0119 unitary << 1, 0, 0, 0, 1, 0, 0, 0, 1;
0120 auto referenceFrame =
0121 surface.referenceFrame(tgContext, Vector3{1, 2, 3}.normalized(), mom);
0122 BOOST_CHECK_EQUAL(referenceFrame, unitary);
0123
0124
0125 auto normal = surface.normal(tgContext, Vector3{1, 2, 3}.normalized(),
0126 Vector3::UnitZ());
0127 Vector3 zero{0., 0., 0.};
0128 BOOST_CHECK_EQUAL(zero, normal);
0129
0130
0131
0132
0133 auto pNewMaterial =
0134 std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0135 surface.assignSurfaceMaterial(pNewMaterial);
0136 BOOST_CHECK_EQUAL(surface.surfaceMaterial(), pNewMaterial.get());
0137
0138 CHECK_CLOSE_OR_SMALL(surface.transform(tgContext), pTransform, 1e-6, 1e-9);
0139
0140
0141 }
0142
0143 BOOST_AUTO_TEST_CASE(EqualityOperators) {
0144
0145 std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
0146 std::make_shared<const RectangleBounds>(5., 10.);
0147 Vector3 reference{0., 1., 2.};
0148 Translation3 translation1{0., 1., 2.};
0149 Translation3 translation2{1., 1., 2.};
0150 auto pTransform1 = Transform3(translation1);
0151 auto pTransform2 = Transform3(translation2);
0152
0153
0154 auto planeSurface =
0155 Surface::makeShared<PlaneSurface>(pTransform1, pPlanarBound);
0156 auto pLayer = PlaneLayer::create(pTransform1, pPlanarBound);
0157 auto pMaterial =
0158 std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0159 DetectorElementStub detElement1{pTransform1, pPlanarBound, 0.2, pMaterial};
0160 DetectorElementStub detElement2{pTransform1, pPlanarBound, 0.3, pMaterial};
0161 DetectorElementStub detElement3{pTransform2, pPlanarBound, 0.3, pMaterial};
0162
0163 SurfaceStub surface1(detElement1);
0164 SurfaceStub surface2(detElement1);
0165 SurfaceStub surface3(detElement2);
0166 SurfaceStub surface4(detElement3);
0167 SurfaceStub surface5(detElement1);
0168 surface5.assignSurfaceMaterial(pMaterial);
0169
0170 BOOST_CHECK(surface1 == surface2);
0171 BOOST_CHECK(surface1 != surface3);
0172 BOOST_CHECK(surface1 != surface4);
0173 BOOST_CHECK(surface1 != surface5);
0174 BOOST_CHECK(surface1 != *planeSurface);
0175
0176
0177 const auto surfacePtr = Surface::makeShared<const SurfaceStub>(detElement1);
0178 const auto sharedSurfacePtr = surfacePtr->getSharedPtr();
0179 BOOST_CHECK(*surfacePtr == *sharedSurfacePtr);
0180 }
0181 BOOST_AUTO_TEST_SUITE_END()
0182
0183 }