All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
FastAndPoorGauss_test.cc File Reference

Unit test for util::FastAndPoorGauss. More...

#include <boost/test/unit_test.hpp>
#include <boost/test/tools/floating_point_comparison.hpp>
#include "icarusalg/Utilities/FastAndPoorGauss.h"
#include "larcorealg/CoreUtils/counter.h"
#include "TFile.h"
#include "TH1F.h"
#include "TF1.h"
#include "TFitResult.h"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   FastAndPoorGauss
 

Functions

template<std::size_t NSamples>
void Test (TFile *pFile=nullptr, bool statChecks=true)
 
 BOOST_AUTO_TEST_CASE (TestCase)
 

Detailed Description

Unit test for util::FastAndPoorGauss.

Date
February 15, 2020
Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
See Also
`icarusalg/Utilities/FastAndPoorGauss.h

Definition in file FastAndPoorGauss_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   FastAndPoorGauss

Definition at line 10 of file FastAndPoorGauss_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( TestCase  )

Definition at line 74 of file FastAndPoorGauss_test.cc.

74  {
75 
76  TFile F("FastAndPoorGauss_test.root", "RECREATE");
77 
78  Test< 1024U>(&F, false); // with low points the statistics is not very good;
79  Test< 4096U>(&F, false); // so we skip the statistics checks
80  Test< 8192U>(&F, false);
81  Test< 16384U>(&F);
82  Test< 32768U>(&F);
83  Test< 65536U>(&F);
84  Test< 131072U>(&F);
85  Test< 262144U>(&F);
86  Test< 524288U>(&F);
87 // Test<1048576U>(&F);
88 
89  F.Write();
90 
91 } // BOOST_AUTO_TEST_CASE( TestCase )
template<std::size_t NSamples>
void Test ( TFile *  pFile = nullptr,
bool  statChecks = true 
)

Definition at line 30 of file FastAndPoorGauss_test.cc.

30  {
31 
32  constexpr unsigned int NPoints = 1'000'000U;
33 
34  std::string const NSamplesTag = std::to_string(NSamples);
35 
37  BOOST_TEST_MESSAGE("Testing sampling " << NSamples << " points.");
38 
39  TH1D HGaus(
40  ("HGaus" + NSamplesTag).c_str(),
41  ("Distribution from util::FastAndPoorGauss<" + NSamplesTag + ">").c_str(),
42  1024, -5.0, +5.0
43  );
44  HGaus.SetDirectory(pFile);
45 
46  util::UniformSequence<> extract { NPoints };
47  for (auto _ [[gnu::unused]]: util::counter(NPoints)) {
48  double const u = extract();
49  double const z = gauss(u);
50  HGaus.Fill(z);
51  } // for
52 
53  TF1* pGaus = new TF1(("FGaus" + NSamplesTag).c_str(), "gaus", -5.0, +5.0);
54  TFitResultPtr pFitRes = HGaus.Fit(pGaus, "QS"); // Quiet, reSult
55  BOOST_CHECK(pFitRes->IsValid());
56  if (statChecks) BOOST_CHECK_LT(pFitRes->Chi2()/pFitRes->Ndf(), 5.0);
57  pFitRes->Print();
58 
59  // mean should be smaller than twice its uncertainty
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); // stddev (1% tolerance)
62 
63  if (pFile) {
64  HGaus.Write();
65  HGaus.SetDirectory(nullptr);
66  }
67 
68 } // void Test()
process_name opflash particleana ie ie ie z
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.
Definition: counter.h:285
std::string to_string(WindowPattern const &pattern)
Samples the interval [ 0, 1 ] in sequence, cyclically.