G4ConvergenceTester.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4ConvergenceTester.hh 69792 2013-05-15 12:59:26Z gcosmo $
00028 //
00029 // Class description:
00030 //
00031 // Convergence Tests for Monte Carlo results.
00032 //
00033 // Reference
00034 // MCNP(TM) -A General Monte Carlo N-Particle Transport Code
00035 // Version 4B
00036 // Judith F. Briesmeister, Editor
00037 // LA-12625-M, Issued: March 1997, UC 705 and UC 700
00038 // CHAPTER 2. GEOMETRY, DATA, PHYSICS, AND MATHEMATICS
00039 //        VI. ESTIMATION OF THE MONTE CARLO PRECISION
00040 //
00041 // Positives numbers are assumed for input values
00042 
00043 // Author: Tatsumi Koi (SLAC/SCCS)
00044 // 
00045 // --------------------------------------------------------------------
00046 
00047 #ifndef G4ConvergenceTester
00048 #define G4ConvergenceTester_h 1
00049 
00050 #include "G4SimplexDownhill.hh"
00051 
00052 #include "G4Timer.hh"
00053 #include "globals.hh"
00054 
00055 #include <map>
00056 #include <vector>
00057 
00058 class G4ConvergenceTester 
00059 {
00060    public:
00061 
00062       G4ConvergenceTester();
00063      ~G4ConvergenceTester();
00064       G4ConvergenceTester( G4double );
00065 
00066    public:
00067 
00068       void AddScore( G4double );
00069 
00070       // default to G4cout but can redirected to another ostream
00071       void ShowHistory(std::ostream& out = G4cout);
00072       void ShowResult(std::ostream& out = G4cout);
00073 
00074       inline G4double GetValueOfMinimizingFunction( std::vector<G4double> x )
00075              { return slope_fitting_function( x ); }
00076 
00077    private:
00078 
00079       void calStat();
00080       // boolean value of “statsAreUpdated” is set to TRUE at end of calStat
00081       // and set to FALSE at end of AddScore
00082       // NOTE : A thread lock for Geant4-MT needs to be put in AddScore so calStat is not
00083       // executed in one thread while AddScore is modifying/adding data
00084       void CheckIsUpdated() { if(!statsAreUpdated) { calStat(); } }
00085       
00086    public:
00087       // Public function to explicitly calculate statistics
00088       void ComputeStatistics() { calStat(); }
00089    
00090       // All “Get” functions check to make sure value is current before returning
00091       G4double GetMean() { CheckIsUpdated(); return mean; }
00092       G4double GetStandardDeviation() { CheckIsUpdated(); return sd; }
00093       G4double GetVariance() { CheckIsUpdated(); return var; }
00094       G4double GetR() { CheckIsUpdated(); return r; }
00095       G4double GetEfficiency() { CheckIsUpdated(); return efficiency; }
00096       G4double GetR2eff() { CheckIsUpdated(); return r2eff; }
00097       G4double GetR2int() { CheckIsUpdated(); return r2int; }
00098       G4double GetShift() { CheckIsUpdated(); return shift; }
00099       G4double GetVOV() { CheckIsUpdated(); return vov; }
00100       G4double GetFOM() { CheckIsUpdated(); return fom; }
00101 
00102    private:
00103       void calc_grid_point_of_history();
00104       void calc_stat_history();
00105       void check_stat_history(std::ostream& out = G4cout);
00106       G4double calc_Pearson_r( G4int, std::vector<G4double>,
00107                                std::vector<G4double> );
00108       G4bool is_monotonically_decrease( std::vector<G4double> ); 
00109       void calc_slope_fit( std::vector< G4double > );
00110       G4double slope_fitting_function( std::vector< G4double > );
00111 
00112    private:
00113 
00114       std::map< G4int , G4double > nonzero_histories;
00115         // (ith-history , score value)
00116       G4int n;
00117         // number of history
00118       G4double sum; // sum of scores;
00119 
00120       G4Timer* timer; 
00121       std::vector<G4double> cpu_time; 
00122 
00123       G4double mean; 
00124       G4double var; 
00125       G4double sd; 
00126       G4double r;          // relative err sd/mean/sqrt(n) 
00127       G4double efficiency; // rate of non zero score 
00128       G4double r2eff; 
00129       G4double r2int; 
00130       G4double shift; 
00131       G4double vov; 
00132       G4double fom; 
00133 
00134       G4double largest;
00135       G4int largest_score_happened;
00136  
00137       G4double mean_1; 
00138       G4double var_1; 
00139       G4double sd_1; 
00140       G4double r_1;        // relative err sd/mean/sqrt(n) 
00141       G4double shift_1; 
00142       G4double vov_1; 
00143       G4double fom_1; 
00144 
00145       G4int noBinOfHistory;
00146       std::vector< G4int > history_grid;
00147       std::vector< G4double > mean_history;
00148       std::vector< G4double > var_history;
00149       std::vector< G4double > sd_history;
00150       std::vector< G4double > r_history;
00151       std::vector< G4double > vov_history;
00152       std::vector< G4double > fom_history;
00153       std::vector< G4double > shift_history;
00154       std::vector< G4double > e_history;
00155       std::vector< G4double > r2eff_history;
00156       std::vector< G4double > r2int_history;
00157 
00158       G4double slope; 
00159       std::vector< G4double > largest_scores; 
00160       std::vector< G4double > f_xi;
00161       std::vector< G4double > f_yi;
00162       G4int noBinOfPDF;
00163       G4SimplexDownhill<G4ConvergenceTester>* minimizer;
00164 
00165       G4int noPass;
00166       G4int noTotal; // Total number of tests
00167 
00168       G4bool statsAreUpdated;
00169 };
00170 #endif
00171 

Generated on Mon May 27 17:47:57 2013 for Geant4 by  doxygen 1.4.7