Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ConvergenceTester Class Reference

#include <G4ConvergenceTester.hh>

Public Member Functions

 G4ConvergenceTester (const G4String &theName="NONAME")
 
 ~G4ConvergenceTester ()
 
 G4ConvergenceTester (G4double)
 
void AddScore (G4double)
 
G4ConvergenceTesteroperator+= (G4double val)
 
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 54 of file G4ConvergenceTester.hh.

Constructor & Destructor Documentation

◆ G4ConvergenceTester() [1/2]

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

Definition at line 40 of file G4ConvergenceTester.cc.

41 : name(theName)
42{
43 nonzero_histories.clear();
44 largest_scores.clear();
45 largest_scores.push_back(0.0);
46
47 history_grid.resize(noBinOfHistory, 0);
48 mean_history.resize(noBinOfHistory, 0.0);
49 var_history.resize(noBinOfHistory, 0.0);
50 sd_history.resize(noBinOfHistory, 0.0);
51 r_history.resize(noBinOfHistory, 0.0);
52 vov_history.resize(noBinOfHistory, 0.0);
53 fom_history.resize(noBinOfHistory, 0.0);
54 shift_history.resize(noBinOfHistory, 0.0);
55 e_history.resize(noBinOfHistory, 0.0);
56 r2eff_history.resize(noBinOfHistory, 0.0);
57 r2int_history.resize(noBinOfHistory, 0.0);
58
59 timer = new G4Timer();
60 timer->Start();
61 cpu_time.clear();
62 cpu_time.push_back(0.0);
63}
void Start()

◆ ~G4ConvergenceTester()

G4ConvergenceTester::~G4ConvergenceTester ( )

Definition at line 65 of file G4ConvergenceTester.cc.

66{
67 delete timer;
68}

◆ G4ConvergenceTester() [2/2]

G4ConvergenceTester::G4ConvergenceTester ( G4double  )

Member Function Documentation

◆ AddScore()

void G4ConvergenceTester::AddScore ( G4double  x)

Definition at line 70 of file G4ConvergenceTester.cc.

71{
72 G4AutoLock l(&aMutex);
73
74 timer->Stop();
75 cpu_time.push_back(timer->GetSystemElapsed() + timer->GetUserElapsed());
76
77 if(x < 0.0)
78 {
79 std::ostringstream message;
80 message << "Expecting zero or positive number as inputs,\n"
81 << "but received a negative number.";
82 G4Exception("G4ConvergenceTester::AddScore()", "Warning",
83 JustWarning, message);
84 }
85
86 if(x == 0.0)
87 {
88 }
89 else
90 {
91 nonzero_histories.insert(std::pair<G4int, G4double>(n, x));
92 if(x > largest_scores.back())
93 {
94 // Following search should become faster if begin from bottom.
95 for(auto it = largest_scores.begin(); it != largest_scores.end(); ++it)
96 {
97 if(x > *it)
98 {
99 largest_scores.insert(it, x);
100 break;
101 }
102 }
103
104 if(largest_scores.size() > 201)
105 {
106 largest_scores.pop_back();
107 }
108 }
109 sum += x;
110 }
111
112 // Data has been added so statistics have now been updated to new values
113 statsAreUpdated = false;
114 ++n;
115 l.unlock();
116 return;
117}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
void Stop()
G4double GetSystemElapsed() const
Definition: G4Timer.cc:124
G4double GetUserElapsed() const
Definition: G4Timer.cc:135

Referenced by operator+=().

◆ ComputeStatistics()

void G4ConvergenceTester::ComputeStatistics ( )
inline

Definition at line 79 of file G4ConvergenceTester.hh.

79{ calStat(); }

◆ GetEfficiency()

G4double G4ConvergenceTester::GetEfficiency ( )
inline

Definition at line 88 of file G4ConvergenceTester.hh.

88{ CheckIsUpdated(); return efficiency; }

◆ GetFOM()

G4double G4ConvergenceTester::GetFOM ( )
inline

Definition at line 93 of file G4ConvergenceTester.hh.

93{ CheckIsUpdated(); return fom; }

◆ GetMean()

G4double G4ConvergenceTester::GetMean ( )
inline

Definition at line 84 of file G4ConvergenceTester.hh.

84{ CheckIsUpdated(); return mean; }

◆ GetR()

G4double G4ConvergenceTester::GetR ( )
inline

Definition at line 87 of file G4ConvergenceTester.hh.

87{ CheckIsUpdated(); return r; }

◆ GetR2eff()

G4double G4ConvergenceTester::GetR2eff ( )
inline

Definition at line 89 of file G4ConvergenceTester.hh.

89{ CheckIsUpdated(); return r2eff; }

◆ GetR2int()

G4double G4ConvergenceTester::GetR2int ( )
inline

Definition at line 90 of file G4ConvergenceTester.hh.

90{ CheckIsUpdated(); return r2int; }

◆ GetShift()

G4double G4ConvergenceTester::GetShift ( )
inline

Definition at line 91 of file G4ConvergenceTester.hh.

91{ CheckIsUpdated(); return shift; }

◆ GetStandardDeviation()

G4double G4ConvergenceTester::GetStandardDeviation ( )
inline

Definition at line 85 of file G4ConvergenceTester.hh.

85{ CheckIsUpdated(); return sd; }

◆ GetValueOfMinimizingFunction()

G4double G4ConvergenceTester::GetValueOfMinimizingFunction ( std::vector< G4double x)
inline

Definition at line 74 of file G4ConvergenceTester.hh.

75 {
76 return slope_fitting_function(x);
77 }

◆ GetVariance()

G4double G4ConvergenceTester::GetVariance ( )
inline

Definition at line 86 of file G4ConvergenceTester.hh.

86{ CheckIsUpdated(); return var; }

◆ GetVOV()

G4double G4ConvergenceTester::GetVOV ( )
inline

Definition at line 92 of file G4ConvergenceTester.hh.

92{ CheckIsUpdated(); return vov; }

◆ operator+=()

G4ConvergenceTester & G4ConvergenceTester::operator+= ( G4double  val)
inline

Definition at line 64 of file G4ConvergenceTester.hh.

65 {
66 this->AddScore(val);
67 return *this;
68 }

◆ ShowHistory()

void G4ConvergenceTester::ShowHistory ( std::ostream &  out = G4cout)

Definition at line 471 of file G4ConvergenceTester.cc.

472{
473 if(!showHistory)
474 {
475 out << "Number of events of this run is too small to show history."
476 << G4endl;
477 return;
478 }
479
480 out << std::setprecision(6);
481
482 out << G4endl;
483 out << "G4ConvergenceTester Output History of " << name << G4endl;
484 out << "i/" << noBinOfHistory << " till_ith mean" << std::setw(13)
485 << "var" << std::setw(13) << "sd" << std::setw(13) << "r" << std::setw(13)
486 << "vov" << std::setw(13) << "fom" << std::setw(13) << "shift"
487 << std::setw(13) << "e" << std::setw(13) << "r2eff" << std::setw(13)
488 << "r2int" << G4endl;
489 for(G4int i = 1; i <= noBinOfHistory; i++)
490 {
491 out << std::setw(4) << i << " " << std::setw(5) << history_grid[i - 1]
492 << std::setw(13) << mean_history[i - 1] << std::setw(13)
493 << var_history[i - 1] << std::setw(13) << sd_history[i - 1]
494 << std::setw(13) << r_history[i - 1] << std::setw(13)
495 << vov_history[i - 1] << std::setw(13) << fom_history[i - 1]
496 << std::setw(13) << shift_history[i - 1] << std::setw(13)
497 << e_history[i - 1] << std::setw(13) << r2eff_history[i - 1]
498 << std::setw(13) << r2int_history[i - 1] << G4endl;
499 }
500}
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57

◆ ShowResult()

void G4ConvergenceTester::ShowResult ( std::ostream &  out = G4cout)

Definition at line 363 of file G4ConvergenceTester.cc.

364{
365 // if data has been added since the last computation of the statistical values
366 // (not statsAreUpdated) call calStat to recompute the statistical values
367 if(!statsAreUpdated)
368 {
369 calStat();
370 }
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
377 << G4endl;
378 out << std::setw(20) << "MEAN = " << std::setw(13) << mean << G4endl;
379 out << std::setw(20) << "VAR = " << std::setw(13) << var << G4endl;
380 out << std::setw(20) << "SD = " << std::setw(13) << sd << G4endl;
381 out << std::setw(20) << "R = " << std::setw(13) << r << G4endl;
382 out << std::setw(20) << "SHIFT = " << std::setw(13) << shift << G4endl;
383 out << std::setw(20) << "VOV = " << std::setw(13) << vov << G4endl;
384 out << std::setw(20) << "FOM = " << std::setw(13) << fom << G4endl;
385
386 out << std::setw(20) << "THE LARGEST SCORE = " << std::setw(13) << largest
387 << " and it happened at " << largest_score_happened << "th event"
388 << G4endl;
389 if(mean != 0)
390 {
391 out << std::setw(20) << "Affected Mean = " << std::setw(13) << mean_1
392 << " and its ratio to original is " << mean_1 / mean << G4endl;
393 }
394 else
395 {
396 out << std::setw(20) << "Affected Mean = " << std::setw(13) << mean_1
397 << G4endl;
398 }
399 if(var != 0)
400 {
401 out << std::setw(20) << "Affected VAR = " << std::setw(13) << var_1
402 << " and its ratio to original is " << var_1 / var << G4endl;
403 }
404 else
405 {
406 out << std::setw(20) << "Affected VAR = " << std::setw(13) << var_1
407 << G4endl;
408 }
409 if(r != 0)
410 {
411 out << std::setw(20) << "Affected R = " << std::setw(13) << r_1
412 << " and its ratio to original is " << r_1 / r << G4endl;
413 }
414 else
415 {
416 out << std::setw(20) << "Affected R = " << std::setw(13) << r_1 << G4endl;
417 }
418 if(shift != 0)
419 {
420 out << std::setw(20) << "Affected SHIFT = " << std::setw(13) << shift_1
421 << " and its ratio to original is " << shift_1 / shift << G4endl;
422 }
423 else
424 {
425 out << std::setw(20) << "Affected SHIFT = " << std::setw(13) << shift_1
426 << G4endl;
427 }
428 if(fom != 0)
429 {
430 out << std::setw(20) << "Affected FOM = " << std::setw(13) << fom_1
431 << " and its ratio to original is " << fom_1 / fom << G4endl;
432 }
433 else
434 {
435 out << std::setw(20) << "Affected FOM = " << std::setw(13) << fom_1
436 << G4endl;
437 }
438
439 if(!showHistory)
440 {
441 out << "Number of events of this run is too small to do convergence tests."
442 << G4endl;
443 return;
444 }
445
446 check_stat_history(out);
447
448 // check SLOPE and output result
449 if(calcSLOPE)
450 {
451 if(slope >= 3)
452 {
453 noPass++;
454 out << "SLOPE is large enough" << G4endl;
455 }
456 else
457 {
458 out << "SLOPE is not large enough" << G4endl;
459 }
460 }
461 else
462 {
463 out << "Number of non zero history too small to calculate SLOPE" << G4endl;
464 }
465
466 out << "This result passes " << noPass << " / " << noTotal
467 << " Convergence Test." << G4endl;
468 out << G4endl;
469}

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