Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-27 08:34:28

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/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/RadialBounds.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <cmath>
0020 #include <numbers>
0021 #include <stdexcept>
0022 #include <vector>
0023 
0024 using namespace Acts;
0025 
0026 namespace ActsTests {
0027 
0028 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0029 
0030 const double rMin = 1.;
0031 const double rMax = 5.;
0032 const double halfPhiSector = std::numbers::pi / 8.;
0033 const double avgPhi = 0.1;
0034 
0035 /// Unit tests for RadialBounds constructors
0036 BOOST_AUTO_TEST_CASE(RadialBoundsConstruction) {
0037   /// Test default construction
0038   // default construction is deleted
0039 
0040   /// Test construction with radii and default sector
0041   BOOST_CHECK_EQUAL(RadialBounds(rMin, rMax).type(), SurfaceBounds::eDisc);
0042 
0043   /// Test construction with radii and sector half angle
0044   BOOST_CHECK_EQUAL(RadialBounds(rMin, rMax, halfPhiSector).type(),
0045                     SurfaceBounds::eDisc);
0046 
0047   /// Copy constructor
0048   RadialBounds original(rMin, rMax);
0049   RadialBounds copied(original);
0050   BOOST_CHECK_EQUAL(copied, original);
0051 }
0052 
0053 // Streaning and recreation test
0054 BOOST_AUTO_TEST_CASE(RadialBoundsRecreation) {
0055   RadialBounds original(rMin, rMax, halfPhiSector, avgPhi);
0056   // const bool symmetric(false);
0057   auto valvector = original.values();
0058   std::array<double, RadialBounds::eSize> values{};
0059   std::copy_n(valvector.begin(), RadialBounds::eSize, values.begin());
0060   RadialBounds recreated(values);
0061   BOOST_CHECK_EQUAL(original, recreated);
0062 }
0063 
0064 // Streaning and recreation test
0065 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
0066   // Negative inner radius
0067   BOOST_CHECK_THROW(RadialBounds(-rMin, rMax, halfPhiSector, avgPhi),
0068                     std::logic_error);
0069 
0070   // Negative outer radius
0071   BOOST_CHECK_THROW(RadialBounds(rMin, -rMax, halfPhiSector, avgPhi),
0072                     std::logic_error);
0073 
0074   // Negative inner and outer radius
0075   BOOST_CHECK_THROW(RadialBounds(-rMin, -rMax, halfPhiSector, avgPhi),
0076                     std::logic_error);
0077 
0078   // Swapped radii
0079   BOOST_CHECK_THROW(RadialBounds(rMax, rMin, halfPhiSector, avgPhi),
0080                     std::logic_error);
0081 
0082   // Out of bound phi sector
0083   BOOST_CHECK_THROW(RadialBounds(rMin, -rMax, -5., avgPhi), std::logic_error);
0084 
0085   // Out of bound phi position
0086   BOOST_CHECK_THROW(RadialBounds(rMin, -rMax, halfPhiSector, 5.),
0087                     std::logic_error);
0088 }
0089 
0090 /// Unit tests for RadialBounds properties
0091 BOOST_AUTO_TEST_CASE(RadialBoundsProperties) {
0092   /// Test type() (redundant; already used in constructor confirmation)
0093   RadialBounds radialBoundsObject(rMin, rMax, halfPhiSector);
0094   BOOST_CHECK_EQUAL(radialBoundsObject.type(), SurfaceBounds::eDisc);
0095 
0096   /// Test distanceToBoundary
0097   Vector2 outside(30., 0.);
0098   Vector2 inSurface(2., 0.);
0099 
0100   /// Test dump
0101   boost::test_tools::output_test_stream dumpOutput;
0102   radialBoundsObject.toStream(dumpOutput);
0103   BOOST_CHECK(
0104       dumpOutput.is_equal("Acts::RadialBounds:  (innerRadius, outerRadius, "
0105                           "hPhiSector, averagePhi) = (1.0000000, "
0106                           "5.0000000, 0.3926991, 0.0000000)"));
0107 
0108   /// Test inside
0109   BOOST_CHECK(radialBoundsObject.inside(inSurface, BoundaryTolerance::None()));
0110   BOOST_CHECK(!radialBoundsObject.inside(outside, BoundaryTolerance::None()));
0111 
0112   /// Test rMin
0113   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMinR), rMin);
0114 
0115   /// Test rMax
0116   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMaxR), rMax);
0117 
0118   /// Test averagePhi (should be a redundant method, this is not configurable)
0119   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eAveragePhi), 0.);
0120 
0121   /// Test halfPhiSector
0122   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eHalfPhiSector),
0123                     halfPhiSector);
0124 }
0125 /// Unit test for testing RadialBounds assignment
0126 BOOST_AUTO_TEST_CASE(RadialBoundsAssignment) {
0127   RadialBounds radialBoundsObject(rMin, rMax, halfPhiSector);
0128 
0129   /// Test operator ==
0130   // not implemented in this class
0131 
0132   /// Test assignment
0133   RadialBounds assignedRadialBoundsObject(10.1, 123.);
0134   assignedRadialBoundsObject = radialBoundsObject;
0135   BOOST_CHECK_EQUAL(assignedRadialBoundsObject, radialBoundsObject);
0136 }
0137 
0138 BOOST_AUTO_TEST_CASE(RadialBoundsCenter) {
0139   // Test radial bounds with default phi
0140   RadialBounds radial(rMin, rMax);
0141   Vector2 center = radial.center();
0142   double expectedR = 0.5 * (rMin + rMax);
0143   BOOST_CHECK_EQUAL(center.x(), expectedR);
0144   BOOST_CHECK_EQUAL(center.y(), 0.0);  // avgPhi = 0
0145 
0146   // Test radial bounds with non-zero average phi
0147   RadialBounds radialOffset(rMin, rMax, halfPhiSector, avgPhi);
0148   Vector2 centerOffset = radialOffset.center();
0149   BOOST_CHECK_EQUAL(centerOffset.x(), expectedR);
0150   BOOST_CHECK_EQUAL(centerOffset.y(), avgPhi);
0151 }
0152 
0153 BOOST_AUTO_TEST_CASE(RadialBoundsCoversFullAzimuth) {
0154   // The default sector is the full azimuth
0155   BOOST_CHECK(RadialBounds(rMin, rMax).coversFullAzimuth());
0156   BOOST_CHECK(RadialBounds(rMin, rMax, std::numbers::pi).coversFullAzimuth());
0157 
0158   // A half sector that is only rounded away from pi still counts as full,
0159   // matching CylinderBounds
0160   BOOST_CHECK(RadialBounds(rMin, rMax, std::nextafter(std::numbers::pi, 0.))
0161                   .coversFullAzimuth());
0162 
0163   // Genuine sectors do not
0164   BOOST_CHECK(!RadialBounds(rMin, rMax, halfPhiSector).coversFullAzimuth());
0165   BOOST_CHECK(
0166       !RadialBounds(rMin, rMax, std::numbers::pi / 2.).coversFullAzimuth());
0167 }
0168 
0169 BOOST_AUTO_TEST_SUITE_END()
0170 
0171 }  // namespace ActsTests