ATLAS Offline Software
MeanAndRMS.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MeanAndRMS_h
6 #define MeanAndRMS_h
7 
8 #include <math.h>
9 
10 class MeanAndRMS {
11 public :
12  MeanAndRMS():m_w(0),m_wx(0),m_wx2(0) {};
13  MeanAndRMS(const double xadd, const double weight=1):m_w(weight),m_wx(weight*xadd),m_wx2(weight*xadd*xadd) {};
15 
16  MeanAndRMS& add(double xadd,double weight=1) {m_wx+=weight*xadd;m_wx2+=weight*xadd*xadd;m_w+=weight;return *this;};
17  MeanAndRMS& operator+=(double xadd) {return add(xadd);};
18  MeanAndRMS& operator-=(double xadd) {return add(-xadd);};
19  MeanAndRMS& operator=(const MeanAndRMS& ref) {m_w=ref.m_w;m_wx=ref.m_wx;m_wx2=ref.m_wx2;return *this;};
20 
21  double sum_weight() const {return m_w;};
22  double mean() const {if(m_w!=0) return m_wx/m_w; else return 0;};
23  double mean2() const {double x=mean();return x*x;};
24  double rms2() const {if(m_w!=0) return m_wx2/m_w - mean2(); else return 0;};
25  double rms() const {double r2=rms2();if(r2>=0) return sqrt(r2); else return 0;};
26  double mean_error() const {if(m_w>0) return rms()/sqrt(m_w); else return 0;};
27  double rms_error() const {if(m_w>0) return rms()/sqrt(2*m_w); else return 0;};
28 
29  operator double() const { return mean(); }
30 protected:
31  double m_w;
32  double m_wx,m_wx2;
33 };
34 
35 #endif
36 
MeanAndRMS::add
MeanAndRMS & add(double xadd, double weight=1)
Definition: MeanAndRMS.h:16
MeanAndRMS::MeanAndRMS
MeanAndRMS()
Definition: MeanAndRMS.h:12
MeanAndRMS::rms
double rms() const
Definition: MeanAndRMS.h:25
MeanAndRMS::rms2
double rms2() const
Definition: MeanAndRMS.h:24
MeanAndRMS::rms_error
double rms_error() const
Definition: MeanAndRMS.h:27
MeanAndRMS::mean_error
double mean_error() const
Definition: MeanAndRMS.h:26
x
#define x
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MeanAndRMS::MeanAndRMS
MeanAndRMS(const MeanAndRMS &ref)
Definition: MeanAndRMS.h:14
MeanAndRMS::operator=
MeanAndRMS & operator=(const MeanAndRMS &ref)
Definition: MeanAndRMS.h:19
MeanAndRMS::sum_weight
double sum_weight() const
Definition: MeanAndRMS.h:21
MeanAndRMS
Definition: MeanAndRMS.h:10
MeanAndRMS::m_w
double m_w
Definition: MeanAndRMS.h:31
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
MeanAndRMS::operator-=
MeanAndRMS & operator-=(double xadd)
Definition: MeanAndRMS.h:18
MeanAndRMS::m_wx
double m_wx
Definition: MeanAndRMS.h:32
ref
const boost::regex ref(r_ef)
MeanAndRMS::mean
double mean() const
Definition: MeanAndRMS.h:22
MeanAndRMS::mean2
double mean2() const
Definition: MeanAndRMS.h:23
MeanAndRMS::m_wx2
double m_wx2
Definition: MeanAndRMS.h:32
MeanAndRMS::operator+=
MeanAndRMS & operator+=(double xadd)
Definition: MeanAndRMS.h:17
MeanAndRMS::MeanAndRMS
MeanAndRMS(const double xadd, const double weight=1)
Definition: MeanAndRMS.h:13