Geant4 11.2.2
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 ()
 
 G4StatDouble (G4double)
 
virtual ~G4StatDouble ()=default
 
 G4StatDouble (const G4StatDouble &)=default
 
G4StatDoubleoperator= (const G4double &rhs)
 
G4StatDoubleoperator= (const G4StatDouble &rhs)=default
 
G4StatDoubleoperator+= (const G4double &rhs)
 
G4StatDoubleoperator+= (const G4StatDouble &rhs)
 
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)
 
void add (const G4StatDouble *)
 
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 = 0.0
 
G4double m_sum_wx2 = 0.0
 
G4int m_n = 0
 
G4double m_sum_w = 0.0
 
G4double m_sum_w2 = 0.0
 
G4double m_scale = 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(); }

◆ 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.)

◆ ~G4StatDouble()

virtual G4StatDouble::~G4StatDouble ( )
virtualdefault

◆ G4StatDouble() [3/3]

G4StatDouble::G4StatDouble ( const G4StatDouble & )
default

Member Function Documentation

◆ add()

void G4StatDouble::add ( const G4StatDouble * ptr)

Definition at line 149 of file G4StatDouble.cc.

150{
151 m_n += ptr->n();
152 m_sum_w += ptr->sum_w();
153 m_sum_w2 += ptr->sum_w2();
154 m_sum_wx += ptr->sum_wx();
155 m_sum_wx2 += ptr->sum_wx2();
156}
G4double m_sum_wx
G4double sum_w() const
G4double m_sum_w
G4double sum_w2() const
G4int n() const
G4double m_sum_w2
G4double m_sum_wx2
G4double sum_wx2() const
G4double sum_wx() const

Referenced by operator+=().

◆ fill()

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

Definition at line 47 of file G4StatDouble.cc.

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

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

◆ mean() [1/2]

G4double G4StatDouble::mean ( ) const

Definition at line 66 of file G4StatDouble.cc.

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

Referenced by mean().

◆ mean() [2/2]

G4double G4StatDouble::mean ( G4double ext_sum_w) const

Definition at line 76 of file G4StatDouble.cc.

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

◆ n()

G4int G4StatDouble::n ( ) const
inline

Definition at line 85 of file G4StatDouble.hh.

85{ return m_n; }

Referenced by add().

◆ operator+=() [1/2]

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

Definition at line 56 of file G4StatDouble.hh.

57 {
58 fill(rhs);
59 return *this;
60 }

◆ operator+=() [2/2]

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

Definition at line 61 of file G4StatDouble.hh.

62 {
63 add(&rhs);
64 return *this;
65 }
void add(const G4StatDouble *)

◆ 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 }

◆ operator=() [2/2]

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

◆ 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}

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

◆ rms() [1/3]

G4double G4StatDouble::rms ( )

Definition at line 128 of file G4StatDouble.cc.

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

Referenced by rms(), and rms().

◆ rms() [2/3]

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

Definition at line 136 of file G4StatDouble.cc.

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

◆ rms() [3/3]

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

Definition at line 90 of file G4StatDouble.cc.

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

◆ scale()

void G4StatDouble::scale ( G4double value)

Definition at line 64 of file G4StatDouble.cc.

64{ m_scale = m_scale * value; }

◆ sum_w()

G4double G4StatDouble::sum_w ( ) const
inline

Definition at line 86 of file G4StatDouble.hh.

86{ return m_sum_w; }

Referenced by add().

◆ sum_w2()

G4double G4StatDouble::sum_w2 ( ) const
inline

Definition at line 87 of file G4StatDouble.hh.

87{ return m_sum_w2; }

Referenced by add().

◆ sum_wx()

G4double G4StatDouble::sum_wx ( ) const
inline

Definition at line 88 of file G4StatDouble.hh.

88{ return m_sum_wx; }

Referenced by add().

◆ sum_wx2()

G4double G4StatDouble::sum_wx2 ( ) const
inline

Definition at line 89 of file G4StatDouble.hh.

89{ return m_sum_wx2; }

Referenced by add().

Member Data Documentation

◆ m_n

G4int G4StatDouble::m_n = 0
protected

Definition at line 97 of file G4StatDouble.hh.

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

◆ m_scale

G4double G4StatDouble::m_scale = 0.0
protected

Definition at line 100 of file G4StatDouble.hh.

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

◆ m_sum_w

G4double G4StatDouble::m_sum_w = 0.0
protected

Definition at line 98 of file G4StatDouble.hh.

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

◆ m_sum_w2

G4double G4StatDouble::m_sum_w2 = 0.0
protected

Definition at line 99 of file G4StatDouble.hh.

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

◆ m_sum_wx

G4double G4StatDouble::m_sum_wx = 0.0
protected

Definition at line 95 of file G4StatDouble.hh.

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

◆ m_sum_wx2

G4double G4StatDouble::m_sum_wx2 = 0.0
protected

Definition at line 96 of file G4StatDouble.hh.

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


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