10 #define BOOST_TEST_MODULE FastAndPoorGauss
11 #include <boost/test/unit_test.hpp>
12 #include <boost/test/tools/floating_point_comparison.hpp>
25 #include "TFitResult.h"
29 template <std::
size_t NSamples>
30 void Test(TFile* pFile =
nullptr,
bool statChecks =
true) {
32 constexpr
unsigned int NPoints = 1
'000'000U;
37 BOOST_TEST_MESSAGE(
"Testing sampling " << NSamples <<
" points.");
40 (
"HGaus" + NSamplesTag).c_str(),
41 (
"Distribution from util::FastAndPoorGauss<" + NSamplesTag +
">").c_str(),
44 HGaus.SetDirectory(pFile);
48 double const u = extract();
49 double const z = gauss(u);
53 TF1* pGaus =
new TF1((
"FGaus" + NSamplesTag).c_str(),
"gaus", -5.0, +5.0);
54 TFitResultPtr pFitRes = HGaus.Fit(pGaus,
"QS");
55 BOOST_CHECK(pFitRes->IsValid());
56 if (statChecks) BOOST_CHECK_LT(pFitRes->Chi2()/pFitRes->Ndf(), 5.0);
60 if (statChecks) BOOST_CHECK_SMALL(pFitRes->Parameter(1), 2.*pFitRes->Error(1));
61 if (statChecks) BOOST_CHECK_CLOSE(pFitRes->Parameter(2), 1.0, 1.0);
65 HGaus.SetDirectory(
nullptr);
76 TFile
F(
"FastAndPoorGauss_test.root",
"RECREATE");
78 Test< 1024U>(&
F,
false);
79 Test< 4096U>(&
F,
false);
80 Test< 8192U>(&
F,
false);
process_name opflash particleana ie ie ie z
Fast approximate Gaussian random translator.
void Test(TFile *pFile=nullptr, bool statChecks=true)
Translates a number u uniformly distributed between 0 and 1 into a Gaussian distributed one z...
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Test of util::counter and support utilities.
std::string to_string(WindowPattern const &pattern)