11 #include <utl/Histogram.h>
12 #include <utl/QuadraticFitter.h>
13 #include <tst/Verify.h>
14 #include <cppunit/extensions/HelperMacros.h>
22 #define EQUAL(_x_, _y_) CPPUNIT_ASSERT(Verify<Equal>(_x_, _y_))
23 #define CLOSE(_x_, _y_) CPPUNIT_ASSERT(Verify<CloseTo>(_x_, _y_))
24 #define CLOSEEPS(_x_, _y_, _eps_) CPPUNIT_ASSERT(Verify<CloseTo>(_x_, _y_, _eps_))
33 CPPUNIT_TEST(testHistogramExactFit);
34 CPPUNIT_TEST(testHistogramSemiRandomFit);
35 CPPUNIT_TEST(testFitRange);
36 CPPUNIT_TEST_SUITE_END();
56 {
return fA *
Sqr(x - fExtreme) + fB; }
59 twoHumpFunction(
const double x)
62 const double par = fA2 *
Sqr(x - fExtreme2) + fB2;
63 const double dec = fAExp * exp(-x/fDecay);
64 return dec + (par >= 0 ? par : 0);
71 vector<double> binEdges;
72 vector<double> counts;
73 for (
int i = 0; i < n; ++i) {
74 binEdges.push_back(i);
75 counts.push_back(quadraticFunction(i+0.5));
77 binEdges.push_back(n);
91 CLOSE(pos2, fExtreme);
98 CLOSE(pos3, fExtreme);
110 CLOSE(qf(fExtreme), fB);
111 CLOSE(qf(fExtreme + 3), quadraticFunction(fExtreme + 3));
112 CLOSE(qf(fExtreme - 5), quadraticFunction(fExtreme - 5));
119 vector<double> binEdges(n+1);
120 vector<double> counts(n);
121 for (
int i = 0; i < n; ++i) {
123 const double q = quadraticFunction(i+0.5);
124 const double sq = q > 0 ?
sqrt(2*q) : 0;
125 const double qq = q + sq*sin(123456789.*i);
138 cout <<
"\n pos=" << pos <<
" posErr=" << posErr <<
" chi2=" << chi2 <<
" "
139 "ndof=" << ndof << endl;
145 const double omega = (chi2 - ndof) /
sqrt(2.*ndof);
153 typedef unsigned short int ushort;
155 vector<char> binEdges(n+1);
156 vector<ushort> counts(n);
157 for (
char i = 0; i < n; ++i) {
159 counts[i] =
ushort(twoHumpFunction(i));
161 binEdges[n] = char(n);
165 const int start = 30;
174 cout <<
"\n pos=" << pos <<
" posErr=" << posErr <<
" chi2=" << chi2 <<
" "
175 "ndof=" << ndof << endl;
181 MakeQuadraticFitter(h,
double(start),
double(stop)).GetExtremePosition(posErr2, chi22, ndof2);
187 const double numericalSolution = 47.979666;
188 CLOSEEPS(pos, numericalSolution + 0.5, posErr/10);
190 cout <<
"\n pos=" << pos <<
" posErr=" << posErr <<
" chi2=" << chi2 <<
" "
191 "ndof=" << ndof << endl;
193 cout <<
"start=" << h.GetBinIndex(30.) <<
" stop=" << h.GetBinIndex(70.) << endl;
203 double fExtreme2 = 0;
#define CLOSEEPS(_x_, _y_, _eps_)
constexpr T Sqr(const T &x)
Holds result of the quadratic fit.
void testHistogramExactFit()
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
const double * GetCoefficients() const
void testHistogramSemiRandomFit()
double quadraticFunction(const double x) const
QuadraticFitter< Histogram, ErrorPolicy > MakeQuadraticFitter(const Histogram &h, const ErrorPolicy)
double GetExtremePosition() const