Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ConvergenceTester.hh
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// G4ConvergenceTester
27//
28// Class description:
29//
30// Convergence Tests for Monte Carlo results.
31//
32// Reference
33// MCNP(TM) -A General Monte Carlo N-Particle Transport Code
34// Version 4B
35// Judith F. Briesmeister, Editor
36// LA-12625-M, Issued: March 1997, UC 705 and UC 700
37// CHAPTER 2. GEOMETRY, DATA, PHYSICS, AND MATHEMATICS
38// VI. ESTIMATION OF THE MONTE CARLO PRECISION
39//
40// Positive numbers are assumed for input values
41
42// Author: Tatsumi Koi (SLAC/SCCS)
43// --------------------------------------------------------------------
44#ifndef G4ConvergenceTester_hh
45#define G4ConvergenceTester_hh 1
46
47#include "G4SimplexDownhill.hh"
48#include "G4Timer.hh"
49#include "globals.hh"
50
51#include <map>
52#include <vector>
53
55{
56 public:
57 G4ConvergenceTester(G4String theName = "NONAME");
60
61 void AddScore(G4double);
62
64 {
65 this->AddScore(val);
66 return *this;
67 }
68
69 // default to G4cout but can redirected to another ostream
70 void ShowHistory(std::ostream& out = G4cout);
71 void ShowResult(std::ostream& out = G4cout);
72
73 inline G4double GetValueOfMinimizingFunction(std::vector<G4double> x)
74 {
75 return slope_fitting_function(x);
76 }
77
78 public:
79 void ComputeStatistics() { calStat(); }
80 // Public function to explicitly calculate statistics
81
82 // All accessors check to make sure value is current before returning
83
85 {
86 CheckIsUpdated();
87 return mean;
88 }
90 {
91 CheckIsUpdated();
92 return sd;
93 }
95 {
96 CheckIsUpdated();
97 return var;
98 }
99 inline G4double GetR()
100 {
101 CheckIsUpdated();
102 return r;
103 }
105 {
106 CheckIsUpdated();
107 return efficiency;
108 }
110 {
111 CheckIsUpdated();
112 return r2eff;
113 }
115 {
116 CheckIsUpdated();
117 return r2int;
118 }
120 {
121 CheckIsUpdated();
122 return shift;
123 }
125 {
126 CheckIsUpdated();
127 return vov;
128 }
130 {
131 CheckIsUpdated();
132 return fom;
133 }
134
135 private:
136 void calStat();
137 // Boolean value of 'statsAreUpdated' is set to TRUE at end of calStat
138 // and set to FALSE at end of AddScore
139 // NOTE : A thread lock for Geant4-MT needs to be put in AddScore so calStat
140 // is not executed in one thread while AddScore is modifying/adding data
141
142 inline void CheckIsUpdated()
143 {
144 if(!statsAreUpdated)
145 {
146 calStat();
147 }
148 }
149
150 void calc_grid_point_of_history();
151 void calc_stat_history();
152 void check_stat_history(std::ostream& out = G4cout);
153 G4double calc_Pearson_r(G4int, std::vector<G4double>, std::vector<G4double>);
154 G4bool is_monotonically_decrease(std::vector<G4double>);
155 void calc_slope_fit(std::vector<G4double>);
156 G4double slope_fitting_function(std::vector<G4double>);
157
158 private:
159 G4String name;
160 std::map<G4int, G4double> nonzero_histories;
161 // (ith-history , score value)
162 G4int n = 0;
163 // number of history
164 G4double sum = 0.0; // sum of scores;
165
166 G4Timer* timer = nullptr;
167 std::vector<G4double> cpu_time;
168
169 G4double mean = 0.0;
170 G4double var = 0.0;
171 G4double sd = 0.0;
172 G4double r = 0.0; // relative err sd/mean/sqrt(n)
173 G4double efficiency = 0.0; // rate of non zero score
174 G4double r2eff = 0.0;
175 G4double r2int = 0.0;
176 G4double shift = 0.0;
177 G4double vov = 0.0;
178 G4double fom = 0.0;
179
180 G4double largest = 0.0;
181 G4int largest_score_happened = 0;
182
183 G4double mean_1 = 0.0;
184 G4double var_1 = 0.0;
185 G4double sd_1 = 0.0;
186 G4double r_1 = 0.0; // relative err sd/mean/sqrt(n)
187 G4double shift_1 = 0.0;
188 G4double vov_1 = 0.0;
189 G4double fom_1 = 0.0;
190
191 G4int noBinOfHistory = 16;
192 std::vector<G4int> history_grid;
193 std::vector<G4double> mean_history;
194 std::vector<G4double> var_history;
195 std::vector<G4double> sd_history;
196 std::vector<G4double> r_history;
197 std::vector<G4double> vov_history;
198 std::vector<G4double> fom_history;
199 std::vector<G4double> shift_history;
200 std::vector<G4double> e_history;
201 std::vector<G4double> r2eff_history;
202 std::vector<G4double> r2int_history;
203
204 G4double slope = 0.0;
205 std::vector<G4double> largest_scores;
206 std::vector<G4double> f_xi;
207 std::vector<G4double> f_yi;
208 G4int noBinOfPDF = 10;
209 G4SimplexDownhill<G4ConvergenceTester>* minimizer = nullptr;
210
211 G4int noPass = 0;
212 G4int noTotal = 8; // Total number of tests
213
214 G4bool statsAreUpdated = true;
215 G4bool showHistory = true;
216 G4bool calcSLOPE = true;
217};
218
219#endif
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
G4ConvergenceTester & operator+=(G4double val)
void ShowResult(std::ostream &out=G4cout)
G4double GetValueOfMinimizingFunction(std::vector< G4double > x)
void ShowHistory(std::ostream &out=G4cout)
G4ConvergenceTester(G4double)