Computes a χ² from expectation function and data points. More...
#include <ChiSquareAccumulator.h>
Public Types | |
using | Function_t = F |
Type of function for the expectation. More... | |
using | Data_t = T |
Type of parameter and observed values. More... | |
Public Member Functions | |
unsigned int | N () const |
Returns the number of added points (it's not degrees of freedom yet!). More... | |
Data_t | expected (Data_t x) const |
Returns the expected value for the specified parameter. More... | |
ChiSquareAccumulator (Function_t const &expected) | |
Constructor: uses the specified expectation function. More... | |
Access to results | |
Data_t | chiSquare () const |
Returns the value of χ² currently accumulated. More... | |
Data_t | operator() () const |
operator Data_t () const | |
Data manipulation | |
void | add (Data_t x, Data_t y) |
Adds a data point to the χ². More... | |
void | add (Data_t x, Data_t y, Data_t s) |
Adds a data point to the χ². More... | |
void | clear () |
Resets all the counts, starting from no data. More... | |
Static Private Member Functions | |
static Data_t | z (Data_t x, Data_t mu, Data_t sigma) |
Normal variable. More... | |
static Data_t | sqr (Data_t v) |
The usual square function. More... | |
Private Attributes | |
unsigned int | fN = 0U |
Number of data entries. More... | |
Data_t | fChiSq = 0.0 |
Accumulated χ² value. More... | |
Function_t | fExpected |
Function for the expectation. More... | |
Computes a χ² from expectation function and data points.
F | type of the function |
T | type of data |
The formula used is the simple with each observed point being and with the function describing the expectation (e.g. a fit result).
The parameter F
must be usable as a unary functor, that is it must accept a single argument convertible from type Data_t
(that is T
), and return a value convertible back to type Data_t
.
Example of usage:
will check three observations against the prediction of 2 - x
, returning a chi2value
of 8.0
and a degreesOfFreedom
of 0
(note that the 3
degrees are manually subtracted).
Definition at line 55 of file ChiSquareAccumulator.h.
using lar::util::ChiSquareAccumulator< F, T >::Data_t = T |
Type of parameter and observed values.
Definition at line 58 of file ChiSquareAccumulator.h.
using lar::util::ChiSquareAccumulator< F, T >::Function_t = F |
Type of function for the expectation.
Definition at line 57 of file ChiSquareAccumulator.h.
|
inline |
Constructor: uses the specified expectation function.
expected | expectation function |
The expectation function domain must be a single dimension of type Data_t
.
Definition at line 68 of file ChiSquareAccumulator.h.
|
inline |
Adds a data point to the χ².
x | parameter |
y | observed data with the x parameter |
The χ² is increased by where e is the expectation function (expected()
). The observed values are considered to have nominal uncertainty 1
.
Definition at line 108 of file ChiSquareAccumulator.h.
|
inline |
Adds a data point to the χ².
x | parameter |
y | observed data with the x parameter |
s | uncertainty on the observed data (default: 1.0 ) |
The χ² is increased by where e is the expectation function (expected()
).
Definition at line 120 of file ChiSquareAccumulator.h.
|
inline |
Returns the value of χ² currently accumulated.
Definition at line 79 of file ChiSquareAccumulator.h.
|
inline |
Resets all the counts, starting from no data.
Definition at line 124 of file ChiSquareAccumulator.h.
|
inline |
Returns the expected value for the specified parameter.
Definition at line 88 of file ChiSquareAccumulator.h.
|
inline |
Returns the number of added points (it's not degrees of freedom yet!).
Definition at line 85 of file ChiSquareAccumulator.h.
|
inline |
Definition at line 81 of file ChiSquareAccumulator.h.
|
inline |
Definition at line 80 of file ChiSquareAccumulator.h.
|
inlinestaticprivate |
The usual square function.
Definition at line 140 of file ChiSquareAccumulator.h.
|
inlinestaticprivate |
|
private |
Accumulated χ² value.
Definition at line 131 of file ChiSquareAccumulator.h.
|
private |
Function for the expectation.
Definition at line 133 of file ChiSquareAccumulator.h.
|
private |
Number of data entries.
Definition at line 130 of file ChiSquareAccumulator.h.