Geant4.10
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4.10.00.p01
source
global
HEPNumerics
src
G4StatDouble.cc
Go to the documentation of this file.
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
26
//
27
// $Id:$
28
//
29
//
30
// ----------------------------------------------------------------------
31
// class G4StatDouble
32
//
33
// Implementation.
34
// Original Author: Giovanni Santin (ESA) - October 2005 in GRAS tool
35
// Adapted by: John Apostolakis - November 2011
36
37
#include "
G4StatDouble.hh
"
38
39
G4StatDouble::G4StatDouble
()
40
{
41
reset
();
42
}
43
44
void
G4StatDouble::reset
()
45
{
46
m_sum_wx
= 0.;
47
m_sum_wx2
= 0.;
48
m_n
= 0;
49
m_sum_w
= 0.;
50
m_sum_w2
= 0.;
51
m_scale
= 1.;
52
}
53
54
G4StatDouble::~G4StatDouble
()
55
{}
56
57
void
G4StatDouble::fill
(
G4double
value
,
G4double
weight)
58
{
59
m_sum_wx
+= value * weight;
60
m_sum_wx2
+= value * value * weight;
61
m_n
++;
62
m_sum_w
+= weight;
63
m_sum_w2
+= weight * weight;
64
65
if
(weight <= 0.)
66
{
67
G4cout
<<
"[G4StatDouble::fill] WARNING: weight<=0. "
68
<< weight <<
G4endl
;
69
}
70
}
71
72
void
G4StatDouble::scale
(
G4double
value
)
73
{
74
m_scale
=
m_scale
*
value
;
75
}
76
77
G4double
G4StatDouble::mean
()
const
78
{
79
G4double
mean_val = 0.;
80
if
(
m_sum_w
> 0.)
81
{
82
mean_val =
m_sum_wx
/
m_sum_w
;
83
}
84
return
m_scale
* mean_val;
85
}
86
87
G4double
G4StatDouble::mean
(
G4double
ext_sum_w)
const
88
{
89
G4double
factor = 0.;
90
// factor to rescale the Mean for the requested number
91
// of events (or sum of weights) ext_sum_w
92
93
if
(ext_sum_w > 0)
94
{
95
factor =
m_sum_w
;
96
factor /= ext_sum_w;
97
}
98
return
mean
() * factor;
99
100
}
101
102
G4double
G4StatDouble::rms
(
G4double
ssum_wx,
G4double
ssum_wx2,
103
G4double
ssum_w,
G4int
nn
)
104
{
105
G4double
vrms;
106
if
(nn > 1)
107
{
108
G4double
vmean = ssum_wx / ssum_w;
109
G4double
xn =
nn
;
110
G4double
tmp =
111
// from GNU Scientific Library. This part is equivalent to N/(N-1)
112
// when w_i = w
113
// ((m_sum_w * m_sum_w) / (m_sum_w * m_sum_w - m_sum_w2))
114
115
// from NIST "DATAPLOT Reference manual", Page 2-66
116
// http://www.itl.nist.gov/div898/software/dataplot/refman2/ch2/weightsd.pdf
117
// rewritten based on: SUM[w(x-m)^2]/SUM[w] = SUM[wx^2]/SUM[w] - m^2
118
// and dividing it by sqrt[n] to go from rms of distribution to the
119
// rms of the mean value
120
121
(1. / (xn - 1))
122
* ((ssum_wx2 / ssum_w) - (vmean * vmean));
123
124
if
(tmp < 0.) tmp=0.;
// this avoids observed computation problem
125
vrms = std::sqrt( tmp );
126
// G4cout << "[G4StatDoubleElement::rms] m_sum_wx: " << m_sum_wx
127
// << " m_sum_wx2: " << m_sum_wx2 << " m_sum_w: " << m_sum_w
128
// << " m_n: " << m_n << " tmp: " << tmp<< " rms: " << rms
129
// << G4endl;
130
// G4cout << "[G4StatDoubleElement::rms] (m_n / (m_n - 1)): " << (xn/(xn - 1))
131
// << " (m_sum_wx2 / m_sum_w): " << (m_sum_wx2 / m_sum_w)
132
// << " (mean * mean): " << (mean * mean)
133
// << " ((m_sum_wx2 / m_sum_w) - (mean * mean)): "
134
// << ((m_sum_wx2 / m_sum_w) - (mean * mean))
135
// << G4endl;
136
}
137
else
138
{
139
vrms = -1.;
140
}
141
return
vrms *
m_scale
;
142
}
143
144
G4double
G4StatDouble::rms
()
145
{
146
// this method computes the RMS with "all internal" parameters:
147
// all the sums are the internal ones: m_sum_wx, m_sum_wx2, m_sum_w, m_n
148
149
return
rms
(
m_sum_wx
,
m_sum_wx2
,
m_sum_w
,
m_n
);
150
}
151
152
G4double
G4StatDouble::rms
(
G4double
ext_sum_w,
G4int
ext_n)
153
{
154
// this method computes the RMS with sum_w and n coming from outside:
155
// ext_sum_w and ext_n:
156
// this means that the result is normalised to the external events
157
// it is useful when, given a number ext_n of events with sum of the weights
158
// ext_sum_w, only m_n (with sum of weights m_sum_w) are actually accumulated
159
// in the internal summation (e.g. for a dose variable in a volume, because
160
// only a few particles reach that volume)
161
162
return
rms
(
m_sum_wx
,
m_sum_wx2
, ext_sum_w, ext_n);
163
}
164
165
void
G4StatDouble::add
(
G4StatDouble
* ptr)
166
{
167
m_n
+= ptr->
n
();
168
m_sum_w
+= ptr->
sum_w
();
169
m_sum_w2
+= ptr->
sum_w2
();
170
m_sum_wx
+= ptr->
sum_wx
();
171
m_sum_wx2
+= ptr->
sum_wx2
();
172
}
G4StatDouble::sum_wx2
G4double sum_wx2() const
Definition:
G4StatDouble.hh:76
G4StatDouble::add
void add(G4StatDouble *)
Definition:
G4StatDouble.cc:165
G4StatDouble::sum_w2
G4double sum_w2() const
Definition:
G4StatDouble.hh:74
G4StatDouble::fill
void fill(G4double x, G4double weight=1.)
Definition:
G4StatDouble.cc:57
G4StatDouble::m_n
G4int m_n
Definition:
G4StatDouble.hh:86
G4StatDouble
Definition:
G4StatDouble.hh:45
G4int
int G4int
Definition:
G4Types.hh:78
G4StatDouble::m_sum_wx
G4double m_sum_wx
Definition:
G4StatDouble.hh:84
G4StatDouble::sum_w
G4double sum_w() const
Definition:
G4StatDouble.hh:73
G4StatDouble::m_sum_wx2
G4double m_sum_wx2
Definition:
G4StatDouble.hh:85
G4StatDouble::reset
void reset()
Definition:
G4StatDouble.cc:44
G4StatDouble::~G4StatDouble
virtual ~G4StatDouble()
Definition:
G4StatDouble.cc:54
G4StatDouble::m_sum_w2
G4double m_sum_w2
Definition:
G4StatDouble.hh:88
G4cout
G4GLOB_DLL std::ostream G4cout
G4InuclParticleNames::nn
Definition:
G4InuclParticleNames.hh:67
G4StatDouble::sum_wx
G4double sum_wx() const
Definition:
G4StatDouble.hh:75
G4StatDouble::m_sum_w
G4double m_sum_w
Definition:
G4StatDouble.hh:87
G4StatDouble::G4StatDouble
G4StatDouble()
Definition:
G4StatDouble.cc:39
G4StatDouble::scale
void scale(G4double)
Definition:
G4StatDouble.cc:72
G4StatDouble::m_scale
G4double m_scale
Definition:
G4StatDouble.hh:89
G4StatDouble::mean
G4double mean() const
Definition:
G4StatDouble.cc:77
value
const XML_Char int const XML_Char * value
Definition:
include/expat.h:331
G4endl
#define G4endl
Definition:
G4ios.hh:61
G4StatDouble.hh
G4StatDouble::rms
G4double rms()
Definition:
G4StatDouble.cc:144
G4double
double G4double
Definition:
G4Types.hh:76
G4StatDouble::n
G4int n() const
Definition:
G4StatDouble.hh:72
Generated on Wed Apr 30 2014 15:55:05 for Geant4.10 by
1.8.7