8#include <framework/utilities/TestHelpers.h>
9#include <framework/utilities/CalcMeanCov.h>
13#include <gtest/gtest.h>
23 constexpr int N = 10000;
24 std::vector<double> values(N, 0);
27 for (
double gmean : { -5.0, 0.0, 1.0, 3.5, 150.}) {
28 for (
double gsigma : {0.1, 1.0, 4.2, 25.}) {
29 double sum1(0), sum2(0), sum3(0);
30 for (
int i = 0; i < N; ++i) {
31 const double x = gRandom->Gaus(gmean, gsigma);
36 const double mean = sum1 / N;
37 for (
auto x : values) {
38 const double d = x - mean;
42 const double variance = (sum2 - sum3 * sum3 / N) / N;
43 const double sigma = std::sqrt(variance);
46 EXPECT_FLOAT_EQ(mean, meancov.
getMean());
47 EXPECT_FLOAT_EQ(sigma, meancov.
getStddev());
48 EXPECT_FLOAT_EQ(sum1, meancov.
getSum());
61 constexpr int N = 10001;
66 for (
int i = 0; i < N; ++i) {
67 meancov.
add(i + 1, i + 13.5, N - i);
69 const double sum1 = (N * N + N) / 2.;
70 const double sum2 = sum1 + 12.5 * N;
71 const double mean1 = (N + 1.0) / 2;
72 const double mean2 = (13.5 + N + 12.5) / 2;
73 const double varia = (N * N - 1.) / 12;
74 const double sigma = std::sqrt(varia);
77 EXPECT_DOUBLE_EQ(mean1, meancov.
getMean<0>());
78 EXPECT_DOUBLE_EQ(mean2, meancov.
getMean<1>());
79 EXPECT_DOUBLE_EQ(mean1, meancov.
getMean<2>());
80 EXPECT_DOUBLE_EQ(sigma, meancov.
getStddev<0>());
81 EXPECT_DOUBLE_EQ(sigma, meancov.
getStddev<1>());
82 EXPECT_DOUBLE_EQ(sigma, meancov.
getStddev<2>());
83 EXPECT_DOUBLE_EQ(sum1, meancov.
getSum<0>());
84 EXPECT_DOUBLE_EQ(sum2, meancov.
getSum<1>());
85 EXPECT_DOUBLE_EQ(sum1, meancov.
getSum<2>());
103 for (
double n : {10, 13, 25}) {
104 for (
double p : {0.1, 0.5, 0.75}) {
105 for (
int k = 0; k <= n; ++k) {
106 const double b = TMath::Binomial(n, k) * std::pow(p, k) * std::pow(1 - p, n - k);
109 EXPECT_DOUBLE_EQ(1.0, meancov.
getEntries()) <<
"n: " << n <<
", p: " << p;
110 EXPECT_DOUBLE_EQ(n * p, meancov.
getMean()) <<
"n: " << n <<
", p: " << p;
111 EXPECT_DOUBLE_EQ(n * p * (1 - p), meancov.
getVariance()) <<
"n: " << n <<
", p: " << p;
123 for (
int i = 0; i < 10000; ++i) {
124 const double weight = gRandom->Uniform(0, 10);
125 values[0] = gRandom->Gaus(0, 1);
126 values[1] = gRandom->Gaus(values[0], 1);
127 values[2] = gRandom->Uniform(-5, 5);
128 templated.
addWeighted(weight, values[0], values[1], values[2]);
150 constexpr int N = 10000;
155 for (
double gmean : { -5.0, 0.0, 1.0, 3.5, 150.}) {
156 for (
double gsigma : {0.1, 1.0, 4.2, 25.}) {
157 for (
int i = 0; i < N; ++i) {
158 const double x = gRandom->Gaus(gmean, gsigma);
Class to calculate mean and and covariance between a number of parameters on running data without sto...
void addWeighted(value_type weight, T... values)
Update mean and covariance by adding a new, weighted entry.
value_type getVariance(int i) const
Return the variance for paramter i.
value_type getCorrelation(int i, int j) const
Return the correlation coefficient between parameters i and j.
value_type getStddev(int i) const
Return the standard deviation for parameter i.
value_type getMean(int i) const
Return the mean for parameter i.
value_type getCovariance(int i, int j) const
Return the covariance between parameters i and j.
void addWeightedArray(value_type weight, value_type *values)
Update mean and covarianced by adding a new weighted entry.
value_type getSum(int i) const
Return the weighted sum values for parameter i.
void add(T... values)
Update mean and covariance by adding a new entry.
void clear()
Clear all values.
value_type getEntries() const
Return the number of entries.
Abstract base class for different kinds of events.