Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-07 09:17:29

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/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Utilities/AngleHelpers.hpp"
0013 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0014 
0015 #include <cmath>
0016 #include <numbers>
0017 
0018 namespace bd = boost::unit_test::data;
0019 
0020 using namespace Acts;
0021 
0022 using Acts::AngleHelpers::etaFromTheta;
0023 using Acts::AngleHelpers::EtaThetaConversionTraits;
0024 using Acts::AngleHelpers::thetaFromEta;
0025 
0026 namespace ActsTests {
0027 
0028 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0029 
0030 BOOST_AUTO_TEST_CASE(EtaThetaConversion) {
0031   CHECK_CLOSE_ABS(0.0, etaFromTheta(std::numbers::pi / 2), 1e-6);
0032   CHECK_CLOSE_ABS(1.0, etaFromTheta(thetaFromEta(1.0)), 1e-6);
0033   CHECK_CLOSE_ABS(1.0, thetaFromEta(etaFromTheta(1.0)), 1e-6);
0034 }
0035 
0036 BOOST_DATA_TEST_CASE(EtaFromThetaRobustness, bd::xrange(0, 1000, 1), exponent) {
0037   {
0038     // check right
0039 
0040     float thetaRight = exponent < 30 ? std::pow(10.0f, -1.0f * exponent) : 0.0f;
0041 
0042     float etaRight = etaFromTheta<float>(thetaRight);
0043     BOOST_CHECK(!std::isnan(etaRight));
0044 
0045     // check left
0046 
0047     float thetaLeft = std::numbers::pi_v<float> - thetaRight;
0048 
0049     float etaLeft = etaFromTheta<float>(thetaLeft);
0050     BOOST_CHECK(!std::isnan(etaLeft));
0051   }
0052 
0053   {
0054     // check right
0055 
0056     double thetaRight = exponent < 300 ? std::pow(10.0, -1.0 * exponent) : 0.0;
0057 
0058     double etaRight = etaFromTheta<double>(thetaRight);
0059     BOOST_CHECK(!std::isnan(etaRight));
0060 
0061     // check left
0062 
0063     double thetaLeft = std::numbers::pi - thetaRight;
0064 
0065     double etaLeft = etaFromTheta<double>(thetaLeft);
0066     BOOST_CHECK(!std::isnan(etaLeft));
0067   }
0068 }
0069 
0070 BOOST_DATA_TEST_CASE(ThetaFromEtaRobustness, bd::xrange(1.0, 1000.0, 1.0),
0071                      etaRight) {
0072   {
0073     // check right
0074 
0075     float thetaRight = thetaFromEta<float>(etaRight);
0076     BOOST_CHECK(!std::isnan(thetaRight));
0077 
0078     // check left
0079 
0080     float etaLeft = -etaRight;
0081 
0082     float thetaLeft = thetaFromEta<float>(etaLeft);
0083     BOOST_CHECK(!std::isnan(thetaLeft));
0084   }
0085 
0086   {
0087     // check right
0088 
0089     double thetaRight = thetaFromEta<double>(etaRight);
0090     BOOST_CHECK(!std::isnan(thetaRight));
0091 
0092     // check left
0093 
0094     double etaLeft = -etaRight;
0095 
0096     double thetaLeft = thetaFromEta<double>(etaLeft);
0097     BOOST_CHECK(!std::isnan(thetaLeft));
0098   }
0099 }
0100 
0101 BOOST_AUTO_TEST_SUITE_END()
0102 
0103 }  // namespace ActsTests