CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Accumulator.cc
Go to the documentation of this file.
2 #include <ostream>
3 
5 : sum_(0.),
6  sumOfSquares_(0.),
7  weightedSum_(0.),
8  sumOfWeights_(0.),
9  n_(0)
10 {
11 }
12 
13 
14 void Accumulator::addEntry(double value, double weight) {
15  sum_ += value;
16  sumOfSquares_ += (value*value);
17  weightedSum_ += value*weight;
19  ++n_;
20 }
21 
22 
23 double Accumulator::mean() const {
24  return sum_/n_;
25 }
26 
27 
28 double Accumulator::variance() const {
29  double numerator = sumOfSquares_ - sum_*mean();
30  unsigned long denominator = n_-1;
31  return numerator/denominator;
32 }
33 
34 
35 double Accumulator::weightedMean() const {
36  return weightedSum_ / sumOfWeights_;
37 }
38 
39 
40 std::ostream& operator<<(std::ostream & os,const Accumulator & stat) {
41  os << "entries: " << stat.nEntries();
42  if(stat.nEntries() > 0) {
43  os << " Mean: " << stat.mean();
44  }
45  if(stat.nEntries() > 1) {
46  os << " Sigma: " << stat.sigma();
47  }
48  return os;
49 }
50 
51 
list numerator
Definition: cuy.py:483
void addEntry(double value, double weight=1.)
Definition: Accumulator.cc:14
double mean() const
Definition: Accumulator.cc:23
double weightedSum_
Definition: Accumulator.h:32
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
unsigned long n_
Definition: Accumulator.h:34
unsigned long nEntries() const
Definition: Accumulator.h:27
double sigma() const
Definition: Accumulator.h:23
double sum_
Definition: Accumulator.h:30
list denominator
Definition: cuy.py:484
double weightedMean() const
Definition: Accumulator.cc:35
double variance() const
Definition: Accumulator.cc:28
int weight
Definition: histoStyle.py:50
double sumOfSquares_
Definition: Accumulator.h:31
double sumOfWeights_
Definition: Accumulator.h:33