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/tools/output_test_stream.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/Surfaces/BoundaryCheck.hpp"
0015 #include "Acts/Surfaces/RadialBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <cmath>
0021 #include <stdexcept>
0022 #include <vector>
0023 
0024 namespace Acts {
0025 
0026 namespace Test {
0027 BOOST_AUTO_TEST_SUITE(Surfaces)
0028 
0029 /// Unit tests for RadialBounds constrcuctors
0030 BOOST_AUTO_TEST_CASE(RadialBoundsConstruction) {
0031   double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
0032   // test default construction
0033   // RadialBounds defaultConstructedRadialBounds;  should be deleted
0034   //
0035   /// Test construction with radii and default sector
0036   BOOST_CHECK_EQUAL(RadialBounds(minRadius, maxRadius).type(),
0037                     SurfaceBounds::eDisc);
0038   //
0039   /// Test construction with radii and sector half angle
0040   BOOST_CHECK_EQUAL(RadialBounds(minRadius, maxRadius, halfPhiSector).type(),
0041                     SurfaceBounds::eDisc);
0042   //
0043   /// Copy constructor
0044   RadialBounds original(minRadius, maxRadius);
0045   RadialBounds copied(original);
0046   BOOST_CHECK_EQUAL(copied, original);
0047 }
0048 
0049 // Streaning and recreation test
0050 BOOST_AUTO_TEST_CASE(RadialBoundsRecreation) {
0051   double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0), avgPhi(0.1);
0052   RadialBounds original(minRadius, maxRadius, halfPhiSector, avgPhi);
0053   // const bool symmetric(false);
0054   auto valvector = original.values();
0055   std::array<double, RadialBounds::eSize> values{};
0056   std::copy_n(valvector.begin(), RadialBounds::eSize, values.begin());
0057   RadialBounds recreated(values);
0058   BOOST_CHECK_EQUAL(original, recreated);
0059 }
0060 
0061 // Streaning and recreation test
0062 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
0063   double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0), avgPhi(0.1);
0064 
0065   // Negative inner radius
0066   BOOST_CHECK_THROW(RadialBounds(-minRadius, maxRadius, halfPhiSector, avgPhi),
0067                     std::logic_error);
0068 
0069   // Negative outer radius
0070   BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, halfPhiSector, avgPhi),
0071                     std::logic_error);
0072 
0073   // Negative inner and outer radius
0074   BOOST_CHECK_THROW(RadialBounds(-minRadius, -maxRadius, halfPhiSector, avgPhi),
0075                     std::logic_error);
0076 
0077   // Swapped radii
0078   BOOST_CHECK_THROW(RadialBounds(maxRadius, minRadius, halfPhiSector, avgPhi),
0079                     std::logic_error);
0080 
0081   // Out of bound phi sector
0082   BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, -5., avgPhi),
0083                     std::logic_error);
0084 
0085   // Out of bound phi position
0086   BOOST_CHECK_THROW(RadialBounds(minRadius, -maxRadius, halfPhiSector, 5.),
0087                     std::logic_error);
0088 }
0089 
0090 /// Unit tests for RadialBounds properties
0091 BOOST_AUTO_TEST_CASE(RadialBoundsProperties) {
0092   double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
0093   /// Test type() (redundant; already used in constructor confirmation)
0094   RadialBounds radialBoundsObject(minRadius, maxRadius, halfPhiSector);
0095   BOOST_CHECK_EQUAL(radialBoundsObject.type(), SurfaceBounds::eDisc);
0096   //
0097   /// Test distanceToBoundary
0098   Vector2 outside(30., 0.);
0099   Vector2 inSurface(2., 0.0);
0100 
0101   /// Test dump
0102   boost::test_tools::output_test_stream dumpOuput;
0103   radialBoundsObject.toStream(dumpOuput);
0104   BOOST_CHECK(
0105       dumpOuput.is_equal("Acts::RadialBounds:  (innerRadius, outerRadius, "
0106                          "hPhiSector, averagePhi) = (1.0000000, "
0107                          "5.0000000, 0.3926991, 0.0000000)"));
0108   //
0109   /// Test inside
0110   BOOST_CHECK(radialBoundsObject.inside(inSurface, BoundaryCheck(true)));
0111   BOOST_CHECK(!radialBoundsObject.inside(outside, BoundaryCheck(true)));
0112   //
0113   /// Test rMin
0114   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMinR), minRadius);
0115   //
0116   /// Test rMax
0117   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMaxR), maxRadius);
0118   //
0119   /// Test averagePhi (should be a redundant method, this is not configurable)
0120   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eAveragePhi), 0.0);
0121   //
0122   /// Test halfPhiSector
0123   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eHalfPhiSector),
0124                     halfPhiSector);
0125 }
0126 /// Unit test for testing RadialBounds assignment
0127 BOOST_AUTO_TEST_CASE(RadialBoundsAssignment) {
0128   double minRadius(1.0), maxRadius(5.0), halfPhiSector(M_PI / 8.0);
0129   RadialBounds radialBoundsObject(minRadius, maxRadius, halfPhiSector);
0130   // operator == 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_SUITE_END()
0139 
0140 }  // namespace Test
0141 
0142 }  // namespace Acts