G4StatDouble Class Reference

#include <G4StatDouble.hh>


Public Member Functions

 G4StatDouble ()
virtual ~G4StatDouble ()
void reset ()
void fill (G4double x, G4double weight=1.)
void scale (G4double)
G4double mean () const
G4double rms ()
G4double mean (G4double ext_sum_w) const
G4double rms (G4double ext_sum_w, G4int ext_n)
G4int n () const
G4double sum_w () const
G4double sum_w2 () const
G4double sum_wx () const
G4double sum_wx2 () const

Protected Member Functions

G4double rms (G4double sum_wx, G4double sum_wx2, G4double sum_w, G4int n)

Protected Attributes

G4double m_sum_wx
G4double m_sum_wx2
G4int m_n
G4double m_sum_w
G4double m_sum_w2
G4double m_scale


Detailed Description

Definition at line 46 of file G4StatDouble.hh.


Constructor & Destructor Documentation

G4StatDouble::G4StatDouble (  ) 

Definition at line 40 of file G4StatDouble.cc.

References reset().

00041 {
00042   reset();
00043 }

G4StatDouble::~G4StatDouble (  )  [virtual]

Definition at line 55 of file G4StatDouble.cc.

00056 {}


Member Function Documentation

void G4StatDouble::fill ( G4double  x,
G4double  weight = 1. 
)

Definition at line 58 of file G4StatDouble.cc.

References G4cout, G4endl, m_n, m_sum_w, m_sum_w2, m_sum_wx, and m_sum_wx2.

00059 {
00060   m_sum_wx  += value * weight;
00061   m_sum_wx2 += value * value * weight;
00062   m_n++;
00063   m_sum_w   += weight;
00064   m_sum_w2  += weight * weight;
00065 
00066   if (weight <= 0.)
00067   {
00068     G4cout << "[G4StatDouble::fill] WARNING: weight<=0. "
00069            << weight << G4endl;
00070   }
00071 }

G4double G4StatDouble::mean ( G4double  ext_sum_w  )  const

Definition at line 88 of file G4StatDouble.cc.

References m_sum_w, and mean().

00089 {
00090   G4double factor = 0.;
00091     // factor to rescale the Mean for the requested number
00092     // of events (or sum of weights) ext_sum_w
00093 
00094   if (ext_sum_w > 0)
00095   {
00096     factor  = m_sum_w;
00097     factor /= ext_sum_w;
00098   }
00099   return mean() * factor;
00100 
00101 }

G4double G4StatDouble::mean (  )  const

Definition at line 78 of file G4StatDouble.cc.

References m_scale, m_sum_w, and m_sum_wx.

Referenced by mean().

00079 {
00080   G4double mean_val = 0.;
00081   if (m_sum_w > 0.)
00082   {
00083     mean_val = m_sum_wx / m_sum_w;
00084   }
00085   return m_scale * mean_val;
00086 }

G4int G4StatDouble::n (  )  const [inline]

Definition at line 70 of file G4StatDouble.hh.

References m_n.

00070 { return m_n; }

void G4StatDouble::reset (  ) 

Definition at line 45 of file G4StatDouble.cc.

References m_n, m_scale, m_sum_w, m_sum_w2, m_sum_wx, and m_sum_wx2.

Referenced by G4StatDouble().

00046 {
00047   m_sum_wx  = 0.;
00048   m_sum_wx2 = 0.;
00049   m_n       = 0;
00050   m_sum_w   = 0.;
00051   m_sum_w2  = 0.;
00052   m_scale   = 1.;
00053 }

G4double G4StatDouble::rms ( G4double  sum_wx,
G4double  sum_wx2,
G4double  sum_w,
G4int  n 
) [protected]

Definition at line 103 of file G4StatDouble.cc.

References m_scale.

00105 {
00106   G4double vrms;
00107   if (nn > 1)
00108   {
00109     G4double vmean = ssum_wx / ssum_w;
00110     G4double xn = nn;
00111     G4double tmp = 
00112       // from GNU Scientific Library. This part is equivalent to N/(N-1)
00113       // when w_i = w
00114       // ((m_sum_w * m_sum_w) / (m_sum_w * m_sum_w - m_sum_w2)) 
00115 
00116       // from NIST "DATAPLOT Reference manual", Page 2-66 
00117       // http://www.itl.nist.gov/div898/software/dataplot/refman2/ch2/weightsd.pdf
00118       // rewritten based on: SUM[w(x-m)^2]/SUM[w] = SUM[wx^2]/SUM[w] - m^2
00119       // and dividing it by sqrt[n] to go from rms of distribution to the
00120       // rms of the mean value
00121 
00122       (1. / (xn - 1))
00123       * ((ssum_wx2 / ssum_w) - (vmean * vmean));
00124 
00125     if (tmp < 0.) tmp=0.; // this avoids observed computation problem
00126     vrms = std::sqrt( tmp );
00127 //  G4cout << "[G4StatDoubleElement::rms] m_sum_wx: " << m_sum_wx
00128 //         << "  m_sum_wx2: " << m_sum_wx2 << "  m_sum_w: " << m_sum_w
00129 //         << "  m_n: " << m_n << "  tmp: " << tmp<< "  rms: " << rms
00130 //         << G4endl;
00131 //  G4cout << "[G4StatDoubleElement::rms] (m_n / (m_n - 1)): " << (xn/(xn - 1))
00132 //         << "  (m_sum_wx2 / m_sum_w): " << (m_sum_wx2 / m_sum_w) 
00133 //         << "  (mean * mean): " << (mean * mean) 
00134 //         << "  ((m_sum_wx2 / m_sum_w) - (mean * mean)): "
00135 //         << ((m_sum_wx2 / m_sum_w) - (mean * mean)) 
00136 //         << G4endl;
00137   }
00138   else
00139   {
00140     vrms = -1.;
00141   }
00142   return vrms * m_scale;
00143 }

G4double G4StatDouble::rms ( G4double  ext_sum_w,
G4int  ext_n 
)

Definition at line 153 of file G4StatDouble.cc.

References m_sum_wx, m_sum_wx2, and rms().

00154 {
00155   // this method computes the RMS with sum_w and n coming from outside:
00156   // ext_sum_w and ext_n:
00157   // this means that the result is normalised to the external events
00158   // it is useful when, given a number ext_n of events with sum of the weights
00159   // ext_sum_w, only m_n (with sum of weights m_sum_w) are actually accumulated
00160   // in the internal summation (e.g. for a dose variable in a volume, because
00161   // only a few particles reach that volume) 
00162 
00163   return rms(m_sum_wx, m_sum_wx2, ext_sum_w, ext_n);
00164 }

G4double G4StatDouble::rms (  ) 

Definition at line 145 of file G4StatDouble.cc.

References m_n, m_sum_w, m_sum_wx, and m_sum_wx2.

Referenced by rms().

00146 {
00147   // this method computes the RMS with "all internal" parameters:
00148   // all the sums are the internal ones: m_sum_wx, m_sum_wx2, m_sum_w, m_n
00149 
00150   return rms(m_sum_wx, m_sum_wx2, m_sum_w, m_n);
00151 }

void G4StatDouble::scale ( G4double   ) 

Definition at line 73 of file G4StatDouble.cc.

References m_scale.

00074 {
00075   m_scale = m_scale * value;
00076 }

G4double G4StatDouble::sum_w (  )  const [inline]

Definition at line 71 of file G4StatDouble.hh.

References m_sum_w.

00071 { return m_sum_w; }

G4double G4StatDouble::sum_w2 (  )  const [inline]

Definition at line 72 of file G4StatDouble.hh.

References m_sum_w2.

00072 { return m_sum_w2; }

G4double G4StatDouble::sum_wx (  )  const [inline]

Definition at line 73 of file G4StatDouble.hh.

References m_sum_wx.

00073 { return m_sum_wx; }

G4double G4StatDouble::sum_wx2 (  )  const [inline]

Definition at line 74 of file G4StatDouble.hh.

References m_sum_wx2.

00074 { return m_sum_wx2; }


Field Documentation

G4int G4StatDouble::m_n [protected]

Definition at line 84 of file G4StatDouble.hh.

Referenced by fill(), n(), reset(), and rms().

G4double G4StatDouble::m_scale [protected]

Definition at line 87 of file G4StatDouble.hh.

Referenced by mean(), reset(), rms(), and scale().

G4double G4StatDouble::m_sum_w [protected]

Definition at line 85 of file G4StatDouble.hh.

Referenced by fill(), mean(), reset(), rms(), and sum_w().

G4double G4StatDouble::m_sum_w2 [protected]

Definition at line 86 of file G4StatDouble.hh.

Referenced by fill(), reset(), and sum_w2().

G4double G4StatDouble::m_sum_wx [protected]

Definition at line 82 of file G4StatDouble.hh.

Referenced by fill(), mean(), reset(), rms(), and sum_wx().

G4double G4StatDouble::m_sum_wx2 [protected]

Definition at line 83 of file G4StatDouble.hh.

Referenced by fill(), reset(), rms(), and sum_wx2().


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:25 2013 for Geant4 by  doxygen 1.4.7