 |
Belle II Software
release-05-01-25
|
36 template<
int N = 1,
class RealType =
double>
38 static_assert(N > 0,
"Number of parameters, N, must be positive");
50 for (
int i = 0; i < N; i++)
52 for (
int i = 0; i < N * (N + 1) / 2; i++)
63 static_assert(
sizeof...(values) == N,
64 "Number of arguments must be equal N");
66 addValue<0>(weight, values...);
73 template<
class... T>
void add(T... values)
79 void add(
const CalcMeanCov<N, RealType>& other)
84 for (
int i = 0; i < N; ++i) {
87 for (
int j = i; j < N; ++j) {
93 m_mean[i] += other.m_entries * delta / n;
134 if (i == j)
return 1.0;
156 static_assert(i >= 0 && i < N,
"index i out of range");
162 static_assert(i >= 0 && i < N,
"index i out of range");
163 static_assert(j >= 0 && j < N,
"index j out of range");
170 if (i == j)
return 1.0;
172 return getCovariance<i, j>() / (getStddev<i>() * getStddev<j>());
177 return getCovariance<i, i>();
182 return std::sqrt(getVariance<i>());
200 template<
int i,
class... T>
205 updateCov<i, i>(weight, delta, x, values...);
209 addValue < i + 1 > (weight, values...);
223 template<
int i,
int j,
class... T>
230 updateCov < i, j + 1 > (weight, delta, values...);
244 for (
int i = 0; i < N; ++i) {
247 for (
int j = i; j < N; ++j) {
262 constexpr
int getIndex(
unsigned int i,
unsigned int j)
const
265 return (i < j) ? ((j + 1) * j / 2 + i) : ((i + 1) * i / 2 + j);
void add(T... values)
Update mean and covariance by adding a new entry.
value_type getSum() const
Return the weighted sum values for parameter i.
value_type getCovariance() const
Return the covariance between parameters i and j.
value_type getEntries() const
Return the number of entries.
void updateCov(value_type weight, value_type delta, value_type x, T... values)
Update covariance between parameters i and j.
void addValue(value_type weight, value_type x, T... values)
Add a single value for parameter i and update mean and covariance.
void addWeighted(value_type weight, T... values)
Update mean and covariance by adding a new, weighted entry.
CalcMeanCov()
default constructor.
void addArray(value_type *values)
Update mean and covariance by adding a new entry.
Abstract base class for different kinds of events.
value_type getMean() const
Return the mean for parameter i.
constexpr int getIndex(unsigned int i, unsigned int j) const
Access element in triangular matrix including diagonal elements.
value_type getVariance() const
Return the variance for paramter i.
value_type getStddev() const
Return the standard deviation for parameter i.
void addArrayValues(value_type weight, value_type *x)
Add a new set of values and update mean and covariance.
value_type m_entries
Store the sum of weights.
value_type getCorrelation() const
Return the correlation coefficient between parameters i and j.
value_type m_mean[N]
Store the mean values for all parameters.
value_type m_covariance[N *(N+1)/2]
Store the triangular covariance matrix for all parameters in continous memory.
void clear()
Clear all values.
RealType value_type
type of float variable to use for calculations and storage
void addWeightedArray(value_type weight, value_type *values)
Update mean and covarianced by adding a new weighted entry.