Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes
G4StatDouble Class Reference

#include <G4StatDouble.hh>

Public Member Functions

void add (const G4StatDouble *)
 
void fill (G4double x, G4double weight=1.)
 
 G4StatDouble ()
 
 G4StatDouble (const G4StatDouble &)=default
 
 G4StatDouble (G4double)
 
G4double mean () const
 
G4double mean (G4double ext_sum_w) const
 
G4int n () const
 
G4StatDoubleoperator+= (const G4double &rhs)
 
G4StatDoubleoperator+= (const G4StatDouble &rhs)
 
G4StatDoubleoperator= (const G4double &rhs)
 
G4StatDoubleoperator= (const G4StatDouble &rhs)
 
void reset ()
 
G4double rms ()
 
G4double rms (G4double ext_sum_w, G4int ext_n)
 
void scale (G4double)
 
G4double sum_w () const
 
G4double sum_w2 () const
 
G4double sum_wx () const
 
G4double sum_wx2 () const
 
virtual ~G4StatDouble ()
 

Protected Member Functions

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

Protected Attributes

G4int m_n = 0
 
G4double m_scale = 0.0
 
G4double m_sum_w = 0.0
 
G4double m_sum_w2 = 0.0
 
G4double m_sum_wx = 0.0
 
G4double m_sum_wx2 = 0.0
 

Detailed Description

Definition at line 40 of file G4StatDouble.hh.

Constructor & Destructor Documentation

◆ G4StatDouble() [1/3]

G4StatDouble::G4StatDouble ( )

Definition at line 33 of file G4StatDouble.cc.

33{ reset(); }

References reset().

◆ G4StatDouble() [2/3]

G4StatDouble::G4StatDouble ( G4double  x)

Definition at line 35 of file G4StatDouble.cc.

35{ fill(x); }
void fill(G4double x, G4double weight=1.)
Definition: G4StatDouble.cc:49

References fill().

◆ ~G4StatDouble()

G4StatDouble::~G4StatDouble ( )
virtual

Definition at line 47 of file G4StatDouble.cc.

47{}

◆ G4StatDouble() [3/3]

G4StatDouble::G4StatDouble ( const G4StatDouble )
default

Member Function Documentation

◆ add()

void G4StatDouble::add ( const G4StatDouble ptr)

Definition at line 151 of file G4StatDouble.cc.

152{
153 m_n += ptr->n();
154 m_sum_w += ptr->sum_w();
155 m_sum_w2 += ptr->sum_w2();
156 m_sum_wx += ptr->sum_wx();
157 m_sum_wx2 += ptr->sum_wx2();
158}
G4double m_sum_wx
G4double sum_w() const
Definition: G4StatDouble.hh:95
G4double m_sum_w
G4double sum_w2() const
Definition: G4StatDouble.hh:96
G4int n() const
Definition: G4StatDouble.hh:94
G4double m_sum_w2
G4double m_sum_wx2
G4double sum_wx2() const
Definition: G4StatDouble.hh:98
G4double sum_wx() const
Definition: G4StatDouble.hh:97

References m_n, m_sum_w, m_sum_w2, m_sum_wx, m_sum_wx2, n(), sum_w(), sum_w2(), sum_wx(), and sum_wx2().

Referenced by operator+=().

◆ fill()

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

Definition at line 49 of file G4StatDouble.cc.

50{
51 m_sum_wx += value * weight;
52 m_sum_wx2 += value * value * weight;
53 if(m_n < INT_MAX)
54 {
55 ++m_n;
56 }
57 m_sum_w += weight;
58 m_sum_w2 += weight * weight;
59
60 if(weight <= 0.)
61 {
62 G4cout << "[G4StatDouble::fill] WARNING: weight<=0. " << weight << G4endl;
63 }
64}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define INT_MAX
Definition: templates.hh:90

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

Referenced by G4StatDouble(), operator+=(), and operator=().

◆ mean() [1/2]

G4double G4StatDouble::mean ( ) const

Definition at line 68 of file G4StatDouble.cc.

69{
70 G4double mean_val = 0.;
71 if(m_sum_w > 0.)
72 {
73 mean_val = m_sum_wx / m_sum_w;
74 }
75 return m_scale * mean_val;
76}
double G4double
Definition: G4Types.hh:83
G4double m_scale

References m_scale, m_sum_w, and m_sum_wx.

Referenced by mean().

◆ mean() [2/2]

G4double G4StatDouble::mean ( G4double  ext_sum_w) const

Definition at line 78 of file G4StatDouble.cc.

79{
80 G4double factor = 0.;
81 // factor to rescale the Mean for the requested number
82 // of events (or sum of weights) ext_sum_w
83
84 if(ext_sum_w > 0)
85 {
86 factor = m_sum_w;
87 factor /= ext_sum_w;
88 }
89 return mean() * factor;
90}
G4double mean() const
Definition: G4StatDouble.cc:68

References m_sum_w, and mean().

◆ n()

G4int G4StatDouble::n ( ) const
inline

Definition at line 94 of file G4StatDouble.hh.

94{ return m_n; }

References m_n.

Referenced by add().

◆ operator+=() [1/2]

G4StatDouble & G4StatDouble::operator+= ( const G4double rhs)
inline

Definition at line 65 of file G4StatDouble.hh.

66 {
67 fill(rhs);
68 return *this;
69 }

References fill().

◆ operator+=() [2/2]

G4StatDouble & G4StatDouble::operator+= ( const G4StatDouble rhs)
inline

Definition at line 70 of file G4StatDouble.hh.

71 {
72 add(&rhs);
73 return *this;
74 }
void add(const G4StatDouble *)

References add().

◆ operator=() [1/2]

G4StatDouble & G4StatDouble::operator= ( const G4double rhs)
inline

Definition at line 49 of file G4StatDouble.hh.

50 {
51 reset();
52 fill(rhs);
53 return *this;
54 }

References fill(), and reset().

◆ operator=() [2/2]

G4StatDouble & G4StatDouble::operator= ( const G4StatDouble rhs)
inline

Definition at line 55 of file G4StatDouble.hh.

56 {
57 m_sum_wx = rhs.m_sum_wx;
58 m_sum_wx2 = rhs.m_sum_wx2;
59 m_n = rhs.m_n;
60 m_sum_w = rhs.m_sum_w;
61 m_sum_w2 = rhs.m_sum_w2;
62 m_scale = rhs.m_scale;
63 return *this;
64 }

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

◆ reset()

void G4StatDouble::reset ( )

Definition at line 37 of file G4StatDouble.cc.

38{
39 m_sum_wx = 0.;
40 m_sum_wx2 = 0.;
41 m_n = 0;
42 m_sum_w = 0.;
43 m_sum_w2 = 0.;
44 m_scale = 1.;
45}

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

Referenced by G4StatDouble(), and operator=().

◆ rms() [1/3]

G4double G4StatDouble::rms ( )

Definition at line 130 of file G4StatDouble.cc.

131{
132 // this method computes the RMS with "all internal" parameters:
133 // all the sums are the internal ones: m_sum_wx, m_sum_wx2, m_sum_w, m_n
134
135 return rms(m_sum_wx, m_sum_wx2, m_sum_w, m_n);
136}
G4double rms()

References m_n, m_sum_w, m_sum_wx, m_sum_wx2, and rms().

Referenced by rms().

◆ rms() [2/3]

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

Definition at line 138 of file G4StatDouble.cc.

139{
140 // this method computes the RMS with sum_w and n coming from outside:
141 // ext_sum_w and ext_n:
142 // this means that the result is normalised to the external events
143 // it is useful when, given a number ext_n of events with sum of the weights
144 // ext_sum_w, only m_n (with sum of weights m_sum_w) are actually accumulated
145 // in the internal summation (e.g. for a dose variable in a volume, because
146 // only a few particles reach that volume)
147
148 return rms(m_sum_wx, m_sum_wx2, ext_sum_w, ext_n);
149}

References m_sum_wx, m_sum_wx2, and rms().

◆ rms() [3/3]

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

Definition at line 92 of file G4StatDouble.cc.

94{
95 G4double vrms = 0.0;
96 if(nn > 1)
97 {
98 G4double vmean = ssum_wx / ssum_w;
99 G4double xn = nn;
100 G4double tmp =
101 // from GNU Scientific Library. This part is equivalent to N/(N-1)
102 // when w_i = w
103 // ((m_sum_w * m_sum_w) / (m_sum_w * m_sum_w - m_sum_w2))
104
105 // from NIST "DATAPLOT Reference manual", Page 2-66
106 // http://www.itl.nist.gov/div898/software/dataplot/refman2/ch2/weightsd.pdf
107 // rewritten based on: SUM[w(x-m)^2]/SUM[w] = SUM[wx^2]/SUM[w] - m^2
108 // and dividing it by sqrt[n] to go from rms of distribution to the
109 // rms of the mean value
110
111 (xn / (xn - 1)) * ((ssum_wx2 / ssum_w) - (vmean * vmean));
112
113 tmp = std::max(tmp, 0.0); // this avoids observed computation problem
114 vrms = std::sqrt(tmp);
115 // G4cout << "[G4StatDoubleElement::rms] m_sum_wx: " << m_sum_wx
116 // << " m_sum_wx2: " << m_sum_wx2 << " m_sum_w: " << m_sum_w
117 // << " m_n: " << m_n << " tmp: " << tmp<< " rms: " << rms
118 // << G4endl;
119 // G4cout << "[G4StatDoubleElement::rms] (m_n / (m_n - 1)): " << (xn/(xn -
120 // 1))
121 // << " (m_sum_wx2 / m_sum_w): " << (m_sum_wx2 / m_sum_w)
122 // << " (mean * mean): " << (mean * mean)
123 // << " ((m_sum_wx2 / m_sum_w) - (mean * mean)): "
124 // << ((m_sum_wx2 / m_sum_w) - (mean * mean))
125 // << G4endl;
126 }
127 return vrms * m_scale;
128}
T max(const T t1, const T t2)
brief Return the largest of the two arguments

References m_scale, G4INCL::Math::max(), and G4InuclParticleNames::nn.

◆ scale()

void G4StatDouble::scale ( G4double  value)

Definition at line 66 of file G4StatDouble.cc.

66{ m_scale = m_scale * value; }

References m_scale.

◆ sum_w()

G4double G4StatDouble::sum_w ( ) const
inline

Definition at line 95 of file G4StatDouble.hh.

95{ return m_sum_w; }

References m_sum_w.

Referenced by add().

◆ sum_w2()

G4double G4StatDouble::sum_w2 ( ) const
inline

Definition at line 96 of file G4StatDouble.hh.

96{ return m_sum_w2; }

References m_sum_w2.

Referenced by add().

◆ sum_wx()

G4double G4StatDouble::sum_wx ( ) const
inline

Definition at line 97 of file G4StatDouble.hh.

97{ return m_sum_wx; }

References m_sum_wx.

Referenced by add().

◆ sum_wx2()

G4double G4StatDouble::sum_wx2 ( ) const
inline

Definition at line 98 of file G4StatDouble.hh.

98{ return m_sum_wx2; }

References m_sum_wx2.

Referenced by add().

Field Documentation

◆ m_n

G4int G4StatDouble::m_n = 0
protected

Definition at line 106 of file G4StatDouble.hh.

Referenced by add(), fill(), n(), operator=(), reset(), and rms().

◆ m_scale

G4double G4StatDouble::m_scale = 0.0
protected

Definition at line 109 of file G4StatDouble.hh.

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

◆ m_sum_w

G4double G4StatDouble::m_sum_w = 0.0
protected

Definition at line 107 of file G4StatDouble.hh.

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

◆ m_sum_w2

G4double G4StatDouble::m_sum_w2 = 0.0
protected

Definition at line 108 of file G4StatDouble.hh.

Referenced by add(), fill(), operator=(), reset(), and sum_w2().

◆ m_sum_wx

G4double G4StatDouble::m_sum_wx = 0.0
protected

Definition at line 104 of file G4StatDouble.hh.

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

◆ m_sum_wx2

G4double G4StatDouble::m_sum_wx2 = 0.0
protected

Definition at line 105 of file G4StatDouble.hh.

Referenced by add(), fill(), operator=(), reset(), rms(), and sum_wx2().


The documentation for this class was generated from the following files: