CMS 3D CMS Logo

Accumulator Class Reference

For validation purposes. More...

#include <CommonTools/Statistics/interface/Accumulator.h>

List of all members.

Public Member Functions

 Accumulator ()
void addEntry (double value, double weight=1.)
double mean () const
unsigned long nEntries () const
double sigma () const
double variance () const
double weightedMean () const

Private Attributes

unsigned long n_
double sum_
double sumOfSquares_
double sumOfWeights_
double weightedSum_


Detailed Description

For validation purposes.

This program calculates mean and RMS of a distribution

Rick Wilkinson

Definition at line 12 of file Accumulator.h.


Constructor & Destructor Documentation

Accumulator::Accumulator (  ) 

Definition at line 5 of file Accumulator.cc.

00006 :  sum_(0.),
00007    sumOfSquares_(0.),
00008    weightedSum_(0.),
00009    sumOfWeights_(0.),
00010    n_(0)
00011 {
00012 }


Member Function Documentation

void Accumulator::addEntry ( double  value,
double  weight = 1. 
)

Definition at line 15 of file Accumulator.cc.

References n_, sum_, sumOfSquares_, sumOfWeights_, and weightedSum_.

00015                                                       {
00016   sum_ += value;
00017   sumOfSquares_ += (value*value);
00018   weightedSum_ += value*weight;
00019   sumOfWeights_ += weight;
00020   ++n_;
00021 }

double Accumulator::mean (  )  const

Definition at line 24 of file Accumulator.cc.

References n_, and sum_.

Referenced by operator<<(), and variance().

00024                                {
00025   return sum_/n_;
00026 }

unsigned long Accumulator::nEntries (  )  const [inline]

Definition at line 27 of file Accumulator.h.

References n_.

Referenced by operator<<().

00027 {return n_;}

double Accumulator::sigma (  )  const [inline]

Definition at line 23 of file Accumulator.h.

References funct::sqrt(), and variance().

Referenced by operator<<().

00023 {return std::sqrt(variance());}

double Accumulator::variance (  )  const

Definition at line 29 of file Accumulator.cc.

References mean(), n_, sum_, and sumOfSquares_.

Referenced by sigma().

00029                                    {
00030   double numerator = sumOfSquares_ - sum_*mean();
00031   unsigned long denominator = n_-1;
00032   return numerator/denominator;
00033 }

double Accumulator::weightedMean (  )  const

Definition at line 36 of file Accumulator.cc.

References sumOfWeights_, and weightedSum_.

00036                                         {
00037   return weightedSum_ / sumOfWeights_;
00038 }


Member Data Documentation

unsigned long Accumulator::n_ [private]

Definition at line 34 of file Accumulator.h.

Referenced by addEntry(), mean(), nEntries(), and variance().

double Accumulator::sum_ [private]

Definition at line 30 of file Accumulator.h.

Referenced by addEntry(), mean(), and variance().

double Accumulator::sumOfSquares_ [private]

Definition at line 31 of file Accumulator.h.

Referenced by addEntry(), and variance().

double Accumulator::sumOfWeights_ [private]

Definition at line 33 of file Accumulator.h.

Referenced by addEntry(), and weightedMean().

double Accumulator::weightedSum_ [private]

Definition at line 32 of file Accumulator.h.

Referenced by addEntry(), and weightedMean().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:13:51 2009 for CMSSW by  doxygen 1.5.4