Back to home page

EIC code displayed by LXR

 
 

    


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

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/Surfaces/AnnulusBounds.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "Acts/Utilities/VectorHelpers.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <stdexcept>
0020 #include <vector>
0021 
0022 namespace Acts::Test {
0023 
0024 BOOST_AUTO_TEST_SUITE(Surfaces)
0025 
0026 const double minRadius = 7.2;
0027 const double maxRadius = 12.0;
0028 const double minPhi = 0.74195;
0029 const double maxPhi = 1.33970;
0030 
0031 const Vector2 offset(-2., 2.);
0032 
0033 // Unit tests for AnnulusBounds constructors
0034 BOOST_AUTO_TEST_CASE(AnnulusBoundsConstruction) {
0035   // Test construction with radii and default sector
0036   auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0037   AnnulusBounds copied(original);
0038   BOOST_CHECK_EQUAL(original, copied);
0039 }
0040 
0041 // Unit tests for AnnulusBounds recreation
0042 BOOST_AUTO_TEST_CASE(AnnulusBoundsRecreation) {
0043   // Test construction with radii and default sector
0044   auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0045   auto valvector = original.values();
0046   std::array<double, AnnulusBounds::eSize> values{};
0047   std::copy_n(valvector.begin(), AnnulusBounds::eSize, values.begin());
0048   AnnulusBounds recreated(values);
0049   BOOST_CHECK_EQUAL(original, recreated);
0050 }
0051 
0052 // Unit tests for AnnulusBounds exception throwing
0053 BOOST_AUTO_TEST_CASE(AnnulusBoundsExcpetion) {
0054   // Exception for negative inner radius
0055   BOOST_CHECK_THROW(AnnulusBounds(-1., maxRadius, minPhi, maxPhi, offset),
0056                     std::logic_error);
0057   // Exception for negative outer radius
0058   BOOST_CHECK_THROW(AnnulusBounds(minRadius, -1., minPhi, maxPhi, offset),
0059                     std::logic_error);
0060   // Exception for swapped radii
0061   BOOST_CHECK_THROW(AnnulusBounds(maxRadius, minRadius, minPhi, maxPhi, offset),
0062                     std::logic_error);
0063   // Exception for out of range min phi
0064   BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, -4., maxPhi, offset),
0065                     std::logic_error);
0066   // Exception for out of range max phi
0067   BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, minPhi, 4., offset),
0068                     std::logic_error);
0069   // Exception for out of range max phi
0070   BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, maxPhi, minPhi, offset),
0071                     std::logic_error);
0072 }
0073 
0074 /// Unit tests for AnnulusBounds properties
0075 BOOST_AUTO_TEST_CASE(AnnulusBoundsProperties) {
0076   /// Test construction with radii and default sector
0077   AnnulusBounds aBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0078 
0079   /// Test type() (redundant; already used in constructor confirmation)
0080   BOOST_CHECK_EQUAL(aBounds.type(), SurfaceBounds::eAnnulus);
0081 
0082   /// Test positions inside/outside
0083   // - start from cartesian (from test drawing)
0084   Vector2 inSurfaceXY(7., 7.);
0085   Vector2 outsideXY1(5., 5.);
0086   Vector2 outsideXY2(10., 3.);
0087   Vector2 outsideXY3(10., 10.);
0088   Vector2 outsideXY4(4., 10.);
0089   std::vector<Vector2> testPoints = {inSurfaceXY, outsideXY1, outsideXY2,
0090                                      outsideXY3, outsideXY4};
0091 
0092   auto toStripFrame = [&](const Vector2& xy) -> Vector2 {
0093     auto shifted = xy + offset;
0094     double r = VectorHelpers::perp(shifted);
0095     double phi = VectorHelpers::phi(shifted);
0096     return Vector2(r, phi);
0097   };
0098 
0099   BOOST_CHECK(
0100       aBounds.inside(toStripFrame(inSurfaceXY), BoundaryTolerance::None()));
0101   BOOST_CHECK(
0102       !aBounds.inside(toStripFrame(outsideXY1), BoundaryTolerance::None()));
0103   BOOST_CHECK(
0104       !aBounds.inside(toStripFrame(outsideXY2), BoundaryTolerance::None()));
0105   BOOST_CHECK(
0106       !aBounds.inside(toStripFrame(outsideXY3), BoundaryTolerance::None()));
0107   BOOST_CHECK(
0108       !aBounds.inside(toStripFrame(outsideXY4), BoundaryTolerance::None()));
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 /// Unit tests for AnnulusBounds vertices
0126 BOOST_AUTO_TEST_CASE(AnnulusBoundsVertices) {
0127   /// Test construction with radii and default sector
0128   AnnulusBounds aBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0129 
0130   // Retrieve the corners
0131   auto corners = aBounds.corners();
0132   BOOST_CHECK_EQUAL(corners.size(), 4);
0133 
0134   // Retrieve the vertices
0135   auto vertices = aBounds.vertices(0u);
0136   BOOST_CHECK_EQUAL(vertices.size(), 4);
0137 
0138   // Now generate with more segments
0139   unsigned int nQuarterSegments = 12;
0140   vertices = aBounds.vertices(nQuarterSegments);
0141   BOOST_CHECK_EQUAL(vertices.size(), 14u);
0142 }
0143 
0144 BOOST_AUTO_TEST_CASE(AnnulusBoundsNegativeTolerance) {
0145   AnnulusBounds aBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
0146   double phiAverage = (minPhi + maxPhi) / 2;
0147 
0148   auto check = [&](const BoundaryTolerance& tolerance, const Vector2& point) {
0149     Vector2 pointAverage(point[0], phiAverage + point[1]);
0150     return aBounds.inside(pointAverage, tolerance);
0151   };
0152 
0153   double midRadius = (minRadius + maxRadius) / 2;
0154   double hlPhi = (maxPhi - minPhi) / 2;
0155 
0156   {
0157     auto tolerance = BoundaryTolerance::AbsoluteEuclidean(1);
0158 
0159     // Test points near radial boundaries
0160     BOOST_CHECK(!check(tolerance, {minRadius - 1.5, 0}));
0161     BOOST_CHECK(check(tolerance, {minRadius - 0.1, 0}));
0162     BOOST_CHECK(check(tolerance, {minRadius + 0.4, 0}));
0163     BOOST_CHECK(check(tolerance, {minRadius + 0.5, 0}));
0164     BOOST_CHECK(check(tolerance, {minRadius + 1.5, 0}));
0165 
0166     BOOST_CHECK(check(tolerance, {maxRadius - 1.5, 0}));
0167     BOOST_CHECK(check(tolerance, {maxRadius - 0.1, 0}));
0168     BOOST_CHECK(check(tolerance, {maxRadius + 0.3, 0}));
0169     BOOST_CHECK(check(tolerance, {maxRadius + 0.55, 0}));
0170     BOOST_CHECK(check(tolerance, {maxRadius + 1.2, 0}));
0171     BOOST_CHECK(!check(tolerance, {maxRadius + 1.7, 0}));
0172 
0173     // Check points near axial boundaries
0174     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 1.5}));
0175     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 1.1}));
0176     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 0.8}));
0177     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 0.5}));
0178 
0179     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 0.5}));
0180     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 0.8}));
0181     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 1.1}));
0182     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 1.5}));
0183   }
0184 
0185   {
0186     auto tolerance = BoundaryTolerance::AbsoluteEuclidean(-1);
0187 
0188     // Test points near radial boundaries
0189     BOOST_CHECK(!check(tolerance, {minRadius - 1.5, 0}));
0190     BOOST_CHECK(!check(tolerance, {minRadius - 0.1, 0}));
0191     BOOST_CHECK(!check(tolerance, {minRadius + 0.4, 0}));
0192     BOOST_CHECK(!check(tolerance, {minRadius + 0.5, 0}));
0193     BOOST_CHECK(check(tolerance, {minRadius + 1.5, 0}));
0194 
0195     BOOST_CHECK(check(tolerance, {maxRadius - 1.5, 0}));
0196     BOOST_CHECK(!check(tolerance, {maxRadius - 0.1, 0}));
0197     BOOST_CHECK(!check(tolerance, {maxRadius + 0.3, 0}));
0198     BOOST_CHECK(!check(tolerance, {maxRadius + 0.55, 0}));
0199     BOOST_CHECK(!check(tolerance, {maxRadius + 1.2, 0}));
0200     BOOST_CHECK(!check(tolerance, {maxRadius + 1.7, 0}));
0201 
0202     // Check points near axial boundaries
0203     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 1.5}));
0204     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 1.1}));
0205     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 0.8}));
0206     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 0.5}));
0207 
0208     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 0.5}));
0209     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 0.8}));
0210     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 1.1}));
0211     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 1.5}));
0212   }
0213 
0214   {
0215     auto tolerance =
0216         BoundaryTolerance::Chi2Bound(SquareMatrix2::Identity(), 0.1);
0217 
0218     // Test points near radial boundaries
0219     BOOST_CHECK(!check(tolerance, {minRadius - 1.5, 0}));
0220     BOOST_CHECK(check(tolerance, {minRadius - 0.1, 0}));
0221     BOOST_CHECK(check(tolerance, {minRadius + 0.4, 0}));
0222     BOOST_CHECK(check(tolerance, {minRadius + 0.5, 0}));
0223     BOOST_CHECK(check(tolerance, {minRadius + 1.5, 0}));
0224 
0225     BOOST_CHECK(check(tolerance, {maxRadius - 1.5, 0}));
0226     BOOST_CHECK(check(tolerance, {maxRadius - 0.1, 0}));
0227     BOOST_CHECK(check(tolerance, {maxRadius + 0.3, 0}));
0228     BOOST_CHECK(check(tolerance, {maxRadius + 0.55, 0}));
0229     BOOST_CHECK(!check(tolerance, {maxRadius + 1.2, 0}));
0230     BOOST_CHECK(!check(tolerance, {maxRadius + 1.7, 0}));
0231 
0232     // Check points near axial boundaries
0233     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 1.5}));
0234     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 1.1}));
0235     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 0.8}));
0236     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 0.5}));
0237 
0238     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 0.5}));
0239     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 0.8}));
0240     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 1.1}));
0241     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 1.5}));
0242   }
0243 
0244   {
0245     auto tolerance =
0246         BoundaryTolerance::Chi2Bound(SquareMatrix2::Identity(), -0.1);
0247 
0248     // Test points near radial boundaries
0249     BOOST_CHECK(!check(tolerance, {minRadius - 1.5, 0}));
0250     BOOST_CHECK(!check(tolerance, {minRadius - 0.1, 0}));
0251     BOOST_CHECK(!check(tolerance, {minRadius + 0.4, 0}));
0252     BOOST_CHECK(check(tolerance, {minRadius + 0.5, 0}));
0253     BOOST_CHECK(check(tolerance, {minRadius + 1.5, 0}));
0254 
0255     BOOST_CHECK(check(tolerance, {maxRadius - 1.5, 0}));
0256     BOOST_CHECK(check(tolerance, {maxRadius - 0.1, 0}));
0257     BOOST_CHECK(!check(tolerance, {maxRadius + 0.3, 0}));
0258     BOOST_CHECK(!check(tolerance, {maxRadius + 0.55, 0}));
0259     BOOST_CHECK(!check(tolerance, {maxRadius + 1.2, 0}));
0260     BOOST_CHECK(!check(tolerance, {maxRadius + 1.7, 0}));
0261 
0262     // Check points near axial boundaries
0263     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 1.5}));
0264     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 1.1}));
0265     BOOST_CHECK(!check(tolerance, {midRadius, -hlPhi * 0.8}));
0266     BOOST_CHECK(check(tolerance, {midRadius, -hlPhi * 0.5}));
0267 
0268     BOOST_CHECK(check(tolerance, {midRadius, hlPhi * 0.5}));
0269     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 0.8}));
0270     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 1.1}));
0271     BOOST_CHECK(!check(tolerance, {midRadius, hlPhi * 1.5}));
0272   }
0273 }
0274 
0275 BOOST_AUTO_TEST_SUITE_END()
0276 
0277 }  // namespace Acts::Test