00001 #include "HTL/H_Statistics.h"
00002 #include "HTL/P_Histograms_1D.h"
00003
00004 #define CLASS___ H_Statistics
00005
00006
00007 Size CLASS___::extra_entries_count( const I_Histo &a_histo )
00008
00009
00010 {
00011 Size count = 0;
00012 I_Histo &h = (I_Histo &) a_histo;
00013 if (h.dim() > 0) {
00014 if ((h.dim() == 2 ) && (h.version() == 0)) {
00015
00016 for( Index i=0; i<9; i++ )
00017 count += h.i_bin( h.bin_count() + i ).count();
00018
00019 } else {
00020 for( Index i=0; i<Index(h.extra_bin_count()); i++ )
00021 count += h.i_bin( h.bin_count() + i ).count();
00022 }
00023 } else {
00024 HTL_ERR ("Invalid dimension. count is zero");
00025 }
00026 return count;
00027 }
00028
00029 Size CLASS___::in_range_entries_count( const I_Histo &a_histo )
00030
00031 {
00032 I_Histo &h = (I_Histo &) a_histo;
00033 if (h.dim() > 0) {
00034 Size count = 0;
00035 for( Index i=0; i<Index(h.bin_count()); i++ )
00036 count += h.i_bin(i).count();
00037
00038 return count;
00039 } else {
00040 HTL_ERR ("Invalid dimension. count is zero");
00041 return 0;
00042 }
00043 }
00044
00045 Size CLASS___::entries_count( const I_Histo &a_histo )
00046 {
00047 if( H_IID_IS_EQUAL0( a_histo._class_name()
00048 , "P_Histo1D_FTS" )
00049 )
00050 {
00051 P_Histo1D_FTS &h =
00052 (P_Histo1D_FTS &) a_histo;
00053 return h.entries_count();
00054 }
00055 if( H_IID_IS_EQUAL0( a_histo._class_name()
00056 , "P_Histo1DVar_FTS" )
00057 )
00058 {
00059 P_Histo1DVar_FTS &h =
00060 (P_Histo1DVar_FTS &) a_histo;
00061 return h.entries_count();
00062 }
00063 return extra_entries_count(a_histo) + in_range_entries_count(a_histo);
00064 }
00065
00066 double CLASS___::mean( const I_Histo &a_histo, Index p )
00067
00068
00069 {
00070 I_Histo &h = (I_Histo &) a_histo;
00071 if (h.dim() >= p) {
00072 double result = 0.0;
00073 double sum_value = 0.0;
00074 double v = 0.0;
00075 switch( h.dim() ) {
00076 case 1: {
00077 I_Histo::I_Bin_Location l(1);
00078 for( Index i=0; i<h.bin_count(); i++ ) {
00079 l[0] = i;
00080 v = h.i_bin(l).value();
00081 result += v * H_Bin_Helper::bin_center(a_histo, p, l);
00082 sum_value += v;
00083 }
00084 break;
00085 }
00086 case 2: {
00087 I_Histo::I_Bin_Location l(2);
00088 for( Index j=0; j<h.i_partition(1).bin_count(); j++ ) {
00089 for( Index i=0; i<h.i_partition(0).bin_count(); i++ ) {
00090 l[0] = i; l[1] = j;
00091 v = h.i_bin(l).value();
00092 result += v *H_Bin_Helper::bin_center(a_histo, p, l);
00093 sum_value += v;
00094 }
00095 }
00096 break;
00097 }
00098 case 3: {
00099 I_Histo::I_Bin_Location l(3);
00100 for( Index k=0; k<h.i_partition(2).bin_count(); k++ )
00101 for( Index j=0; j<h.i_partition(1).bin_count(); j++ )
00102 for( Index i=0; i<h.i_partition(0).bin_count(); i++ ) {
00103 l[0] = i; l[1] = j; l[2] = k;
00104 v = h.i_bin(l).value();
00105 result += v *H_Bin_Helper::bin_center(a_histo, p, l);
00106 sum_value += v;
00107 }
00108 break;
00109 }
00110 default:
00111 HTL_OUT( "Not supported" );
00112 break;
00113 }
00114 return (sum_value != 0.0) ? result / sum_value : 0.0;
00115 } else {
00116 HTL_ERR("Invalid partition index in mean(..). Mean is zero");
00117 return 0;
00118 }
00119 }
00120
00121 double CLASS___::rms( const I_Histo &a_histo, double a_mean, Index p )
00122
00123
00124
00125
00126 {
00127 I_Histo &h = (I_Histo &) a_histo;
00128 if (h.dim() >= p) {
00129 double result = 0.0;
00130 double sum_value = 0.0;
00131 double v = 0.0, t = 0.0;
00132
00133 switch( h.dim() ) {
00134 case 1: {
00135 I_Histo::I_Bin_Location l(1);
00136 for( Index i=0; i<h.bin_count(); i++ ) {
00137 l[0] = i;
00138 v = h.i_bin(l).value();
00139 t = H_Bin_Helper::bin_center(a_histo, p, l) - a_mean;
00140 result += t*t*v;
00141 sum_value += v;
00142 }
00143 break;
00144 }
00145 case 2: {
00146 I_Histo::I_Bin_Location l(2);
00147 for( Index j=0; j<h.i_partition(1).bin_count(); j++ )
00148 for( Index i=0; i<h.i_partition(0).bin_count(); i++ ) {
00149 l[0] = i; l[1] = j;
00150 v = h.i_bin(l).value();
00151 t = H_Bin_Helper::bin_center(a_histo, p, l) - a_mean;
00152 result += t*t*v;
00153 sum_value += v;
00154 }
00155 break;
00156 }
00157 case 3: {
00158 I_Histo::I_Bin_Location l(3);
00159 for( Index k=0; k<h.i_partition(2).bin_count(); k++ )
00160 for( Index j=0; j<h.i_partition(1).bin_count(); j++ )
00161 for( Index i=0; i<h.i_partition(0).bin_count(); i++ ) {
00162 l[0] = i; l[1] = j; l[2] = k;
00163 v = h.i_bin(l).value();
00164 t = H_Bin_Helper::bin_center(a_histo, p, l) - a_mean;
00165 result += t*t*v;
00166 sum_value += v;
00167 }
00168 break;
00169 }
00170 default:
00171 HTL_OUT("Not supported" );
00172 break;
00173 }
00174 return (sum_value != 0.0) ? sqrt(result/sum_value) : 0.0;
00175 } else {
00176 HTL_ERR("Invalid partition index in rms(..). rms is zero");
00177 return 0;
00178 }
00179 }
00180
00181 double CLASS___::nequival( const I_Histo &a_histo )
00182
00183 {
00184 double x = H_Bin_Helper::in_range_value( a_histo );
00185 double y = H_Bin_Helper::in_range_error( a_histo, H_Sqr() );
00186 return (y!=0.0) ? x*x/y : 0.0;
00187 }
00188
00189
00190 #undef CLASS___
00191