CMS 3D CMS Logo

Accumulator.cc
Go to the documentation of this file.
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;
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 
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 }
void addEntry(double value, double weight=1.)
Definition: Accumulator.cc:6
double mean() const
Definition: Accumulator.cc:14
double weightedSum_
Definition: Accumulator.h:31
Definition: weight.py:1
unsigned long n_
Definition: Accumulator.h:33
unsigned long nEntries() const
Definition: Accumulator.h:26
double sigma() const
Definition: Accumulator.h:22
double sum_
Definition: Accumulator.h:29
double weightedMean() const
Definition: Accumulator.cc:22
Definition: value.py:1
std::ostream & operator<<(std::ostream &os, const Accumulator &stat)
Definition: Accumulator.cc:24
double variance() const
Definition: Accumulator.cc:16
double sumOfSquares_
Definition: Accumulator.h:30
double sumOfWeights_
Definition: Accumulator.h:32