Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2020 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/Definitions/Tolerance.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/Geometry/GenericApproachDescriptor.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Geometry/Layer.hpp"
0018 #include "Acts/Surfaces/BoundaryCheck.hpp"
0019 #include "Acts/Surfaces/CylinderSurface.hpp"
0020 #include "Acts/Surfaces/Surface.hpp"
0021 #include "Acts/Surfaces/SurfaceArray.hpp"
0022 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0023 #include "Acts/Utilities/Intersection.hpp"
0024 
0025 #include <cstddef>
0026 #include <limits>
0027 #include <memory>
0028 #include <vector>
0029 
0030 #include "../Surfaces/SurfaceStub.hpp"
0031 #include "LayerStub.hpp"
0032 
0033 namespace Acts::Test::Layers {
0034 
0035 // Build a default context for testing
0036 GeometryContext tgContext = GeometryContext();
0037 
0038 BOOST_AUTO_TEST_SUITE(Layers)
0039 
0040 /// Unit test for creating compliant/non-compliant GenericApproachDescriptor
0041 /// object
0042 BOOST_AUTO_TEST_CASE(GenericApproachDescriptorConstruction) {
0043   std::vector<std::shared_ptr<const Surface>> someSurfaces{
0044       Surface::makeShared<SurfaceStub>(), Surface::makeShared<SurfaceStub>()};
0045   BOOST_CHECK_NO_THROW(
0046       GenericApproachDescriptor minimallyConstructedApproachDescriptor(
0047           someSurfaces));
0048   //
0049   std::vector<std::shared_ptr<const Layer>> sharedLayers{
0050       std::make_shared<LayerStub>(nullptr),
0051       std::make_shared<LayerStub>(nullptr)};
0052   BOOST_CHECK_NO_THROW(GenericApproachDescriptor sharedLayerApproachDescriptor(
0053       {sharedLayers.at(0)->surfaceRepresentation().getSharedPtr(),
0054        sharedLayers.at(1)->surfaceRepresentation().getSharedPtr()}));
0055 }
0056 
0057 /// Unit test for testing GenericApproachDescriptor properties
0058 BOOST_AUTO_TEST_CASE(GenericApproachDescriptorProperties) {
0059   Vector3 origin{
0060       0.,
0061       0.,
0062       0.,
0063   };
0064   Vector3 zDir{0., 0., 1.};
0065   BoundaryCheck bcheck{true};
0066   double nearLimit = -100 * UnitConstants::um;
0067   double farLimit = std::numeric_limits<double>::max();
0068   //
0069   std::vector<std::shared_ptr<const Surface>> someSurfaces{
0070       Surface::makeShared<SurfaceStub>(), Surface::makeShared<SurfaceStub>()};
0071   GenericApproachDescriptor approachDescriptor(someSurfaces);
0072   LayerStub aLayer(nullptr);
0073   // registerLayer()
0074   BOOST_CHECK_NO_THROW(approachDescriptor.registerLayer(aLayer));
0075   // approachSurface
0076   SurfaceIntersection surfIntersection = approachDescriptor.approachSurface(
0077       tgContext, origin, zDir, bcheck, nearLimit, farLimit);
0078   double expectedIntersection = 20.0;  // property of SurfaceStub
0079   CHECK_CLOSE_REL(surfIntersection.pathLength(), expectedIntersection, 1e-6);
0080   // containedSurfaces()
0081   BOOST_CHECK_EQUAL(approachDescriptor.containedSurfaces().size(),
0082                     someSurfaces.size());
0083 
0084   for (std::size_t i = 0; i < someSurfaces.size(); i++) {
0085     BOOST_CHECK_EQUAL(approachDescriptor.containedSurfaces().at(i),
0086                       someSurfaces.at(i).get());
0087   }
0088 }
0089 
0090 /// Unit test for testing GenericApproachDescriptor overstepping
0091 /// - for the approach estimate, there is no overstepping tolerance
0092 /// allowed
0093 BOOST_AUTO_TEST_CASE(GenericApproachNoOverstepping) {
0094   Vector3 origin{0., -0.5, 1.};
0095   Vector3 direction{0., 1., 0.};
0096   BoundaryCheck bcheck{true};
0097   double nearLimit = -100 * UnitConstants::um;
0098   double farLimit = std::numeric_limits<double>::max();
0099 
0100   auto conCyl =
0101       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 10., 20.);
0102 
0103   std::vector<std::shared_ptr<const Surface>> approachSurface = {conCyl};
0104 
0105   GenericApproachDescriptor gad(approachSurface);
0106 
0107   auto sfIntersection = gad.approachSurface(
0108       GeometryContext(), origin, direction, bcheck, nearLimit, farLimit);
0109 
0110   // No overstepping allowed, the preferred solution should be the forward one
0111   CHECK_CLOSE_ABS(sfIntersection.pathLength(), 10.5, s_epsilon);
0112   CHECK_CLOSE_ABS(sfIntersection.position().x(), 0., s_epsilon);
0113   CHECK_CLOSE_ABS(sfIntersection.position().y(), 10., s_epsilon);
0114   CHECK_CLOSE_ABS(sfIntersection.position().z(), 1., s_epsilon);
0115 }
0116 
0117 BOOST_AUTO_TEST_SUITE_END()
0118 }  // namespace Acts::Test::Layers