Back to home page

sPhenix code displayed by LXR

 
 

    


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

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 // clang-format off
0010 #include <boost/test/unit_test.hpp>
0011 #include <boost/test/data/test_case.hpp>
0012 #include <boost/test/tools/output_test_stream.hpp>
0013 #include <algorithm>
0014 #include <array>
0015 #include <stdexcept>
0016 #include <vector>
0017 // clang-format on
0018 
0019 #include "Acts/Definitions/Algebra.hpp"
0020 #include "Acts/Surfaces/AnnulusBounds.hpp"
0021 #include "Acts/Surfaces/BoundaryCheck.hpp"
0022 #include "Acts/Surfaces/SurfaceBounds.hpp"
0023 #include "Acts/Utilities/VectorHelpers.hpp"
0024 
0025 namespace Acts {
0026 
0027 namespace Test {
0028 BOOST_AUTO_TEST_SUITE(Surfaces)
0029 
0030 double minRadius = 7.2;
0031 double maxRadius = 12.0;
0032 double minPhi = 0.74195;
0033 double maxPhi = 1.33970;
0034 
0035 Vector2 offset(-2., 2.);
0036 
0037 // Unit tests for AnnulusBounds constructors
0038 BOOST_AUTO_TEST_CASE(AnnulusBoundsConstruction) {
0039   // Test construction with radii and default sector
0040   auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0041   AnnulusBounds copied(original);
0042   BOOST_CHECK_EQUAL(original, copied);
0043 }
0044 
0045 // Unit tests for AnnulusBounds recreation
0046 BOOST_AUTO_TEST_CASE(AnnulusBoundsRecreation) {
0047   // Test construction with radii and default sector
0048   auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0049   auto valvector = original.values();
0050   std::array<double, AnnulusBounds::eSize> values{};
0051   std::copy_n(valvector.begin(), AnnulusBounds::eSize, values.begin());
0052   AnnulusBounds recreated(values);
0053   BOOST_CHECK_EQUAL(original, recreated);
0054 }
0055 
0056 // Unit tests for AnnulusBounds exception throwing
0057 BOOST_AUTO_TEST_CASE(AnnulusBoundsExcpetion) {
0058   // Exception for negative inner radius
0059   BOOST_CHECK_THROW(AnnulusBounds(-1., maxRadius, minPhi, maxPhi, offset),
0060                     std::logic_error);
0061   // Exception for negative outer radius
0062   BOOST_CHECK_THROW(AnnulusBounds(minRadius, -1., minPhi, maxPhi, offset),
0063                     std::logic_error);
0064   // Exception for swapped radii
0065   BOOST_CHECK_THROW(AnnulusBounds(maxRadius, minRadius, minPhi, maxPhi, offset),
0066                     std::logic_error);
0067   // Exception for out of range  min phi
0068   BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, -4., maxPhi, offset),
0069                     std::logic_error);
0070   // Exception for out of range  max phi
0071   BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, minPhi, 4., offset),
0072                     std::logic_error);
0073   // Exception for out of range  max phi
0074   BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, maxPhi, minPhi, offset),
0075                     std::logic_error);
0076 }
0077 
0078 /// Unit tests for AnnulusBounds properties
0079 BOOST_AUTO_TEST_CASE(AnnulusBoundsProperties) {
0080   /// Test construction with radii and default sector
0081   AnnulusBounds aBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0082 
0083   //
0084   /// Test type() (redundant; already used in constructor confirmation)
0085   BOOST_CHECK_EQUAL(aBounds.type(), SurfaceBounds::eAnnulus);
0086 
0087   /// Test positions inside/outside
0088   // - start from cartesian (from test drawing)
0089   Vector2 inSurfaceXY(7., 7.);
0090   Vector2 outsideXY1(5., 5.);
0091   Vector2 outsideXY2(10., 3.);
0092   Vector2 outsideXY3(10., 10.);
0093   Vector2 outsideXY4(4., 10.);
0094   std::vector<Vector2> testPoints = {inSurfaceXY, outsideXY1, outsideXY2,
0095                                      outsideXY3, outsideXY4};
0096 
0097   auto toStripFrame = [&](const Vector2& xy) -> Vector2 {
0098     auto shifted = xy + offset;
0099     double r = VectorHelpers::perp(shifted);
0100     double phi = VectorHelpers::phi(shifted);
0101     return Vector2(r, phi);
0102   };
0103 
0104   BOOST_CHECK(aBounds.inside(toStripFrame(inSurfaceXY), BoundaryCheck(true)));
0105   BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY1), BoundaryCheck(true)));
0106   BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY2), BoundaryCheck(true)));
0107   BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY3), BoundaryCheck(true)));
0108   BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY4), BoundaryCheck(true)));
0109 
0110   // Check radial inside
0111   BOOST_CHECK(!aBounds.insideRadialBounds(0.5));
0112   BOOST_CHECK(aBounds.insideRadialBounds(9.));
0113   BOOST_CHECK(!aBounds.insideRadialBounds(18.));
0114 
0115   // Test rMin
0116   BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMinR), minRadius);
0117   // Test rMax
0118   BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMaxR), maxRadius);
0119   // Test phiMin
0120   BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMinPhiRel), minPhi);
0121   // Test phiMax
0122   BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMaxPhiRel), maxPhi);
0123 }
0124 
0125 BOOST_AUTO_TEST_SUITE_END()
0126 
0127 }  // namespace Test
0128 
0129 }  // namespace Acts