Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:28

0001 // -*- C++ -*-
0002 //
0003 // Statistic.h is a part of Herwig - A multi-purpose Monte Carlo event generator
0004 // Copyright (C) 2002-2019 The Herwig Collaboration
0005 //
0006 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef HERWIG_Statistic_H
0010 #define HERWIG_Statistic_H
0011 #include <cmath>
0012 
0013 //
0014 // This is the declaration of the Statistic class.
0015 //
0016 
0017 namespace Herwig {
0018 
0019 /**
0020  * The Statistic class is a simple class designed to 
0021  * store a variable for statistical analysis
0022  */
0023 class Statistic {
0024 
0025 public:
0026 
0027   /**
0028    * The default constructor.
0029    */
0030   Statistic() : _n(0), _xsum(0.), _x2sum(0.),
0031         _min(-1e100), _max(1e100) {}
0032 
0033   /**
0034    *  The minimum value
0035    */
0036   double minimum() const { return _min; }
0037 
0038   /**
0039    *  The maximum value
0040    */
0041   double maximum() const { return _max; }
0042 
0043   /**
0044    *  Operator to add another point
0045    */
0046   void operator+=(double input) 
0047   {
0048     ++_n;
0049     _xsum  += input;
0050     _x2sum += input * input;
0051     if (_min > input || _n == 1) _min = input;
0052     if (_max < input || _n == 1) _max = input;
0053   }
0054 
0055   /**
0056    *  Number of points
0057    */
0058   unsigned int numberOfPoints() const { return _n; }
0059   
0060   /**
0061    *  Mean
0062    */
0063   double mean() const 
0064   {
0065     return _n > 0  ?  _xsum / _n : 0.; 
0066   }
0067 
0068   /**
0069    *  Error on the mean estimate. Needed for example for Profile
0070    *  histograms, where this should be used to compute a chi2
0071    *  or significance level of deviation to data, rather than stdDeV.
0072    *  This is obvious because the error on the estimate should go to 
0073    *  zero for N -> infinity.
0074    */
0075   double mean_stdDev() const { return std::sqrt(mean_var()); }
0076 
0077   /**
0078    *  Variance on the mean estimate. Needed for example for Profile
0079    *  histograms, where this should be used to compute a chi2
0080    *  or significance level of deviation to data, rather than stdDeV
0081    *  This is obvious because the error on the estimate should go to 
0082    *  zero for N -> infinity.
0083    */
0084   double mean_var() const 
0085   {
0086     return _n > 1  ?  var() / _n : 0.; 
0087   }
0088 
0089   /**
0090    *  Standard Deviation
0091    */
0092   double stdDev() const { return std::sqrt(var()); }
0093 
0094   /**
0095    *  Variance
0096    */
0097   double var() const 
0098   { 
0099     return _n > 1  ?  ( _x2sum - _xsum*_xsum/_n ) / ( _n - 1 ) : 0.; 
0100   }
0101 
0102   /**
0103    *  Total entry
0104    */
0105   double total() const { return _xsum; }
0106 
0107 private:
0108 
0109   /**
0110    *   Number of entries
0111    */
0112   unsigned int _n;
0113 
0114   /**
0115    *  Sum of the values
0116    */ 
0117   double _xsum;
0118 
0119   /**
0120    *  Sum of the squares of the values
0121    */
0122   double _x2sum;
0123 
0124   /**
0125    *  The minimum value
0126    */
0127   double _min;
0128   
0129   /**
0130    *  The maximum value
0131    */
0132   double _max;
0133 };
0134 
0135 }
0136 
0137 #endif /* HERWIG_Statistic_H */