Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:12

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/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 "ActsTests/CommonHelpers/DetectorElementStub.hpp"
0021 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0022 #include "ActsTests/CommonHelpers/PredefinedMaterials.hpp"
0023 
0024 #include <memory>
0025 
0026 #include "SurfaceStub.hpp"
0027 
0028 namespace Acts {
0029 /// Mock track object with minimal methods implemented for compilation
0030 class MockTrack {
0031  public:
0032   MockTrack(const Vector3& mom, const Vector3& pos) : m_mom(mom), m_pos(pos) {
0033     // nop
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 }  // namespace Acts
0045 
0046 using namespace Acts;
0047 
0048 namespace ActsTests {
0049 
0050 // Create a test context
0051 GeometryContext tgContext = GeometryContext();
0052 
0053 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0054 
0055 /// todo: make test fixture; separate out different cases
0056 
0057 /// Unit test for creating compliant/non-compliant Surface object
0058 BOOST_AUTO_TEST_CASE(SurfaceConstruction) {
0059   // SurfaceStub s;
0060   BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub().type());
0061   SurfaceStub original;
0062   BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(original).type());
0063   Translation3 translation{0., 1., 2.};
0064   Transform3 transform(translation);
0065   BOOST_CHECK_EQUAL(Surface::Other,
0066                     SurfaceStub(tgContext, original, transform).type());
0067   // need some cruft to make the next one work
0068   auto pTransform = Transform3(translation);
0069   std::shared_ptr<const Acts::PlanarBounds> p =
0070       std::make_shared<const RectangleBounds>(5., 10.);
0071   DetectorElementStub detElement{pTransform, p, 0.2, nullptr};
0072   BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(detElement).type());
0073 }
0074 
0075 /// Unit test for testing Surface properties
0076 BOOST_AUTO_TEST_CASE(SurfaceProperties) {
0077   // build a test object , 'surface'
0078   std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
0079       std::make_shared<const RectangleBounds>(5., 10.);
0080   Vector3 reference{0., 1., 2.};
0081   Translation3 translation{0., 1., 2.};
0082   auto pTransform = Transform3(translation);
0083   auto pLayer = PlaneLayer::create(pTransform, pPlanarBound);
0084   auto pMaterial =
0085       std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0086   DetectorElementStub detElement{pTransform, pPlanarBound, 0.2, pMaterial};
0087   SurfaceStub surface(detElement);
0088 
0089   // associatedDetectorElement
0090   BOOST_CHECK_EQUAL(surface.associatedDetectorElement(), &detElement);
0091 
0092   // test associatelayer, associatedLayer
0093   surface.associateLayer(*pLayer);
0094   BOOST_CHECK_EQUAL(surface.associatedLayer(), pLayer.get());
0095 
0096   // associated Material is not set to the surface
0097   // it is set to the detector element surface though
0098   BOOST_CHECK_NE(surface.surfaceMaterial(), pMaterial.get());
0099 
0100   // center()
0101   CHECK_CLOSE_OR_SMALL(reference, surface.center(tgContext), 1e-6, 1e-9);
0102 
0103   // insideBounds
0104   Vector2 localPosition{0.1, 3.};
0105   BOOST_CHECK(surface.insideBounds(localPosition));
0106   Vector2 outside{20., 20.};
0107   BOOST_CHECK(surface.insideBounds(
0108       outside));  // should return false, but doesn't because SurfaceStub has
0109                   // "no bounds" hard-coded
0110   Vector3 mom{100., 200., 300.};
0111 
0112   // isOnSurface
0113   BOOST_CHECK(surface.isOnSurface(tgContext, reference, mom,
0114                                   BoundaryTolerance::Infinite()));
0115   BOOST_CHECK(surface.isOnSurface(
0116       tgContext, reference, mom,
0117       BoundaryTolerance::None()));  // need to improve bounds()
0118 
0119   // referenceFrame()
0120   RotationMatrix3 unitary;
0121   unitary << 1, 0, 0, 0, 1, 0, 0, 0, 1;
0122   auto referenceFrame =
0123       surface.referenceFrame(tgContext, Vector3{1, 2, 3}.normalized(), mom);
0124   BOOST_CHECK_EQUAL(referenceFrame, unitary);
0125 
0126   // normal()
0127   auto normal = surface.normal(tgContext, Vector3{1, 2, 3}.normalized(),
0128                                Vector3::UnitZ());
0129   Vector3 zero{0., 0., 0.};
0130   BOOST_CHECK_EQUAL(zero, normal);
0131 
0132   // pathCorrection is pure virtual
0133 
0134   // surfaceMaterial()
0135   auto pNewMaterial =
0136       std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0137   surface.assignSurfaceMaterial(pNewMaterial);
0138   BOOST_CHECK_EQUAL(surface.surfaceMaterial(), pNewMaterial.get());
0139 
0140   CHECK_CLOSE_OR_SMALL(surface.transform(tgContext), pTransform, 1e-6, 1e-9);
0141 
0142   // type() is pure virtual
0143 }
0144 
0145 BOOST_AUTO_TEST_CASE(EqualityOperators) {
0146   // build some test objects
0147   std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
0148       std::make_shared<const RectangleBounds>(5., 10.);
0149   Vector3 reference{0., 1., 2.};
0150   Translation3 translation1{0., 1., 2.};
0151   Translation3 translation2{1., 1., 2.};
0152   auto pTransform1 = Transform3(translation1);
0153   auto pTransform2 = Transform3(translation2);
0154 
0155   // build a planeSurface to be compared
0156   auto planeSurface =
0157       Surface::makeShared<PlaneSurface>(pTransform1, pPlanarBound);
0158   auto pLayer = PlaneLayer::create(pTransform1, pPlanarBound);
0159   auto pMaterial =
0160       std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0161   DetectorElementStub detElement1{pTransform1, pPlanarBound, 0.2, pMaterial};
0162   DetectorElementStub detElement2{pTransform1, pPlanarBound, 0.3, pMaterial};
0163   DetectorElementStub detElement3{pTransform2, pPlanarBound, 0.3, pMaterial};
0164 
0165   SurfaceStub surface1(detElement1);
0166   SurfaceStub surface2(detElement1);  // 1 and 2 are the same
0167   SurfaceStub surface3(detElement2);  // 3 differs in thickness
0168   SurfaceStub surface4(detElement3);  // 4 has a different transform and id
0169   SurfaceStub surface5(detElement1);
0170   surface5.assignSurfaceMaterial(pMaterial);  // 5 has non-null surface material
0171 
0172   BOOST_CHECK(surface1 == surface2);
0173   BOOST_CHECK(surface1 != surface3);
0174   BOOST_CHECK(surface1 != surface4);
0175   BOOST_CHECK(surface1 != surface5);
0176   BOOST_CHECK(surface1 != *planeSurface);
0177 
0178   // Test the getSharedPtr
0179   const auto surfacePtr = Surface::makeShared<const SurfaceStub>(detElement1);
0180   const auto sharedSurfacePtr = surfacePtr->getSharedPtr();
0181   BOOST_CHECK(*surfacePtr == *sharedSurfacePtr);
0182 }
0183 BOOST_AUTO_TEST_SUITE_END()
0184 
0185 }  // namespace ActsTests