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