LArSoft
v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
|
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 |
Returns the value of χ² currently accumulated. More... | |
operator Data_t () const | |
Returns the value of χ² currently accumulated. More... | |
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.
References lar::util::ChiSquareAccumulator< F, T >::expected(), lar::util::ChiSquareAccumulator< F, T >::fChiSq, lar::util::ChiSquareAccumulator< F, T >::fN, and lar::util::ChiSquareAccumulator< F, T >::sqr().
|
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.
References lar::util::ChiSquareAccumulator< F, T >::expected(), lar::util::ChiSquareAccumulator< F, T >::fChiSq, lar::util::ChiSquareAccumulator< F, T >::fN, lar::util::ChiSquareAccumulator< F, T >::sqr(), and lar::util::ChiSquareAccumulator< F, T >::z().
|
inline |
Returns the value of χ² currently accumulated.
Definition at line 79 of file ChiSquareAccumulator.h.
References lar::util::ChiSquareAccumulator< F, T >::fChiSq.
Referenced by lar::util::ChiSquareAccumulator< F, T >::operator Data_t(), and lar::util::ChiSquareAccumulator< F, T >::operator()().
|
inline |
Resets all the counts, starting from no data.
Definition at line 124 of file ChiSquareAccumulator.h.
References lar::util::ChiSquareAccumulator< F, T >::fChiSq, and lar::util::ChiSquareAccumulator< F, T >::fN.
|
inline |
Returns the expected value for the specified parameter.
Definition at line 88 of file ChiSquareAccumulator.h.
References lar::util::ChiSquareAccumulator< F, T >::fExpected.
Referenced by lar::util::ChiSquareAccumulator< F, T >::add().
|
inline |
Returns the number of added points (it's not degrees of freedom yet!).
Definition at line 85 of file ChiSquareAccumulator.h.
References lar::util::ChiSquareAccumulator< F, T >::fN.
|
inline |
Returns the value of χ² currently accumulated.
Definition at line 81 of file ChiSquareAccumulator.h.
References lar::util::ChiSquareAccumulator< F, T >::chiSquare().
|
inline |
Returns the value of χ² currently accumulated.
Definition at line 80 of file ChiSquareAccumulator.h.
References lar::util::ChiSquareAccumulator< F, T >::chiSquare().
|
inlinestaticprivate |
The usual square function.
Definition at line 140 of file ChiSquareAccumulator.h.
Referenced by lar::util::ChiSquareAccumulator< F, T >::add().
|
inlinestaticprivate |
Normal variable.
Definition at line 136 of file ChiSquareAccumulator.h.
Referenced by lar::util::ChiSquareAccumulator< F, T >::add().
|
private |
Accumulated χ² value.
Definition at line 131 of file ChiSquareAccumulator.h.
Referenced by lar::util::ChiSquareAccumulator< F, T >::add(), lar::util::ChiSquareAccumulator< F, T >::chiSquare(), and lar::util::ChiSquareAccumulator< F, T >::clear().
|
private |
Function for the expectation.
Definition at line 133 of file ChiSquareAccumulator.h.
Referenced by lar::util::ChiSquareAccumulator< F, T >::expected().
|
private |
Number of data entries.
Definition at line 130 of file ChiSquareAccumulator.h.
Referenced by lar::util::ChiSquareAccumulator< F, T >::add(), lar::util::ChiSquareAccumulator< F, T >::clear(), and lar::util::ChiSquareAccumulator< F, T >::N().