Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:29

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2018 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 http://mozilla.org/MPL/2.0/.
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 /// 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 
0044 namespace Test {
0045 
0046 // Create a test context
0047 GeometryContext tgContext = GeometryContext();
0048 
0049 BOOST_AUTO_TEST_SUITE(Surfaces)
0050 
0051 /// todo: make test fixture; separate out different cases
0052 
0053 /// Unit test for creating compliant/non-compliant Surface object
0054 BOOST_AUTO_TEST_CASE(SurfaceConstruction) {
0055   // SurfaceStub s;
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   // need some cruft to make the next one work
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 /// Unit test for testing Surface properties
0072 BOOST_AUTO_TEST_CASE(SurfaceProperties) {
0073   // build a test object , 'surface'
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   // associatedDetectorElement
0085   BOOST_CHECK_EQUAL(surface.associatedDetectorElement(), &detElement);
0086   // test  associatelayer, associatedLayer
0087   surface.associateLayer(*pLayer);
0088   BOOST_CHECK_EQUAL(surface.associatedLayer(), pLayer.get());
0089   // associated Material is not set to the surface
0090   // it is set to the detector element surface though
0091   BOOST_CHECK_NE(surface.surfaceMaterial(), pMaterial.get());
0092   // center()
0093   CHECK_CLOSE_OR_SMALL(reference, surface.center(tgContext), 1e-6, 1e-9);
0094   // insideBounds
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));  // should return false, but doesn't because SurfaceStub has
0100                   // "no bounds" hard-coded
0101   Vector3 mom{100., 200., 300.};
0102   // isOnSurface
0103   BOOST_CHECK(
0104       surface.isOnSurface(tgContext, reference, mom, BoundaryCheck(false)));
0105   BOOST_CHECK(
0106       surface.isOnSurface(tgContext, reference, mom,
0107                           BoundaryCheck(true)));  // need to improve bounds()
0108   // referenceFrame()
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);  // need more complex case to test
0114   BOOST_CHECK_EQUAL(referenceFrame, unitary);
0115   // normal()
0116   auto normal = surface.normal(tgContext, Vector3{1, 2, 3}.normalized(),
0117                                Vector3::UnitZ());  // needs more
0118                                                    // complex test
0119   Vector3 zero{0., 0., 0.};
0120   BOOST_CHECK_EQUAL(zero, normal);
0121   // pathCorrection is pure virtual
0122   // surfaceMaterial()
0123   auto pNewMaterial =
0124       std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
0125   surface.assignSurfaceMaterial(pNewMaterial);
0126   BOOST_CHECK_EQUAL(surface.surfaceMaterial(),
0127                     pNewMaterial.get());  // passes ??
0128   //
0129   CHECK_CLOSE_OR_SMALL(surface.transform(tgContext), pTransform, 1e-6, 1e-9);
0130   // type() is pure virtual
0131 }
0132 
0133 BOOST_AUTO_TEST_CASE(EqualityOperators) {
0134   // build some test objects
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   // build a planeSurface to be compared
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);  // 1 and 2 are the same
0154   SurfaceStub surface3(detElement2);  // 3 differs in thickness
0155   SurfaceStub surface4(detElement3);  // 4 has a different transform and id
0156   SurfaceStub surface5(detElement1);
0157   surface5.assignSurfaceMaterial(pMaterial);  // 5 has non-null surface material
0158   //
0159   BOOST_CHECK(surface1 == surface2);
0160   //
0161   // remove test for the moment,
0162   // surfaces do not have a concept of thickness (only detector elements have)
0163   // only thickness is different here
0164   //
0165   // BOOST_CHECK_NE(surface1, surface3);  // will fail
0166   //
0167   BOOST_CHECK(surface1 != surface4);
0168   //
0169   BOOST_CHECK(surface1 != surface5);
0170   //
0171   BOOST_CHECK(surface1 != *planeSurface);
0172   // Test the getSharedPtr
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 }  // namespace Test
0179 }  // namespace Acts