Geant4  10.02.p02
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 //
27 // $Id: G4ConvergenceTester.hh 79002 2014-02-10 15:03:47Z gcosmo $
28 //
29 // Class description:
30 //
31 // Convergence Tests for Monte Carlo results.
32 //
33 // Reference
34 // MCNP(TM) -A General Monte Carlo N-Particle Transport Code
35 // Version 4B
36 // Judith F. Briesmeister, Editor
37 // LA-12625-M, Issued: March 1997, UC 705 and UC 700
38 // CHAPTER 2. GEOMETRY, DATA, PHYSICS, AND MATHEMATICS
39 // VI. ESTIMATION OF THE MONTE CARLO PRECISION
40 //
41 // Positives numbers are assumed for input values
42 
43 // Author: Tatsumi Koi (SLAC/SCCS)
44 //
45 // --------------------------------------------------------------------
46 
47 #ifndef G4ConvergenceTester
48 #define G4ConvergenceTester_h 1
49 
50 #include "G4SimplexDownhill.hh"
51 
52 #include "G4Timer.hh"
53 #include "globals.hh"
54 
55 #include <map>
56 #include <vector>
57 
59 {
60  public:
61 
62  G4ConvergenceTester( G4String theName="NONAME" );
65 
66  public:
67 
68  void AddScore( G4double );
69 
70  // default to G4cout but can redirected to another ostream
71  void ShowHistory(std::ostream& out = G4cout);
72  void ShowResult(std::ostream& out = G4cout);
73 
74  inline G4double GetValueOfMinimizingFunction( std::vector<G4double> x )
75  { return slope_fitting_function( x ); }
76 
77  private:
78 
79  void calStat();
80  // boolean value of “statsAreUpdated” is set to TRUE at end of calStat
81  // and set to FALSE at end of AddScore
82  // NOTE : A thread lock for Geant4-MT needs to be put in AddScore so calStat is not
83  // executed in one thread while AddScore is modifying/adding data
84  void CheckIsUpdated() { if(!statsAreUpdated) { calStat(); } }
85 
86  public:
87  // Public function to explicitly calculate statistics
88  void ComputeStatistics() { calStat(); }
89 
90  // All “Get” functions check to make sure value is current before returning
94  G4double GetR() { CheckIsUpdated(); return r; }
99  G4double GetVOV() { CheckIsUpdated(); return vov; }
101 
102  private:
104  void calc_stat_history();
105  void check_stat_history(std::ostream& out = G4cout);
106  G4double calc_Pearson_r( G4int, std::vector<G4double>,
107  std::vector<G4double> );
108  G4bool is_monotonically_decrease( std::vector<G4double> );
109  void calc_slope_fit( std::vector< G4double > );
110  G4double slope_fitting_function( std::vector< G4double > );
111 
112  private:
113 
115  std::map< G4int , G4double > nonzero_histories;
116  // (ith-history , score value)
118  // number of history
119  G4double sum; // sum of scores;
120 
122  std::vector<G4double> cpu_time;
123 
127  G4double r; // relative err sd/mean/sqrt(n)
128  G4double efficiency; // rate of non zero score
134 
137 
141  G4double r_1; // relative err sd/mean/sqrt(n)
145 
147  std::vector< G4int > history_grid;
148  std::vector< G4double > mean_history;
149  std::vector< G4double > var_history;
150  std::vector< G4double > sd_history;
151  std::vector< G4double > r_history;
152  std::vector< G4double > vov_history;
153  std::vector< G4double > fom_history;
154  std::vector< G4double > shift_history;
155  std::vector< G4double > e_history;
156  std::vector< G4double > r2eff_history;
157  std::vector< G4double > r2int_history;
158 
160  std::vector< G4double > largest_scores;
161  std::vector< G4double > f_xi;
162  std::vector< G4double > f_yi;
165 
167  G4int noTotal; // Total number of tests
168 
170 
173 };
174 #endif
175 
G4bool is_monotonically_decrease(std::vector< G4double >)
G4double slope_fitting_function(std::vector< G4double >)
std::vector< G4double > largest_scores
std::vector< G4double > sd_history
std::vector< G4double > cpu_time
std::vector< G4double > r2int_history
std::map< G4int, G4double > nonzero_histories
std::vector< G4double > mean_history
std::vector< G4double > f_xi
G4SimplexDownhill< G4ConvergenceTester > * minimizer
void check_stat_history(std::ostream &out=G4cout)
std::vector< G4double > e_history
std::vector< G4int > history_grid
int G4int
Definition: G4Types.hh:78
std::vector< G4double > vov_history
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
std::vector< G4double > r2eff_history
void calc_slope_fit(std::vector< G4double >)
std::vector< G4double > shift_history
void ShowHistory(std::ostream &out=G4cout)
const G4double x[NPOINTSGL]
G4double GetValueOfMinimizingFunction(std::vector< G4double > x)
std::vector< G4double > var_history
double G4double
Definition: G4Types.hh:76
std::vector< G4double > r_history
void ShowResult(std::ostream &out=G4cout)
std::vector< G4double > fom_history
std::vector< G4double > f_yi
G4double calc_Pearson_r(G4int, std::vector< G4double >, std::vector< G4double >)
G4ConvergenceTester(G4String theName="NONAME")