Import Geant4 11.0.0.beta source tree
This commit is contained in:
@@ -53,167 +53,124 @@
|
||||
|
||||
class G4ConvergenceTester
|
||||
{
|
||||
public:
|
||||
G4ConvergenceTester(G4String theName = "NONAME");
|
||||
~G4ConvergenceTester();
|
||||
G4ConvergenceTester(G4double);
|
||||
public:
|
||||
|
||||
void AddScore(G4double);
|
||||
G4ConvergenceTester(const G4String& theName = "NONAME");
|
||||
~G4ConvergenceTester();
|
||||
G4ConvergenceTester(G4double);
|
||||
|
||||
inline G4ConvergenceTester& operator+=(G4double val)
|
||||
{
|
||||
this->AddScore(val);
|
||||
return *this;
|
||||
}
|
||||
void AddScore(G4double);
|
||||
|
||||
// default to G4cout but can redirected to another ostream
|
||||
void ShowHistory(std::ostream& out = G4cout);
|
||||
void ShowResult(std::ostream& out = G4cout);
|
||||
|
||||
inline G4double GetValueOfMinimizingFunction(std::vector<G4double> x)
|
||||
{
|
||||
return slope_fitting_function(x);
|
||||
}
|
||||
|
||||
public:
|
||||
void ComputeStatistics() { calStat(); }
|
||||
// Public function to explicitly calculate statistics
|
||||
|
||||
// All accessors check to make sure value is current before returning
|
||||
|
||||
inline G4double GetMean()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return mean;
|
||||
}
|
||||
inline G4double GetStandardDeviation()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return sd;
|
||||
}
|
||||
inline G4double GetVariance()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return var;
|
||||
}
|
||||
inline G4double GetR()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return r;
|
||||
}
|
||||
inline G4double GetEfficiency()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return efficiency;
|
||||
}
|
||||
inline G4double GetR2eff()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return r2eff;
|
||||
}
|
||||
inline G4double GetR2int()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return r2int;
|
||||
}
|
||||
inline G4double GetShift()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return shift;
|
||||
}
|
||||
inline G4double GetVOV()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return vov;
|
||||
}
|
||||
inline G4double GetFOM()
|
||||
{
|
||||
CheckIsUpdated();
|
||||
return fom;
|
||||
}
|
||||
|
||||
private:
|
||||
void calStat();
|
||||
// Boolean value of 'statsAreUpdated' is set to TRUE at end of calStat
|
||||
// and set to FALSE at end of AddScore
|
||||
// NOTE : A thread lock for Geant4-MT needs to be put in AddScore so calStat
|
||||
// is not executed in one thread while AddScore is modifying/adding data
|
||||
|
||||
inline void CheckIsUpdated()
|
||||
{
|
||||
if(!statsAreUpdated)
|
||||
inline G4ConvergenceTester& operator+=(G4double val)
|
||||
{
|
||||
calStat();
|
||||
this->AddScore(val);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
void calc_grid_point_of_history();
|
||||
void calc_stat_history();
|
||||
void check_stat_history(std::ostream& out = G4cout);
|
||||
G4double calc_Pearson_r(G4int, std::vector<G4double>, std::vector<G4double>);
|
||||
G4bool is_monotonically_decrease(std::vector<G4double>);
|
||||
void calc_slope_fit(std::vector<G4double>);
|
||||
G4double slope_fitting_function(std::vector<G4double>);
|
||||
void ShowHistory(std::ostream& out = G4cout);
|
||||
void ShowResult(std::ostream& out = G4cout);
|
||||
// Default to G4cout but can be redirected to another ostream
|
||||
|
||||
private:
|
||||
G4String name;
|
||||
std::map<G4int, G4double> nonzero_histories;
|
||||
// (ith-history , score value)
|
||||
G4int n = 0;
|
||||
// number of history
|
||||
G4double sum = 0.0; // sum of scores;
|
||||
inline G4double GetValueOfMinimizingFunction(std::vector<G4double> x)
|
||||
{
|
||||
return slope_fitting_function(x);
|
||||
}
|
||||
|
||||
G4Timer* timer = nullptr;
|
||||
std::vector<G4double> cpu_time;
|
||||
void ComputeStatistics() { calStat(); }
|
||||
// Explicitly calculate statistics
|
||||
|
||||
G4double mean = 0.0;
|
||||
G4double var = 0.0;
|
||||
G4double sd = 0.0;
|
||||
G4double r = 0.0; // relative err sd/mean/sqrt(n)
|
||||
G4double efficiency = 0.0; // rate of non zero score
|
||||
G4double r2eff = 0.0;
|
||||
G4double r2int = 0.0;
|
||||
G4double shift = 0.0;
|
||||
G4double vov = 0.0;
|
||||
G4double fom = 0.0;
|
||||
// All accessors check to make sure value is current before returning
|
||||
|
||||
G4double largest = 0.0;
|
||||
G4int largest_score_happened = 0;
|
||||
inline G4double GetMean() { CheckIsUpdated(); return mean; }
|
||||
inline G4double GetStandardDeviation() { CheckIsUpdated(); return sd; }
|
||||
inline G4double GetVariance() { CheckIsUpdated(); return var; }
|
||||
inline G4double GetR() { CheckIsUpdated(); return r; }
|
||||
inline G4double GetEfficiency() { CheckIsUpdated(); return efficiency; }
|
||||
inline G4double GetR2eff() { CheckIsUpdated(); return r2eff; }
|
||||
inline G4double GetR2int() { CheckIsUpdated(); return r2int; }
|
||||
inline G4double GetShift() { CheckIsUpdated(); return shift; }
|
||||
inline G4double GetVOV() { CheckIsUpdated(); return vov; }
|
||||
inline G4double GetFOM() { CheckIsUpdated(); return fom; }
|
||||
|
||||
G4double mean_1 = 0.0;
|
||||
G4double var_1 = 0.0;
|
||||
G4double sd_1 = 0.0;
|
||||
G4double r_1 = 0.0; // relative err sd/mean/sqrt(n)
|
||||
G4double shift_1 = 0.0;
|
||||
G4double vov_1 = 0.0;
|
||||
G4double fom_1 = 0.0;
|
||||
private:
|
||||
|
||||
G4int noBinOfHistory = 16;
|
||||
std::vector<G4int> history_grid;
|
||||
std::vector<G4double> mean_history;
|
||||
std::vector<G4double> var_history;
|
||||
std::vector<G4double> sd_history;
|
||||
std::vector<G4double> r_history;
|
||||
std::vector<G4double> vov_history;
|
||||
std::vector<G4double> fom_history;
|
||||
std::vector<G4double> shift_history;
|
||||
std::vector<G4double> e_history;
|
||||
std::vector<G4double> r2eff_history;
|
||||
std::vector<G4double> r2int_history;
|
||||
void calStat();
|
||||
// Boolean value of 'statsAreUpdated' is set to TRUE at end of calStat
|
||||
// and set to FALSE at end of AddScore().
|
||||
// NOTE: A thread lock needs to be put in AddScore() so calStat()
|
||||
// is not executed in one thread while AddScore() is adding data
|
||||
|
||||
G4double slope = 0.0;
|
||||
std::vector<G4double> largest_scores;
|
||||
std::vector<G4double> f_xi;
|
||||
std::vector<G4double> f_yi;
|
||||
G4int noBinOfPDF = 10;
|
||||
G4SimplexDownhill<G4ConvergenceTester>* minimizer = nullptr;
|
||||
inline void CheckIsUpdated()
|
||||
{
|
||||
if(!statsAreUpdated) { calStat(); }
|
||||
}
|
||||
|
||||
G4int noPass = 0;
|
||||
G4int noTotal = 8; // Total number of tests
|
||||
void calc_grid_point_of_history();
|
||||
void calc_stat_history();
|
||||
void check_stat_history(std::ostream& out = G4cout);
|
||||
G4double calc_Pearson_r(G4int,std::vector<G4double>,std::vector<G4double>);
|
||||
G4bool is_monotonically_decrease(std::vector<G4double>);
|
||||
void calc_slope_fit(std::vector<G4double>);
|
||||
G4double slope_fitting_function(std::vector<G4double>);
|
||||
|
||||
G4bool statsAreUpdated = true;
|
||||
G4bool showHistory = true;
|
||||
G4bool calcSLOPE = true;
|
||||
private:
|
||||
|
||||
G4String name;
|
||||
std::map<G4int, G4double> nonzero_histories; // (ith-history, score value)
|
||||
G4int n = 0; // number of history
|
||||
G4double sum = 0.0; // sum of scores;
|
||||
|
||||
G4Timer* timer = nullptr;
|
||||
std::vector<G4double> cpu_time;
|
||||
|
||||
G4double mean = 0.0;
|
||||
G4double var = 0.0;
|
||||
G4double sd = 0.0;
|
||||
G4double r = 0.0; // relative err sd/mean/sqrt(n)
|
||||
G4double efficiency = 0.0; // rate of non zero score
|
||||
G4double r2eff = 0.0;
|
||||
G4double r2int = 0.0;
|
||||
G4double shift = 0.0;
|
||||
G4double vov = 0.0;
|
||||
G4double fom = 0.0;
|
||||
|
||||
G4double largest = 0.0;
|
||||
G4int largest_score_happened = 0;
|
||||
|
||||
G4double mean_1 = 0.0;
|
||||
G4double var_1 = 0.0;
|
||||
G4double sd_1 = 0.0;
|
||||
G4double r_1 = 0.0; // relative err sd/mean/sqrt(n)
|
||||
G4double shift_1 = 0.0;
|
||||
G4double vov_1 = 0.0;
|
||||
G4double fom_1 = 0.0;
|
||||
|
||||
G4int noBinOfHistory = 16;
|
||||
std::vector<G4int> history_grid;
|
||||
std::vector<G4double> mean_history;
|
||||
std::vector<G4double> var_history;
|
||||
std::vector<G4double> sd_history;
|
||||
std::vector<G4double> r_history;
|
||||
std::vector<G4double> vov_history;
|
||||
std::vector<G4double> fom_history;
|
||||
std::vector<G4double> shift_history;
|
||||
std::vector<G4double> e_history;
|
||||
std::vector<G4double> r2eff_history;
|
||||
std::vector<G4double> r2int_history;
|
||||
|
||||
G4double slope = 0.0;
|
||||
std::vector<G4double> largest_scores;
|
||||
std::vector<G4double> f_xi;
|
||||
std::vector<G4double> f_yi;
|
||||
G4int noBinOfPDF = 10;
|
||||
G4SimplexDownhill<G4ConvergenceTester>* minimizer = nullptr;
|
||||
|
||||
G4int noPass = 0;
|
||||
G4int noTotal = 8; // Total number of tests
|
||||
|
||||
G4bool statsAreUpdated = true;
|
||||
G4bool showHistory = true;
|
||||
G4bool calcSLOPE = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# Module : G4hepnumerics
|
||||
# Package: Geant4.src.G4global.G4hepnumerics
|
||||
#------------------------------------------------------------------------------
|
||||
# - G4hepnumerics module build definition
|
||||
|
||||
#
|
||||
# Define the Geant4 Module.
|
||||
#
|
||||
geant4_define_module(NAME G4hepnumerics
|
||||
HEADERS
|
||||
geant4_add_module(G4hepnumerics
|
||||
PUBLIC_HEADERS
|
||||
G4AnalyticalPolSolver.hh
|
||||
G4ChebyshevApproximation.hh
|
||||
G4ConvergenceTester.hh
|
||||
@@ -42,9 +36,6 @@ geant4_define_module(NAME G4hepnumerics
|
||||
G4JTPolynomialSolver.cc
|
||||
G4SimpleIntegration.cc
|
||||
G4StatDouble.cc
|
||||
G4VGaussianQuadrature.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
G4globman
|
||||
)
|
||||
G4VGaussianQuadrature.cc)
|
||||
|
||||
# List any source specific properties here
|
||||
geant4_module_link_libraries(G4hepnumerics PUBLIC G4globman)
|
||||
|
||||
@@ -29,9 +29,15 @@
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4ConvergenceTester.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include <iomanip>
|
||||
|
||||
G4ConvergenceTester::G4ConvergenceTester(G4String theName)
|
||||
namespace
|
||||
{
|
||||
G4Mutex aMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4ConvergenceTester::G4ConvergenceTester(const G4String& theName)
|
||||
: name(theName)
|
||||
{
|
||||
nonzero_histories.clear();
|
||||
@@ -56,20 +62,25 @@ G4ConvergenceTester::G4ConvergenceTester(G4String theName)
|
||||
cpu_time.push_back(0.0);
|
||||
}
|
||||
|
||||
G4ConvergenceTester::~G4ConvergenceTester() { delete timer; }
|
||||
G4ConvergenceTester::~G4ConvergenceTester()
|
||||
{
|
||||
delete timer;
|
||||
}
|
||||
|
||||
void G4ConvergenceTester::AddScore(G4double x)
|
||||
{
|
||||
// G4cout << x << G4endl;
|
||||
G4AutoLock l(&aMutex);
|
||||
|
||||
timer->Stop();
|
||||
cpu_time.push_back(timer->GetSystemElapsed() + timer->GetUserElapsed());
|
||||
|
||||
if(x < 0.0)
|
||||
{
|
||||
G4cout << "Warning: G4convergenceTester expects zero or positive number as "
|
||||
"inputs, but received a negative number."
|
||||
<< G4endl;
|
||||
std::ostringstream message;
|
||||
message << "Expecting zero or positive number as inputs,\n"
|
||||
<< "but received a negative number.";
|
||||
G4Exception("G4ConvergenceTester::AddScore()", "Warning",
|
||||
JustWarning, message);
|
||||
}
|
||||
|
||||
if(x == 0.0)
|
||||
@@ -80,9 +91,8 @@ void G4ConvergenceTester::AddScore(G4double x)
|
||||
nonzero_histories.insert(std::pair<G4int, G4double>(n, x));
|
||||
if(x > largest_scores.back())
|
||||
{
|
||||
// Following serch should become faster if begin from bottom.
|
||||
std::vector<G4double>::iterator it;
|
||||
for(it = largest_scores.begin(); it != largest_scores.end(); it++)
|
||||
// Following search should become faster if begin from bottom.
|
||||
for(auto it = largest_scores.begin(); it != largest_scores.end(); ++it)
|
||||
{
|
||||
if(x > *it)
|
||||
{
|
||||
@@ -99,15 +109,16 @@ void G4ConvergenceTester::AddScore(G4double x)
|
||||
sum += x;
|
||||
}
|
||||
|
||||
// Data has been added so statistics have not been updated to new values
|
||||
// Data has been added so statistics have now been updated to new values
|
||||
statsAreUpdated = false;
|
||||
n++;
|
||||
++n;
|
||||
l.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
void G4ConvergenceTester::calStat()
|
||||
{
|
||||
efficiency = double(nonzero_histories.size()) / n;
|
||||
efficiency = G4double(nonzero_histories.size()) / n;
|
||||
|
||||
mean = sum / n;
|
||||
|
||||
@@ -173,8 +184,6 @@ void G4ConvergenceTester::calStat()
|
||||
r_1 = 0.0;
|
||||
vov_1 = 0.0;
|
||||
|
||||
// G4cout << "The largest history = " << largest << G4endl;
|
||||
|
||||
mean_1 = (sum + largest) / (n + 1);
|
||||
|
||||
for(auto it = nonzero_histories.cbegin(); it != nonzero_histories.cend();
|
||||
@@ -245,16 +254,11 @@ void G4ConvergenceTester::calc_grid_point_of_history()
|
||||
for(G4int i = 1; i <= noBinOfHistory; ++i)
|
||||
{
|
||||
history_grid[i - 1] = G4int(n / (G4double(noBinOfHistory)) * i - 0.1);
|
||||
// G4cout << "history_grid " << i-1 << " " << history_grid [ i-1 ] <<
|
||||
// G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4ConvergenceTester::calc_stat_history()
|
||||
{
|
||||
// G4cout << "i/16 till_ith mean var sd r vov fom shift e r2eff
|
||||
// r2int" << G4endl;
|
||||
|
||||
if(history_grid[0] == 0)
|
||||
{
|
||||
showHistory = false;
|
||||
@@ -506,7 +510,6 @@ void G4ConvergenceTester::check_stat_history(std::ostream& out)
|
||||
first_ally.resize(N);
|
||||
second_ally.resize(N);
|
||||
|
||||
//
|
||||
G4double sum_of_var =
|
||||
std::accumulate(var_history.begin(), var_history.end(), 0.0);
|
||||
if(sum_of_var == 0.0)
|
||||
@@ -676,8 +679,6 @@ G4bool G4ConvergenceTester::is_monotonically_decrease(
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// void G4ConvergenceTester::calc_slope_fit ( std::vector<G4double>
|
||||
// largest_socres )
|
||||
void G4ConvergenceTester::calc_slope_fit(std::vector<G4double>)
|
||||
{
|
||||
// create PDF bins
|
||||
@@ -694,9 +695,6 @@ void G4ConvergenceTester::calc_slope_fit(std::vector<G4double>)
|
||||
last = last - 1;
|
||||
}
|
||||
|
||||
// G4cout << "largest " << max << G4endl;
|
||||
// G4cout << "last " << min << G4endl;
|
||||
|
||||
if(max * 0.99 < min)
|
||||
{
|
||||
// upper limit is assumed to have been reached
|
||||
@@ -715,7 +713,6 @@ void G4ConvergenceTester::calc_slope_fit(std::vector<G4double>)
|
||||
for(G4int i = 1; i < noBinOfPDF; ++i)
|
||||
{
|
||||
pdf_grid[i] = std::pow(10.0, log10_max - log10_delta / 10.0 * (i));
|
||||
// G4cout << "pdf i " << i << " " << pdf_grid[i] << G4endl;
|
||||
}
|
||||
|
||||
std::vector<G4double> pdf;
|
||||
@@ -728,9 +725,6 @@ void G4ConvergenceTester::calc_slope_fit(std::vector<G4double>)
|
||||
if(largest_scores[j] >= pdf_grid[i + 1])
|
||||
{
|
||||
pdf[i] += 1.0 / (pdf_grid[i] - pdf_grid[i + 1]) / n;
|
||||
// G4cout << "pdf " << j << " " << i << " " << largest_scores[j] << "
|
||||
// "
|
||||
// << G4endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -740,8 +734,6 @@ void G4ConvergenceTester::calc_slope_fit(std::vector<G4double>)
|
||||
f_yi.resize(noBinOfPDF);
|
||||
for(G4int i = 0; i < noBinOfPDF; ++i)
|
||||
{
|
||||
// G4cout << "pdf i " << i << " " << (pdf_grid[i]+pdf_grid[i+1])/2 << " "
|
||||
// << pdf[i] << G4endl;
|
||||
f_xi[i] = (pdf_grid[i] + pdf_grid[i + 1]) / 2;
|
||||
f_yi[i] = pdf[i];
|
||||
}
|
||||
@@ -798,7 +790,6 @@ G4double G4ConvergenceTester::slope_fitting_function(std::vector<G4double> x)
|
||||
(f_yi[i] - 1 / a * std::pow(1 + k * f_xi[i] / a, -1 / k - 1));
|
||||
}
|
||||
}
|
||||
// G4cout << "y = " << y << G4endl;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user