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)
94 G4cout <<
"Warning: G4convergenceTester expects zero or positive number as inputs, but received a negative number." <<
G4endl;
106 std::vector< G4double >::iterator
it;
146 std::map< G4int , G4double >::iterator
it;
151 var += ( xi -
mean ) * ( xi - mean );
153 vov += ( xi -
mean ) * ( xi - mean ) * ( xi -
mean ) * ( xi - mean );
166 sd = std::sqrt (
var );
182 G4double spend_time_of_largest = 0.0;
219 if (
var_1 != 0.0 ) {
296 G4int nonzero_till_ith = 0;
299 std::map< G4int , G4double >::iterator
it;
303 if( itr.first <= ith )
311 if ( nonzero_till_ith == 0 )
314 mean_till_ith = mean_till_ith / ( ith+1 );
322 for(
const auto& itr : nonzero_histories)
324 if ( itr.first <= ith )
327 sum_x2_till_ith += std::pow( xi, 2.0 );
328 var_till_ith += std::pow( xi - mean_till_ith, 2.0 ) ;
329 shift_till_ith += std::pow( xi - mean_till_ith, 3.0 );
330 vov_till_ith += std::pow( xi - mean_till_ith, 4.0 );
334 var_till_ith += ((ith+1) - nonzero_till_ith) * std::pow(mean_till_ith, 2.0);
335 vov_till_ith += ((ith+1) - nonzero_till_ith) * std::pow(mean_till_ith, 4.0);
337 G4double sum_till_ith = mean_till_ith * (ith+1);
339 if(!(std::fabs(var_till_ith) > 0.0))
341 if(!(std::fabs(mean_till_ith) > 0.0))
343 if(!(std::fabs(sum_till_ith) > 0.0))
346 vov_till_ith = vov_till_ith
347 / std::pow( var_till_ith, 2.0 ) - 1.0 / (ith+1);
350 var_till_ith = var_till_ith / ( ith+1 - 1 );
353 r_history [ i ] = std::sqrt( var_till_ith )
355 / std::sqrt ( 1.0*(ith+1) );
368 shift_till_ith += ((ith+1) - nonzero_till_ith) *
369 std::pow(mean_till_ith, 3.0) * ( -1.0 );
370 shift_till_ith = shift_till_ith
371 / ( 2 * var_till_ith * (ith+1) );
382 / std::pow( sum_till_ith, 2.0 ) - 1
398 out << std::setprecision( 6 );
401 out <<
"G4ConvergenceTester Output Result of " <<
name <<
G4endl;
402 out << std::setw(20) <<
"EFFICIENCY = " << std::setw(13) <<
efficiency <<
G4endl;
403 out << std::setw(20) <<
"MEAN = " << std::setw(13) <<
mean <<
G4endl;
404 out << std::setw(20) <<
"VAR = " << std::setw(13) <<
var <<
G4endl;
405 out << std::setw(20) <<
"SD = " << std::setw(13) <<
sd <<
G4endl;
406 out << std::setw(20) <<
"R = " << std::setw(13) <<
r <<
G4endl;
407 out << std::setw(20) <<
"SHIFT = "<< std::setw(13) <<
shift <<
G4endl;
408 out << std::setw(20) <<
"VOV = "<< std::setw(13) <<
vov <<
G4endl;
409 out << std::setw(20) <<
"FOM = "<< std::setw(13) <<
fom <<
G4endl;
413 out << std::setw(20) <<
"Affected Mean = " << std::setw(13) <<
mean_1 <<
" and its ratio to original is " <<
mean_1/
mean <<
G4endl;
415 out << std::setw(20) <<
"Affected Mean = " << std::setw(13) <<
mean_1 <<
G4endl;
418 out << std::setw(20) <<
"Affected VAR = " << std::setw(13) <<
var_1 <<
" and its ratio to original is " <<
var_1/
var <<
G4endl;
420 out << std::setw(20) <<
"Affected VAR = " << std::setw(13) <<
var_1 <<
G4endl;
423 out << std::setw(20) <<
"Affected R = " << std::setw(13) <<
r_1 <<
" and its ratio to original is " <<
r_1/
r <<
G4endl;
425 out << std::setw(20) <<
"Affected R = " << std::setw(13) <<
r_1 <<
G4endl;
428 out << std::setw(20) <<
"Affected SHIFT = " << std::setw(13) <<
shift_1 <<
" and its ratio to original is " <<
shift_1/
shift <<
G4endl;
430 out << std::setw(20) <<
"Affected SHIFT = " << std::setw(13) <<
shift_1 <<
G4endl;
433 out << std::setw(20) <<
"Affected FOM = " << std::setw(13) <<
fom_1 <<
" and its ratio to original is " <<
fom_1/
fom <<
G4endl;
435 out << std::setw(20) <<
"Affected FOM = " << std::setw(13) <<
fom_1 <<
G4endl;
439 out <<
"Number of events of this run is too small to do convergence tests." <<
G4endl;
450 out <<
"SLOPE is large enough" <<
G4endl;
454 out <<
"SLOPE is not large enough" <<
G4endl;
457 out <<
"Number of non zero history too small to calculate SLOPE" <<
G4endl;
460 out <<
"This result passes " <<
noPass <<
" / "<<
noTotal <<
" Convergence Test." <<
G4endl;
469 out <<
"Number of events of this run is too small to show history." <<
G4endl;
473 out << std::setprecision( 6 );
476 out <<
"G4ConvergenceTester Output History of " <<
name <<
G4endl;
478 << std::setw(13) <<
"var"
479 << std::setw(13) <<
"sd"
480 << std::setw(13) <<
"r"
481 << std::setw(13) <<
"vov"
482 << std::setw(13) <<
"fom"
483 << std::setw(13) <<
"shift"
484 << std::setw(13) <<
"e"
485 << std::setw(13) <<
"r2eff"
486 << std::setw(13) <<
"r2int"
490 out << std::setw( 4) << i <<
" "
511 std::vector<G4double> first_ally;
512 std::vector<G4double> second_ally;
521 first_ally.resize( N );
522 second_ally.resize( N );
526 if ( sum_of_var == 0.0 ) {
527 out <<
"Variances in all historical grids are zero." <<
G4endl;
528 out <<
"Terminating checking behavior of statistics numbers." <<
G4endl;
534 for ( i = 0 ; i <
N ; i++ )
541 t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
545 out <<
"MEAN distribution is RANDOM" <<
G4endl;
550 out <<
"MEAN distribution is not RANDOM" <<
G4endl;
556 for ( i = 0 ; i <
N ; i++ )
563 t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
567 out <<
"r follows 1/std::sqrt(N)" <<
G4endl;
572 out <<
"r does not follow 1/std::sqrt(N)" <<
G4endl;
577 out <<
"r is monotonically decrease " <<
G4endl;
581 out <<
"r is NOT monotonically decrease " <<
G4endl;
596 for ( i = 0 ; i <
N ; i++ )
603 t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
607 out <<
"VOV follows 1/std::sqrt(N)" <<
G4endl;
612 out <<
"VOV does not follow 1/std::sqrt(N)" <<
G4endl;
617 out <<
"VOV is monotonically decrease " <<
G4endl;
621 out <<
"VOV is NOT monotonically decrease " <<
G4endl;
626 for ( i = 0 ; i <
N ; i++ )
633 t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
637 out <<
"FOM distribution is RANDOM" <<
G4endl;
642 out <<
"FOM distribution is not RANDOM" <<
G4endl;
655 for ( i = 0 ; i <
N ; i++ )
657 first_mean += first_ally [ i ];
658 second_mean += second_ally [ i ];
660 first_mean = first_mean /
N;
661 second_mean = second_mean /
N;
664 for ( i = 0 ; i <
N ; i++ )
666 a += ( first_ally [ i ] - first_mean ) * ( second_ally [ i ] - second_mean );
671 for ( i = 0 ; i <
N ; i++ )
673 b1 += ( first_ally [ i ] - first_mean ) * ( first_ally [ i ] - first_mean );
674 b2 += ( second_ally [ i ] - second_mean ) * ( second_ally [ i ] - second_mean );
677 G4double rds = a / std::sqrt ( b1 * b2 );
687 std::vector<G4double>::iterator
it;
688 for ( it = ally.begin() ; it != ally.end() - 1 ; it++ )
690 if ( *it < *(it+1) )
return FALSE;
720 if ( max*0.99 < min )
727 std::vector < G4double > pdf_grid;
732 G4double log10_max = std::log10( max );
733 G4double log10_min = std::log10( min );
734 G4double log10_delta = log10_max - log10_min;
737 pdf_grid[i] = std::pow ( 10.0 , log10_max - log10_delta/10.0*(i) );
741 std::vector < G4double > pdf;
742 pdf.resize( noBinOfPDF );
744 for (
G4int j=0 ; j < last ; j ++ )
746 for (
G4int i = 0 ; i < 11 ; i++ )
750 pdf[i] += 1.0 / ( pdf_grid[i] - pdf_grid[i+1] ) /
n;
757 f_xi.resize( noBinOfPDF );
758 f_yi.resize( noBinOfPDF );
762 f_xi[i] = (pdf_grid[i]+pdf_grid[i+1])/2;
798 return 3.402823466e+38;
802 return 3.402823466e+38;
809 for ( i = 0 ; i <
int (
f_yi.size() ) ; i++ )
812 if ( ( 1 + k *
f_xi [ i ] / a ) < 0 )
818 y += (
f_yi [ i ] - 1/a*std::pow ( 1 + k *
f_xi [ i ] / a , - 1/k - 1 ) ) * (
f_yi [ i ] - 1/a*std::pow ( 1 + k *
f_xi [ i ] / a , - 1/k - 1 ) );