Back to home page

EIC code displayed by LXR

 
 

    


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

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