herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
Statistic.h
1// -*- C++ -*-
2//
3// Statistic.h is a part of Herwig - A multi-purpose Monte Carlo event generator
4// Copyright (C) 2002-2019 The Herwig Collaboration
5//
6// Herwig is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef HERWIG_Statistic_H
10#define HERWIG_Statistic_H
11#include <cmath>
12
13//
14// This is the declaration of the Statistic class.
15//
16
17namespace Herwig {
18
23class Statistic {
24
25public:
26
30 Statistic() : _n(0), _xsum(0.), _x2sum(0.),
31 _min(-1e100), _max(1e100) {}
32
36 double minimum() const { return _min; }
37
41 double maximum() const { return _max; }
42
46 void operator+=(double input)
47 {
48 ++_n;
49 _xsum += input;
50 _x2sum += input * input;
51 if (_min > input || _n == 1) _min = input;
52 if (_max < input || _n == 1) _max = input;
53 }
54
58 unsigned int numberOfPoints() const { return _n; }
59
63 double mean() const
64 {
65 return _n > 0 ? _xsum / _n : 0.;
66 }
67
75 double mean_stdDev() const { return std::sqrt(mean_var()); }
76
84 double mean_var() const
85 {
86 return _n > 1 ? var() / _n : 0.;
87 }
88
92 double stdDev() const { return std::sqrt(var()); }
93
97 double var() const
98 {
99 return _n > 1 ? ( _x2sum - _xsum*_xsum/_n ) / ( _n - 1 ) : 0.;
100 }
101
105 double total() const { return _xsum; }
106
107private:
108
112 unsigned int _n;
113
117 double _xsum;
118
122 double _x2sum;
123
127 double _min;
128
132 double _max;
133};
134
135}
136
137#endif /* HERWIG_Statistic_H */
The Statistic class is a simple class designed to store a variable for statistical analysis.
Definition: Statistic.h:23
double _max
The maximum value.
Definition: Statistic.h:132
double minimum() const
The minimum value.
Definition: Statistic.h:36
double mean_stdDev() const
Error on the mean estimate.
Definition: Statistic.h:75
double mean_var() const
Variance on the mean estimate.
Definition: Statistic.h:84
double _x2sum
Sum of the squares of the values.
Definition: Statistic.h:122
double total() const
Total entry.
Definition: Statistic.h:105
unsigned int _n
Number of entries.
Definition: Statistic.h:112
double maximum() const
The maximum value.
Definition: Statistic.h:41
double _xsum
Sum of the values.
Definition: Statistic.h:117
double _min
The minimum value.
Definition: Statistic.h:127
unsigned int numberOfPoints() const
Number of points.
Definition: Statistic.h:58
double mean() const
Mean.
Definition: Statistic.h:63
void operator+=(double input)
Operator to add another point.
Definition: Statistic.h:46
double stdDev() const
Standard Deviation.
Definition: Statistic.h:92
Statistic()
The default constructor.
Definition: Statistic.h:30
double var() const
Variance.
Definition: Statistic.h:97
-*- C++ -*-