Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
91  G4double GetMean() { CheckIsUpdated(); return mean; }
92  G4double GetStandardDeviation() { CheckIsUpdated(); return sd; }
93  G4double GetVariance() { CheckIsUpdated(); return var; }
94  G4double GetR() { CheckIsUpdated(); return r; }
95  G4double GetEfficiency() { CheckIsUpdated(); return efficiency; }
96  G4double GetR2eff() { CheckIsUpdated(); return r2eff; }
97  G4double GetR2int() { CheckIsUpdated(); return r2int; }
98  G4double GetShift() { CheckIsUpdated(); return shift; }
99  G4double GetVOV() { CheckIsUpdated(); return vov; }
100  G4double GetFOM() { CheckIsUpdated(); return fom; }
101 
102  private:
103  void calc_grid_point_of_history();
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 
114  G4String name;
115  std::map< G4int , G4double > nonzero_histories;
116  // (ith-history , score value)
117  G4int n;
118  // number of history
119  G4double sum; // sum of scores;
120 
121  G4Timer* timer;
122  std::vector<G4double> cpu_time;
123 
124  G4double mean;
125  G4double var;
126  G4double sd;
127  G4double r; // relative err sd/mean/sqrt(n)
128  G4double efficiency; // rate of non zero score
129  G4double r2eff;
130  G4double r2int;
131  G4double shift;
132  G4double vov;
133  G4double fom;
134 
135  G4double largest;
136  G4int largest_score_happened;
137 
138  G4double mean_1;
139  G4double var_1;
140  G4double sd_1;
141  G4double r_1; // relative err sd/mean/sqrt(n)
142  G4double shift_1;
143  G4double vov_1;
144  G4double fom_1;
145 
146  G4int noBinOfHistory;
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 
159  G4double slope;
160  std::vector< G4double > largest_scores;
161  std::vector< G4double > f_xi;
162  std::vector< G4double > f_yi;
163  G4int noBinOfPDF;
165 
166  G4int noPass;
167  G4int noTotal; // Total number of tests
168 
169  G4bool statsAreUpdated;
170 
171  G4bool showHistory;
172  G4bool calcSLOPE;
173 };
174 #endif
175 
const XML_Char * name
Definition: expat.h:151
tuple x
Definition: test.py:50
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void ShowHistory(std::ostream &out=G4cout)
G4double GetValueOfMinimizingFunction(std::vector< G4double > x)
double G4double
Definition: G4Types.hh:76
void ShowResult(std::ostream &out=G4cout)
G4ConvergenceTester(G4String theName="NONAME")