Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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::G4StatDouble ( )

Definition at line 40 of file G4StatDouble.cc.

41{
42 reset();
43}

◆ ~G4StatDouble()

G4StatDouble::~G4StatDouble ( )
virtual

Definition at line 55 of file G4StatDouble.cc.

56{}

Member Function Documentation

◆ fill()

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

Definition at line 58 of file G4StatDouble.cc.

59{
60 m_sum_wx += value * weight;
61 m_sum_wx2 += value * value * weight;
62 m_n++;
63 m_sum_w += weight;
64 m_sum_w2 += weight * weight;
65
66 if (weight <= 0.)
67 {
68 G4cout << "[G4StatDouble::fill] WARNING: weight<=0. "
69 << weight << G4endl;
70 }
71}
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
G4double m_sum_wx
Definition: G4StatDouble.hh:82
G4double m_sum_w
Definition: G4StatDouble.hh:85
G4double m_sum_w2
Definition: G4StatDouble.hh:86
G4double m_sum_wx2
Definition: G4StatDouble.hh:83

◆ mean() [1/2]

G4double G4StatDouble::mean ( ) const

Definition at line 78 of file G4StatDouble.cc.

79{
80 G4double mean_val = 0.;
81 if (m_sum_w > 0.)
82 {
83 mean_val = m_sum_wx / m_sum_w;
84 }
85 return m_scale * mean_val;
86}
double G4double
Definition: G4Types.hh:64
G4double m_scale
Definition: G4StatDouble.hh:87

Referenced by mean().

◆ mean() [2/2]

G4double G4StatDouble::mean ( G4double  ext_sum_w) const

Definition at line 88 of file G4StatDouble.cc.

89{
90 G4double factor = 0.;
91 // factor to rescale the Mean for the requested number
92 // of events (or sum of weights) ext_sum_w
93
94 if (ext_sum_w > 0)
95 {
96 factor = m_sum_w;
97 factor /= ext_sum_w;
98 }
99 return mean() * factor;
100
101}
G4double mean() const
Definition: G4StatDouble.cc:78

◆ n()

G4int G4StatDouble::n ( ) const
inline

Definition at line 70 of file G4StatDouble.hh.

70{ return m_n; }

◆ reset()

void G4StatDouble::reset ( )

Definition at line 45 of file G4StatDouble.cc.

46{
47 m_sum_wx = 0.;
48 m_sum_wx2 = 0.;
49 m_n = 0;
50 m_sum_w = 0.;
51 m_sum_w2 = 0.;
52 m_scale = 1.;
53}

Referenced by G4StatDouble().

◆ rms() [1/3]

G4double G4StatDouble::rms ( )

Definition at line 145 of file G4StatDouble.cc.

146{
147 // this method computes the RMS with "all internal" parameters:
148 // all the sums are the internal ones: m_sum_wx, m_sum_wx2, m_sum_w, m_n
149
150 return rms(m_sum_wx, m_sum_wx2, m_sum_w, m_n);
151}
G4double rms()

Referenced by rms().

◆ rms() [2/3]

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

Definition at line 153 of file G4StatDouble.cc.

154{
155 // this method computes the RMS with sum_w and n coming from outside:
156 // ext_sum_w and ext_n:
157 // this means that the result is normalised to the external events
158 // it is useful when, given a number ext_n of events with sum of the weights
159 // ext_sum_w, only m_n (with sum of weights m_sum_w) are actually accumulated
160 // in the internal summation (e.g. for a dose variable in a volume, because
161 // only a few particles reach that volume)
162
163 return rms(m_sum_wx, m_sum_wx2, ext_sum_w, ext_n);
164}

◆ rms() [3/3]

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

Definition at line 103 of file G4StatDouble.cc.

105{
106 G4double vrms;
107 if (nn > 1)
108 {
109 G4double vmean = ssum_wx / ssum_w;
110 G4double xn = nn;
111 G4double tmp =
112 // from GNU Scientific Library. This part is equivalent to N/(N-1)
113 // when w_i = w
114 // ((m_sum_w * m_sum_w) / (m_sum_w * m_sum_w - m_sum_w2))
115
116 // from NIST "DATAPLOT Reference manual", Page 2-66
117 // http://www.itl.nist.gov/div898/software/dataplot/refman2/ch2/weightsd.pdf
118 // rewritten based on: SUM[w(x-m)^2]/SUM[w] = SUM[wx^2]/SUM[w] - m^2
119 // and dividing it by sqrt[n] to go from rms of distribution to the
120 // rms of the mean value
121
122 (1. / (xn - 1))
123 * ((ssum_wx2 / ssum_w) - (vmean * vmean));
124
125 if (tmp < 0.) tmp=0.; // this avoids observed computation problem
126 vrms = std::sqrt( tmp );
127// G4cout << "[G4StatDoubleElement::rms] m_sum_wx: " << m_sum_wx
128// << " m_sum_wx2: " << m_sum_wx2 << " m_sum_w: " << m_sum_w
129// << " m_n: " << m_n << " tmp: " << tmp<< " rms: " << rms
130// << G4endl;
131// G4cout << "[G4StatDoubleElement::rms] (m_n / (m_n - 1)): " << (xn/(xn - 1))
132// << " (m_sum_wx2 / m_sum_w): " << (m_sum_wx2 / m_sum_w)
133// << " (mean * mean): " << (mean * mean)
134// << " ((m_sum_wx2 / m_sum_w) - (mean * mean)): "
135// << ((m_sum_wx2 / m_sum_w) - (mean * mean))
136// << G4endl;
137 }
138 else
139 {
140 vrms = -1.;
141 }
142 return vrms * m_scale;
143}

◆ scale()

void G4StatDouble::scale ( G4double  value)

Definition at line 73 of file G4StatDouble.cc.

74{
75 m_scale = m_scale * value;
76}

◆ sum_w()

G4double G4StatDouble::sum_w ( ) const
inline

Definition at line 71 of file G4StatDouble.hh.

71{ return m_sum_w; }

◆ sum_w2()

G4double G4StatDouble::sum_w2 ( ) const
inline

Definition at line 72 of file G4StatDouble.hh.

72{ return m_sum_w2; }

◆ sum_wx()

G4double G4StatDouble::sum_wx ( ) const
inline

Definition at line 73 of file G4StatDouble.hh.

73{ return m_sum_wx; }

◆ sum_wx2()

G4double G4StatDouble::sum_wx2 ( ) const
inline

Definition at line 74 of file G4StatDouble.hh.

74{ return m_sum_wx2; }

Member Data Documentation

◆ m_n

G4int G4StatDouble::m_n
protected

Definition at line 84 of file G4StatDouble.hh.

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

◆ m_scale

G4double G4StatDouble::m_scale
protected

Definition at line 87 of file G4StatDouble.hh.

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

◆ m_sum_w

G4double G4StatDouble::m_sum_w
protected

Definition at line 85 of file G4StatDouble.hh.

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

◆ m_sum_w2

G4double G4StatDouble::m_sum_w2
protected

Definition at line 86 of file G4StatDouble.hh.

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

◆ m_sum_wx

G4double G4StatDouble::m_sum_wx
protected

Definition at line 82 of file G4StatDouble.hh.

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

◆ m_sum_wx2

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: