Geant4 10.7.0
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 (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 ( G4String  theName = "NONAME")

Definition at line 34 of file G4ConvergenceTester.cc.

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

◆ ~G4ConvergenceTester()

G4ConvergenceTester::~G4ConvergenceTester ( )

Definition at line 59 of file G4ConvergenceTester.cc.

59{ delete timer; }

◆ G4ConvergenceTester() [2/2]

G4ConvergenceTester::G4ConvergenceTester ( G4double  )

Member Function Documentation

◆ AddScore()

void G4ConvergenceTester::AddScore ( G4double  x)

Definition at line 61 of file G4ConvergenceTester.cc.

62{
63 // G4cout << x << G4endl;
64
65 timer->Stop();
66 cpu_time.push_back(timer->GetSystemElapsed() + timer->GetUserElapsed());
67
68 if(x < 0.0)
69 {
70 G4cout << "Warning: G4convergenceTester expects zero or positive number as "
71 "inputs, but received a negative number."
72 << G4endl;
73 }
74
75 if(x == 0.0)
76 {
77 }
78 else
79 {
80 nonzero_histories.insert(std::pair<G4int, G4double>(n, x));
81 if(x > largest_scores.back())
82 {
83 // Following serch should become faster if begin from bottom.
84 std::vector<G4double>::iterator it;
85 for(it = largest_scores.begin(); it != largest_scores.end(); it++)
86 {
87 if(x > *it)
88 {
89 largest_scores.insert(it, x);
90 break;
91 }
92 }
93
94 if(largest_scores.size() > 201)
95 {
96 largest_scores.pop_back();
97 }
98 }
99 sum += x;
100 }
101
102 // Data has been added so statistics have not been updated to new values
103 statsAreUpdated = false;
104 n++;
105 return;
106}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void Stop()
G4double GetSystemElapsed() const
Definition: G4Timer.cc:132
G4double GetUserElapsed() const
Definition: G4Timer.cc:143

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 104 of file G4ConvergenceTester.hh.

105 {
106 CheckIsUpdated();
107 return efficiency;
108 }

◆ GetFOM()

G4double G4ConvergenceTester::GetFOM ( )
inline

Definition at line 129 of file G4ConvergenceTester.hh.

130 {
131 CheckIsUpdated();
132 return fom;
133 }

◆ GetMean()

G4double G4ConvergenceTester::GetMean ( )
inline

Definition at line 84 of file G4ConvergenceTester.hh.

85 {
86 CheckIsUpdated();
87 return mean;
88 }

◆ GetR()

G4double G4ConvergenceTester::GetR ( )
inline

Definition at line 99 of file G4ConvergenceTester.hh.

100 {
101 CheckIsUpdated();
102 return r;
103 }

◆ GetR2eff()

G4double G4ConvergenceTester::GetR2eff ( )
inline

Definition at line 109 of file G4ConvergenceTester.hh.

110 {
111 CheckIsUpdated();
112 return r2eff;
113 }

◆ GetR2int()

G4double G4ConvergenceTester::GetR2int ( )
inline

Definition at line 114 of file G4ConvergenceTester.hh.

115 {
116 CheckIsUpdated();
117 return r2int;
118 }

◆ GetShift()

G4double G4ConvergenceTester::GetShift ( )
inline

Definition at line 119 of file G4ConvergenceTester.hh.

120 {
121 CheckIsUpdated();
122 return shift;
123 }

◆ GetStandardDeviation()

G4double G4ConvergenceTester::GetStandardDeviation ( )
inline

Definition at line 89 of file G4ConvergenceTester.hh.

90 {
91 CheckIsUpdated();
92 return sd;
93 }

◆ GetValueOfMinimizingFunction()

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

Definition at line 73 of file G4ConvergenceTester.hh.

74 {
75 return slope_fitting_function(x);
76 }

◆ GetVariance()

G4double G4ConvergenceTester::GetVariance ( )
inline

Definition at line 94 of file G4ConvergenceTester.hh.

95 {
96 CheckIsUpdated();
97 return var;
98 }

◆ GetVOV()

G4double G4ConvergenceTester::GetVOV ( )
inline

Definition at line 124 of file G4ConvergenceTester.hh.

125 {
126 CheckIsUpdated();
127 return vov;
128 }

◆ operator+=()

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

Definition at line 63 of file G4ConvergenceTester.hh.

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

◆ ShowHistory()

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

Definition at line 461 of file G4ConvergenceTester.cc.

462{
463 if(!showHistory)
464 {
465 out << "Number of events of this run is too small to show history."
466 << G4endl;
467 return;
468 }
469
470 out << std::setprecision(6);
471
472 out << G4endl;
473 out << "G4ConvergenceTester Output History of " << name << G4endl;
474 out << "i/" << noBinOfHistory << " till_ith mean" << std::setw(13)
475 << "var" << std::setw(13) << "sd" << std::setw(13) << "r" << std::setw(13)
476 << "vov" << std::setw(13) << "fom" << std::setw(13) << "shift"
477 << std::setw(13) << "e" << std::setw(13) << "r2eff" << std::setw(13)
478 << "r2int" << G4endl;
479 for(G4int i = 1; i <= noBinOfHistory; i++)
480 {
481 out << std::setw(4) << i << " " << std::setw(5) << history_grid[i - 1]
482 << std::setw(13) << mean_history[i - 1] << std::setw(13)
483 << var_history[i - 1] << std::setw(13) << sd_history[i - 1]
484 << std::setw(13) << r_history[i - 1] << std::setw(13)
485 << vov_history[i - 1] << std::setw(13) << fom_history[i - 1]
486 << std::setw(13) << shift_history[i - 1] << std::setw(13)
487 << e_history[i - 1] << std::setw(13) << r2eff_history[i - 1]
488 << std::setw(13) << r2int_history[i - 1] << G4endl;
489 }
490}
int G4int
Definition: G4Types.hh:85

◆ ShowResult()

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

Definition at line 353 of file G4ConvergenceTester.cc.

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

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