CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 }
list numerator
Definition: cuy.py:484
void addEntry(double value, double weight=1.)
Definition: Accumulator.cc:6
double mean() const
Definition: Accumulator.cc:14
double weightedSum_
Definition: Accumulator.h:31
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
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
list denominator
Definition: cuy.py:485
double weightedMean() const
Definition: Accumulator.cc:22
double variance() const
Definition: Accumulator.cc:16
int weight
Definition: histoStyle.py:51
double sumOfSquares_
Definition: Accumulator.h:30
double sumOfWeights_
Definition: Accumulator.h:32