Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:23

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Project include(s).
0009 #include "traccc/definitions/primitives.hpp"
0010 #include "traccc/utils/prob.hpp"
0011 
0012 // ROOT include(s).
0013 #ifdef TRACCC_HAVE_ROOT
0014 #include <Math/ProbFuncMathCore.h>
0015 #endif  // TRACCC_HAVE_ROOT
0016 
0017 // GTest include(s).
0018 #include <gtest/gtest.h>
0019 
0020 using namespace traccc;
0021 
0022 // Test gamma function for pvalue evaulation
0023 TEST(pvalue, compare_with_root) {
0024   // zero chisquare -> pvalue = 1
0025   EXPECT_FLOAT_EQ(prob(0.f, 0.1f), 1.f);
0026   EXPECT_FLOAT_EQ(prob(0.f, 1.f), 1.f);
0027   EXPECT_FLOAT_EQ(prob(0.f, 10.f), 1.f);
0028 
0029   // Negative chi square -> pvalue = 0
0030   EXPECT_FLOAT_EQ(prob(-1.f, 12.f), 0.f);
0031   EXPECT_FLOAT_EQ(prob(-194.f, 12.f), 0.f);
0032 
0033   // Non-positive NDF -> pvalue = 0
0034   EXPECT_FLOAT_EQ(prob(3.f, -17.4f), 0.f);
0035   EXPECT_FLOAT_EQ(prob(27.f, 0.f), 0.f);
0036 
0037   // Compare with the outputs of ROOT::Math::Prob(chi2, ndf)
0038   EXPECT_FLOAT_EQ(prob(3.f, 5.f), 0.69998584f);
0039   EXPECT_FLOAT_EQ(prob(17.4f, 6.26f), 0.0094291369f);
0040 
0041 #ifdef TRACCC_HAVE_ROOT
0042   EXPECT_FLOAT_EQ(prob(3.f, 5.f),
0043                   static_cast<float>(ROOT::Math::chisquared_cdf_c(3., 5.)));
0044   EXPECT_FLOAT_EQ(prob(17.4f, 6.26f),
0045                   static_cast<float>(ROOT::Math::chisquared_cdf_c(17.4, 6.26)));
0046 
0047   for (int i_n = 0; i_n < 500; i_n++) {
0048     const traccc::scalar ndf = static_cast<traccc::scalar>(i_n) * 0.1f;
0049     for (int i_c = 0; i_c < 100; i_c++) {
0050       const traccc::scalar chi2 = static_cast<traccc::scalar>(i_c) * 0.1f;
0051       const traccc::scalar pval = prob(ndf, chi2);
0052       const traccc::scalar pval_root =
0053           static_cast<traccc::scalar>(ROOT::Math::chisquared_cdf_c(
0054               static_cast<double>(ndf), static_cast<double>(chi2)));
0055 
0056       ASSERT_NEAR(pval - pval_root, 0.f, pval_root * 1e-4f);
0057       ASSERT_GE(pval, 0.0f);
0058       ASSERT_LE(pval, 1.0f);
0059     }
0060   }
0061 #endif  // TRACCC_HAVE_ROOT
0062 }