Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:53

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