CommonTools
Statistics
src
Accumulator.cc
Go to the documentation of this file.
1
#include "
CommonTools/Statistics/interface/Accumulator.h
"
2
#include <ostream>
3
4
Accumulator::Accumulator
() : sum_(0.), sumOfSquares_(0.), weightedSum_(0.), sumOfWeights_(0.), n_(0) {}
5
6
void
Accumulator::addEntry
(
double
value
,
double
weight
) {
7
sum_
+=
value
;
8
sumOfSquares_
+= (
value
*
value
);
9
weightedSum_
+=
value
*
weight
;
10
sumOfWeights_
+=
weight
;
11
++
n_
;
12
}
13
14
double
Accumulator::mean
()
const
{
return
sum_
/
n_
; }
15
16
double
Accumulator::variance
()
const
{
17
double
numerator
=
sumOfSquares_
-
sum_
*
mean
();
18
unsigned
long
denominator
=
n_
- 1;
19
return
numerator
/
denominator
;
20
}
21
22
double
Accumulator::weightedMean
()
const
{
return
weightedSum_
/
sumOfWeights_
; }
23
24
std::ostream&
operator<<
(std::ostream& os,
const
Accumulator
&
stat
) {
25
os <<
"entries: "
<<
stat
.nEntries();
26
if
(
stat
.nEntries() > 0) {
27
os <<
" Mean: "
<<
stat
.mean();
28
}
29
if
(
stat
.nEntries() > 1) {
30
os <<
" Sigma: "
<<
stat
.sigma();
31
}
32
return
os;
33
}
Accumulator::weightedSum_
double weightedSum_
Definition:
Accumulator.h:31
Accumulator::variance
double variance() const
Definition:
Accumulator.cc:16
Accumulator::sumOfSquares_
double sumOfSquares_
Definition:
Accumulator.h:30
mps_merge.weight
weight
Definition:
mps_merge.py:88
Accumulator::Accumulator
Accumulator()
Definition:
Accumulator.cc:4
operator<<
std::ostream & operator<<(std::ostream &os, const Accumulator &stat)
Definition:
Accumulator.cc:24
Accumulator::addEntry
void addEntry(double value, double weight=1.)
Definition:
Accumulator.cc:6
Accumulator::n_
unsigned long n_
Definition:
Accumulator.h:33
hgcalPlots.stat
stat
Definition:
hgcalPlots.py:1111
Accumulator::sum_
double sum_
Definition:
Accumulator.h:29
Accumulator::mean
double mean() const
Definition:
Accumulator.cc:14
value
Definition:
value.py:1
HLTTauDQMOffline_cfi.numerator
numerator
Definition:
HLTTauDQMOffline_cfi.py:194
HLTTauDQMOffline_cfi.denominator
denominator
Definition:
HLTTauDQMOffline_cfi.py:195
Accumulator::weightedMean
double weightedMean() const
Definition:
Accumulator.cc:22
relativeConstraints.value
value
Definition:
relativeConstraints.py:53
Accumulator::sumOfWeights_
double sumOfWeights_
Definition:
Accumulator.h:32
Accumulator.h
weight
Definition:
weight.py:1
Accumulator
Definition:
Accumulator.h:12
Generated for CMSSW Reference Manual by
1.8.16