Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:06

0001 #ifndef Statistics_Accumulator_h
0002 #define Statistics_Accumulator_h
0003 
0004 /** For validation purposes.  This program
0005     calculates mean and RMS of a distribution
0006 
0007   \Author Rick Wilkinson
0008 */
0009 #include <iosfwd>
0010 #include <cmath>
0011 
0012 class Accumulator {
0013 public:
0014   Accumulator();
0015 
0016   void addEntry(double value, double weight = 1.);
0017 
0018   double mean() const;
0019 
0020   double variance() const;
0021 
0022   double sigma() const { return std::sqrt(variance()); }
0023 
0024   double weightedMean() const;
0025 
0026   unsigned long nEntries() const { return n_; }
0027 
0028 private:
0029   double sum_;
0030   double sumOfSquares_;
0031   double weightedSum_;
0032   double sumOfWeights_;
0033   unsigned long n_;
0034 };
0035 
0036 std::ostream& operator<<(std::ostream& os, const Accumulator& stat);
0037 
0038 #endif