Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-15 08:05:45

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/ConeBounds.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <cmath>
0020 #include <numbers>
0021 #include <stdexcept>
0022 #include <vector>
0023 
0024 // Note on nomenclature:
0025 // - alpha = cone opening half angle
0026 // - z is the axis of symmetry
0027 // - zMin, zMax define limits for truncated cone
0028 // - phi is clock angle around cone, with x axis corresponding to phi=0
0029 // - Cone segments may be defined with the averagePhi (central position of
0030 // segment) and halfPhi (extent in phi of cone segment either side of the
0031 // averagePhi)
0032 // - Local coords are z, rphi
0033 
0034 using namespace Acts;
0035 
0036 namespace ActsTests {
0037 
0038 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0039 
0040 const double alpha = std::numbers::pi / 8.;
0041 const double zMin = 3.;
0042 const double zMax = 6.;
0043 const double halfPhi = std::numbers::pi / 4.;
0044 const double averagePhi = 0.;
0045 const bool symmetric = false;
0046 
0047 /// Unit test for creating compliant/non-compliant ConeBounds object
0048 BOOST_AUTO_TEST_CASE(ConeBoundsConstruction) {
0049   /// Test default construction
0050   // default construction is deleted
0051 
0052   BOOST_TEST_CHECKPOINT("Four parameter constructor (last two at default)");
0053   ConeBounds defaultConeBounds(alpha, symmetric);
0054   BOOST_CHECK_EQUAL(defaultConeBounds.type(), SurfaceBounds::eCone);
0055 
0056   BOOST_TEST_CHECKPOINT("Four parameter constructor");
0057   ConeBounds fourParameterConstructed(alpha, symmetric, halfPhi, averagePhi);
0058   BOOST_CHECK_EQUAL(fourParameterConstructed.type(), SurfaceBounds::eCone);
0059 
0060   BOOST_TEST_CHECKPOINT("Five parameter constructor (last two at default)");
0061   ConeBounds defaulted5ParamConeBounds(alpha, zMin, zMax);
0062   BOOST_CHECK_EQUAL(defaulted5ParamConeBounds.type(), SurfaceBounds::eCone);
0063 
0064   BOOST_TEST_CHECKPOINT("Five parameter constructor)");
0065   ConeBounds fiveParamConstructedConeBounds(alpha, zMin, zMax, halfPhi,
0066                                             averagePhi);
0067   BOOST_CHECK_EQUAL(fiveParamConstructedConeBounds.type(),
0068                     SurfaceBounds::eCone);
0069 
0070   BOOST_TEST_CHECKPOINT("Copy constructor");
0071   ConeBounds copyConstructedConeBounds(fiveParamConstructedConeBounds);
0072   BOOST_CHECK_EQUAL(copyConstructedConeBounds, fiveParamConstructedConeBounds);
0073 }
0074 
0075 /// Streaning and recreation test
0076 BOOST_AUTO_TEST_CASE(ConeBoundsRecreation) {
0077   ConeBounds original(alpha, zMin, zMax, halfPhi, averagePhi);
0078   auto valvector = original.values();
0079   std::array<double, ConeBounds::eSize> values{};
0080   std::copy_n(valvector.begin(), ConeBounds::eSize, values.begin());
0081   ConeBounds recreated(values);
0082 
0083   BOOST_CHECK_EQUAL(recreated, original);
0084 }
0085 
0086 /// Unit tests for AnnulusBounds exception throwing
0087 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
0088   // Exception for opening angle smaller 0
0089   BOOST_CHECK_THROW(ConeBounds(-alpha, zMin, zMax, halfPhi, averagePhi),
0090                     std::logic_error);
0091 
0092   // Exception for opening angle bigger pi
0093   BOOST_CHECK_THROW(
0094       ConeBounds(std::numbers::pi, zMin, zMax, halfPhi, averagePhi),
0095       std::logic_error);
0096 
0097   // Exception for swapped zMin and zMax
0098   BOOST_CHECK_THROW(ConeBounds(alpha, zMax, zMin, halfPhi, averagePhi),
0099                     std::logic_error);
0100 
0101   // Exception for negative half sector phi
0102   BOOST_CHECK_THROW(ConeBounds(alpha, zMin, zMax, -halfPhi, averagePhi),
0103                     std::logic_error);
0104 
0105   // Exception for out of range phi positioning
0106   BOOST_CHECK_THROW(
0107       ConeBounds(alpha, zMin, zMax, halfPhi, 2 * std::numbers::pi),
0108       std::logic_error);
0109 }
0110 
0111 /// Unit tests for properties of ConeBounds object
0112 BOOST_AUTO_TEST_CASE(ConeBoundsProperties) {
0113   const Vector2 origin(0, 0);
0114   const Vector2 somewhere(4., 4.);
0115   ConeBounds coneBoundsObject(alpha, zMin, zMax, halfPhi, averagePhi);
0116 
0117   /// Test for type (redundant)
0118   BOOST_CHECK_EQUAL(coneBoundsObject.type(), SurfaceBounds::eCone);
0119 
0120   /// Test for inside
0121   BOOST_CHECK(!coneBoundsObject.inside(origin));
0122 
0123   /// Test for r
0124   CHECK_CLOSE_REL(coneBoundsObject.r(zMin), zMin * std::tan(alpha), 1e-6);
0125 
0126   /// Test for tanAlpha
0127   CHECK_CLOSE_REL(coneBoundsObject.tanAlpha(), std::tan(alpha), 1e-6);
0128 
0129   /// Test for alpha
0130   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eAlpha), alpha, 1e-6);
0131 
0132   /// Test for minZ
0133   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMinZ), zMin, 1e-6);
0134 
0135   /// Test for maxZ
0136   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMaxZ), zMax, 1e-6);
0137 
0138   /// Test for averagePhi
0139   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eHalfPhiSector), halfPhi,
0140                   1e-6);
0141 
0142   /// Test for dump
0143   boost::test_tools::output_test_stream dumpOutput;
0144   coneBoundsObject.toStream(dumpOutput);
0145   BOOST_CHECK(dumpOutput.is_equal(
0146       "Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, averagePhi) = "
0147       "(0.4142136, 3.0000000, 6.0000000, 0.7853982, 0.0000000)"));
0148 }
0149 
0150 // Unit test for testing ConeBounds assignment
0151 BOOST_AUTO_TEST_CASE(ConeBoundsAssignment) {
0152   ConeBounds originalConeBounds(alpha, zMin, zMax, halfPhi, averagePhi);
0153   ConeBounds assignedConeBounds(0.1, 2.3, 4.5, 1.2, 2.1);
0154   assignedConeBounds = originalConeBounds;
0155 
0156   BOOST_CHECK_EQUAL(assignedConeBounds, originalConeBounds);
0157 }
0158 
0159 BOOST_AUTO_TEST_CASE(ConeBoundsCenter) {
0160   // Test cone bounds centroid
0161   ConeBounds cone(alpha, zMin, zMax, halfPhi, averagePhi);
0162   Vector2 center = cone.center();
0163 
0164   double expectedZ = 0.5 * (zMin + zMax);
0165   BOOST_CHECK_EQUAL(center.x(), averagePhi);
0166   BOOST_CHECK_EQUAL(center.y(), expectedZ);
0167 
0168   // Test with different averagePhi
0169   const double avgPhiOffset = std::numbers::pi / 6.;
0170   ConeBounds coneOffset(alpha, zMin, zMax, halfPhi, avgPhiOffset);
0171   Vector2 centerOffset = coneOffset.center();
0172   BOOST_CHECK_EQUAL(centerOffset.x(), avgPhiOffset);
0173   BOOST_CHECK_EQUAL(centerOffset.y(), expectedZ);
0174 }
0175 
0176 BOOST_AUTO_TEST_SUITE_END()
0177 
0178 }  // namespace ActsTests