ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ConvergenceTester.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ConvergenceTester.hh
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 //
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 // Positives numbers are assumed for input values
41 
42 // Author: Tatsumi Koi (SLAC/SCCS)
43 //
44 // --------------------------------------------------------------------
45 
46 #ifndef G4ConvergenceTester
47 #define G4ConvergenceTester_h 1
48 
49 #include "G4SimplexDownhill.hh"
50 
51 #include "G4Timer.hh"
52 #include "globals.hh"
53 
54 #include <map>
55 #include <vector>
56 
58 {
59  public:
60 
61  G4ConvergenceTester( G4String theName="NONAME" );
64 
65  public:
66 
67  void AddScore( G4double );
68 
70  { this->AddScore(val); return *this; }
71 
72  // default to G4cout but can redirected to another ostream
73  void ShowHistory(std::ostream& out = G4cout);
74  void ShowResult(std::ostream& out = G4cout);
75 
76  inline G4double GetValueOfMinimizingFunction( std::vector<G4double> x )
77  { return slope_fitting_function( x ); }
78 
79  private:
80 
81  void calStat();
82  // boolean value of “statsAreUpdated” is set to TRUE at end of calStat
83  // and set to FALSE at end of AddScore
84  // NOTE : A thread lock for Geant4-MT needs to be put in AddScore so calStat is not
85  // executed in one thread while AddScore is modifying/adding data
86  void CheckIsUpdated() { if(!statsAreUpdated) { calStat(); } }
87 
88  public:
89  // Public function to explicitly calculate statistics
90  void ComputeStatistics() { calStat(); }
91 
92  // All “Get” functions check to make sure value is current before returning
96  G4double GetR() { CheckIsUpdated(); return r; }
103 
104  private:
106  void calc_stat_history();
107  void check_stat_history(std::ostream& out = G4cout);
108  G4double calc_Pearson_r( G4int, std::vector<G4double>,
109  std::vector<G4double> );
110  G4bool is_monotonically_decrease( std::vector<G4double> );
111  void calc_slope_fit( std::vector< G4double > );
112  G4double slope_fitting_function( std::vector< G4double > );
113 
114  private:
115 
117  std::map< G4int , G4double > nonzero_histories;
118  // (ith-history , score value)
120  // number of history
121  G4double sum; // sum of scores;
122 
124  std::vector<G4double> cpu_time;
125 
129  G4double r; // relative err sd/mean/sqrt(n)
130  G4double efficiency; // rate of non zero score
136 
139 
143  G4double r_1; // relative err sd/mean/sqrt(n)
147 
149  std::vector< G4int > history_grid;
150  std::vector< G4double > mean_history;
151  std::vector< G4double > var_history;
152  std::vector< G4double > sd_history;
153  std::vector< G4double > r_history;
154  std::vector< G4double > vov_history;
155  std::vector< G4double > fom_history;
156  std::vector< G4double > shift_history;
157  std::vector< G4double > e_history;
158  std::vector< G4double > r2eff_history;
159  std::vector< G4double > r2int_history;
160 
162  std::vector< G4double > largest_scores;
163  std::vector< G4double > f_xi;
164  std::vector< G4double > f_yi;
167 
169  G4int noTotal; // Total number of tests
170 
172 
175 };
176 #endif
177