Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ConvergenceTester Class Reference

#include <G4ConvergenceTester.hh>

Public Member Functions

 G4ConvergenceTester (G4String theName="NONAME")
 
 ~G4ConvergenceTester ()
 
 G4ConvergenceTester (G4double)
 
void AddScore (G4double)
 
void ShowHistory (std::ostream &out=G4cout)
 
void ShowResult (std::ostream &out=G4cout)
 
G4double GetValueOfMinimizingFunction (std::vector< G4double > x)
 
void ComputeStatistics ()
 
G4double GetMean ()
 
G4double GetStandardDeviation ()
 
G4double GetVariance ()
 
G4double GetR ()
 
G4double GetEfficiency ()
 
G4double GetR2eff ()
 
G4double GetR2int ()
 
G4double GetShift ()
 
G4double GetVOV ()
 
G4double GetFOM ()
 

Detailed Description

Definition at line 58 of file G4ConvergenceTester.hh.

Constructor & Destructor Documentation

G4ConvergenceTester::G4ConvergenceTester ( G4String  theName = "NONAME")

Definition at line 46 of file G4ConvergenceTester.cc.

47  : name(theName), n(0), sum(0.), mean(0.), var(0.), sd(0.), r(0.), efficiency(0.),
48  r2eff(0.), r2int(0.), shift(0.), vov(0.), fom(0.), largest(0.),
49  largest_score_happened(0), mean_1(0.), var_1(0.), sd_1(0.), r_1(0.),
50  shift_1(0.), vov_1(0.), fom_1(0.), noBinOfHistory(16), slope(0.),
51  noBinOfPDF(10), minimizer(0), noPass(0), noTotal(8), statsAreUpdated(true)
52  , showHistory(true) , calcSLOPE(true)
53 {
54  nonzero_histories.clear();
55  largest_scores.clear();
56  largest_scores.push_back( 0.0 );
57 
58  history_grid.resize( noBinOfHistory , 0 );
59  mean_history.resize( noBinOfHistory , 0.0 );
60  var_history.resize( noBinOfHistory , 0.0 );
61  sd_history.resize( noBinOfHistory , 0.0 );
62  r_history.resize( noBinOfHistory , 0.0 );
63  vov_history.resize( noBinOfHistory , 0.0 );
64  fom_history.resize( noBinOfHistory , 0.0 );
65  shift_history.resize( noBinOfHistory , 0.0 );
66  e_history.resize( noBinOfHistory , 0.0 );
67  r2eff_history.resize( noBinOfHistory , 0.0 );
68  r2int_history.resize( noBinOfHistory , 0.0 );
69 
70  timer = new G4Timer();
71  timer->Start();
72  cpu_time.clear();
73  cpu_time.push_back( 0.0 );
74 }
const XML_Char * name
Definition: expat.h:151
void Start()

Here is the call graph for this function:

G4ConvergenceTester::~G4ConvergenceTester ( )

Definition at line 78 of file G4ConvergenceTester.cc.

79 {
80  delete timer;
81 }
G4ConvergenceTester::G4ConvergenceTester ( G4double  )

Member Function Documentation

void G4ConvergenceTester::AddScore ( G4double  x)

Definition at line 85 of file G4ConvergenceTester.cc.

86 {
87 
88  //G4cout << x << G4endl;
89 
90  timer->Stop();
91  cpu_time.push_back( timer->GetSystemElapsed() + timer->GetUserElapsed() );
92 
93  if ( x < 0.0 ) {
94  G4cout << "Warning: G4convergenceTester expects zero or positive number as inputs, but received a negative number." << G4endl;
95  }
96 
97  if ( x == 0.0 )
98  {
99  }
100  else
101  {
102  nonzero_histories.insert( std::pair< G4int , G4double > ( n , x ) );
103  if ( x > largest_scores.back() )
104  {
105 // Following serch should become faster if begin from bottom.
106  std::vector< G4double >::iterator it;
107  for ( it = largest_scores.begin() ; it != largest_scores.end() ; it++ )
108  {
109  if ( x > *it )
110  {
111  largest_scores.insert( it , x );
112  break;
113  }
114  }
115 
116  if ( largest_scores.size() > 201 )
117  {
118  largest_scores.pop_back();
119  }
120  //G4cout << largest_scores.size() << " " << largest_scores.front() << " " << largest_scores.back() << G4endl;
121  }
122  sum += x;
123  }
124 
125  // Data has been added so statistics have not been updated to new values
126  statsAreUpdated = false;
127  n++;
128  return;
129 }
G4double GetSystemElapsed() const
Definition: G4Timer.cc:119
G4GLOB_DLL std::ostream G4cout
G4double GetUserElapsed() const
Definition: G4Timer.cc:130
void Stop()
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

void G4ConvergenceTester::ComputeStatistics ( )
inline

Definition at line 88 of file G4ConvergenceTester.hh.

88 { calStat(); }
G4double G4ConvergenceTester::GetEfficiency ( )
inline

Definition at line 95 of file G4ConvergenceTester.hh.

95 { CheckIsUpdated(); return efficiency; }
G4double G4ConvergenceTester::GetFOM ( )
inline

Definition at line 100 of file G4ConvergenceTester.hh.

100 { CheckIsUpdated(); return fom; }
G4double G4ConvergenceTester::GetMean ( )
inline

Definition at line 91 of file G4ConvergenceTester.hh.

91 { CheckIsUpdated(); return mean; }
G4double G4ConvergenceTester::GetR ( )
inline

Definition at line 94 of file G4ConvergenceTester.hh.

94 { CheckIsUpdated(); return r; }
G4double G4ConvergenceTester::GetR2eff ( )
inline

Definition at line 96 of file G4ConvergenceTester.hh.

96 { CheckIsUpdated(); return r2eff; }
G4double G4ConvergenceTester::GetR2int ( )
inline

Definition at line 97 of file G4ConvergenceTester.hh.

97 { CheckIsUpdated(); return r2int; }
G4double G4ConvergenceTester::GetShift ( )
inline

Definition at line 98 of file G4ConvergenceTester.hh.

98 { CheckIsUpdated(); return shift; }
G4double G4ConvergenceTester::GetStandardDeviation ( )
inline

Definition at line 92 of file G4ConvergenceTester.hh.

92 { CheckIsUpdated(); return sd; }
G4double G4ConvergenceTester::GetValueOfMinimizingFunction ( std::vector< G4double x)
inline

Definition at line 74 of file G4ConvergenceTester.hh.

75  { return slope_fitting_function( x ); }
G4double G4ConvergenceTester::GetVariance ( )
inline

Definition at line 93 of file G4ConvergenceTester.hh.

93 { CheckIsUpdated(); return var; }
G4double G4ConvergenceTester::GetVOV ( )
inline

Definition at line 99 of file G4ConvergenceTester.hh.

99 { CheckIsUpdated(); return vov; }
void G4ConvergenceTester::ShowHistory ( std::ostream &  out = G4cout)

Definition at line 439 of file G4ConvergenceTester.cc.

440 {
441 
442  if ( !showHistory ) {
443  out << "Number of events of this run is too small to show history." << G4endl;
444  return;
445  }
446 
447  out << std::setprecision( 6 );
448 
449  out << G4endl;
450  out << "G4ConvergenceTester Output History of " << name << G4endl;
451  out << "i/" << noBinOfHistory << " till_ith mean"
452  << std::setw(13) << "var"
453  << std::setw(13) << "sd"
454  << std::setw(13) << "r"
455  << std::setw(13) << "vov"
456  << std::setw(13) << "fom"
457  << std::setw(13) << "shift"
458  << std::setw(13) << "e"
459  << std::setw(13) << "r2eff"
460  << std::setw(13) << "r2int"
461  << G4endl;
462  for ( G4int i = 1 ; i <= noBinOfHistory ; i++ )
463  {
464  out << std::setw( 4) << i << " "
465  << std::setw( 5) << history_grid [ i-1 ]
466  << std::setw(13) << mean_history [ i-1 ]
467  << std::setw(13) << var_history [ i-1 ]
468  << std::setw(13) << sd_history [ i-1 ]
469  << std::setw(13) << r_history [ i-1 ]
470  << std::setw(13) << vov_history [ i-1 ]
471  << std::setw(13) << fom_history [ i-1 ]
472  << std::setw(13) << shift_history [ i-1 ]
473  << std::setw(13) << e_history [ i-1 ]
474  << std::setw(13) << r2eff_history [ i-1 ]
475  << std::setw(13) << r2int_history [ i-1 ]
476  << G4endl;
477  }
478 }
const XML_Char * name
Definition: expat.h:151
int G4int
Definition: G4Types.hh:78
#define G4endl
Definition: G4ios.hh:61
void G4ConvergenceTester::ShowResult ( std::ostream &  out = G4cout)

Definition at line 366 of file G4ConvergenceTester.cc.

367 {
368  // if data has been added since the last computation of the statistical values (not statsAreUpdated)
369  // call calStat to recompute the statistical values
370  if(!statsAreUpdated) { calStat(); }
371 
372  out << std::setprecision( 6 );
373 
374  out << G4endl;
375  out << "G4ConvergenceTester Output Result of " << name << G4endl;
376  out << std::setw(20) << "EFFICIENCY = " << std::setw(13) << efficiency << G4endl;
377  out << std::setw(20) << "MEAN = " << std::setw(13) << mean << G4endl;
378  out << std::setw(20) << "VAR = " << std::setw(13) << var << G4endl;
379  out << std::setw(20) << "SD = " << std::setw(13) << sd << G4endl;
380  out << std::setw(20) << "R = " << std::setw(13) << r << G4endl;
381  out << std::setw(20) << "SHIFT = "<< std::setw(13) << shift << G4endl;
382  out << std::setw(20) << "VOV = "<< std::setw(13) << vov << G4endl;
383  out << std::setw(20) << "FOM = "<< std::setw(13) << fom << G4endl;
384 
385  out << std::setw(20) << "THE LARGEST SCORE = " << std::setw(13) << largest << " and it happend at " << largest_score_happened << "th event" << G4endl;
386  if ( mean!=0 ) {
387  out << std::setw(20) << "Affected Mean = " << std::setw(13) << mean_1 << " and its ratio to orignal is " << mean_1/mean << G4endl;
388  } else {
389  out << std::setw(20) << "Affected Mean = " << std::setw(13) << mean_1 << G4endl;
390  }
391  if ( var!=0 ) {
392  out << std::setw(20) << "Affected VAR = " << std::setw(13) << var_1 << " and its ratio to orignal is " << var_1/var << G4endl;
393  } else {
394  out << std::setw(20) << "Affected VAR = " << std::setw(13) << var_1 << G4endl;
395  }
396  if ( r!=0 ) {
397  out << std::setw(20) << "Affected R = " << std::setw(13) << r_1 << " and its ratio to orignal is " << r_1/r << G4endl;
398  } else {
399  out << std::setw(20) << "Affected R = " << std::setw(13) << r_1 << G4endl;
400  }
401  if ( shift!=0 ) {
402  out << std::setw(20) << "Affected SHIFT = " << std::setw(13) << shift_1 << " and its ratio to orignal is " << shift_1/shift << G4endl;
403  } else {
404  out << std::setw(20) << "Affected SHIFT = " << std::setw(13) << shift_1 << G4endl;
405  }
406  if ( fom!=0 ) {
407  out << std::setw(20) << "Affected FOM = " << std::setw(13) << fom_1 << " and its ratio to orignal is " << fom_1/fom << G4endl;
408  } else {
409  out << std::setw(20) << "Affected FOM = " << std::setw(13) << fom_1 << G4endl;
410  }
411 
412  if ( !showHistory ) {
413  out << "Number of events of this run is too small to do convergence tests." << G4endl;
414  return;
415  }
416 
417  check_stat_history(out);
418 
419 // check SLOPE and output result
420  if ( calcSLOPE ) {
421  if ( slope >= 3 )
422  {
423  noPass++;
424  out << "SLOPE is large enough" << G4endl;
425  }
426  else
427  {
428  out << "SLOPE is not large enough" << G4endl;
429  }
430  } else {
431  out << "Number of non zero history too small to calculate SLOPE" << G4endl;
432  }
433 
434  out << "This result passes " << noPass << " / "<< noTotal << " Convergence Test." << G4endl;
435  out << G4endl;
436 
437 }
const XML_Char * name
Definition: expat.h:151
#define G4endl
Definition: G4ios.hh:61

The documentation for this class was generated from the following files: