Gaudi Framework, version v21r7

Home   Generated: 22 Jan 2010

HistoStats.cpp

Go to the documentation of this file.
00001 // $Id: HistoStats.cpp,v 1.5 2008/06/04 08:18:22 marcocle Exp $
00002 // ============================================================================
00003 // Include files 
00004 // ============================================================================
00005 // STD & STL 
00006 // ============================================================================
00007 #include <cmath>
00008 #include <limits>
00009 #include <climits>
00010 // ============================================================================
00011 // AIDA 
00012 // ============================================================================
00013 #include "AIDA/IHistogram1D.h"
00014 #include "AIDA/IAxis.h"
00015 // ============================================================================
00016 // GaudiUtils 
00017 // ============================================================================
00018 #include "GaudiUtils/HistoStats.h"
00019 // ============================================================================
00025 // ============================================================================
00026 namespace 
00027 {
00028   // ==========================================================================
00030   const double s_bad      = -1 * std::numeric_limits<double>::max() ;
00032   const long   s_long_bad =      std::numeric_limits<int>::min() ;
00033   // ==========================================================================
00034 }
00035 // ============================================================================
00036 /*  get the moment of the certain around the specified  "value"
00037  *  @param histo histogram
00038  *  @param order the momentm order
00039  *  @param value central value 
00040  *  @return the evaluated moment
00041  */
00042 // ============================================================================
00043 double Gaudi::Utils::HistoStats::moment        
00044 ( const AIDA::IHistogram1D* histo , 
00045   const unsigned int        order ,  
00046   const double              value ) 
00047 {
00048   if ( 0 == histo ) { return s_bad ; }                       // RETURN
00049   if ( 0 == order ) { return 1.0   ; }                       // RETURN
00050   if ( 1 == order ) { return mean( histo ) - value ; }       // RETURN
00051   if ( 2 == order ) 
00052   {
00053     const double _r =         rms  ( histo ) ;
00054     const double _d = value - mean ( histo ) ;
00055     return _r *_r + _d * _d ;                            // RETURN
00056   }
00057   const double n = nEff ( histo )  ;
00058   if ( 0 >= n     ) { return 0.0   ; }                    // RETURN 
00059   
00060   const int _order = (int) order ;
00061   
00062   // get the exis 
00063   const AIDA::IAxis& axis = histo -> axis () ;
00064   // number of bins 
00065   const int nBins = axis.bins() ;
00066   double result = 0 ;
00067   double weight = 0 ;
00068   // loop over all bins 
00069   for ( int i = 0 ; i < nBins ; ++i ) 
00070   {
00071     const double lE   = axis . binLowerEdge ( i ) ;
00072     const double uE   = axis . binUpperEdge ( i ) ;
00073     //
00074     const double yBin = histo -> binHeight    ( i ) ;   // bin weight 
00075     const double xBin = 0.5 * ( lE + uE ) ;             // bin center 
00076     //
00077     weight += yBin ;
00078     result += yBin * std::pow ( xBin - value , _order ) ;
00079   }    
00080   if ( 0 != weight ) { result /= weight ; }
00081   return result ;
00082 }
00083 // ============================================================================
00090 // ============================================================================
00091 double Gaudi::Utils::HistoStats::momentErr
00092 ( const AIDA::IHistogram1D* histo , 
00093   const unsigned int        order ) 
00094 {
00095   if ( 0 == histo ) { return s_bad ; }                   // RETURN 
00096   const double n = nEff ( histo ) ;
00097   if ( 0 >= n     ) { return 0.0   ; }                   // RETURN
00098   const double a2o = moment ( histo , 2 * order ) ;      // a(2o)
00099   const double ao  = moment ( histo ,     order ) ;      // a(o) 
00100   double result = a2o - ao*ao ;
00101   result        /= n ;
00102   result = std::max ( 0.0 , result ) ;
00103   return std:: sqrt ( result ) ;                            // RETURN  
00104 }
00105 // ============================================================================
00106 /*  evaluate the central momentum (around the mean value) 
00107  *  @param histo histogram
00108  *  @param order the momentm order
00109  *  @param value central value 
00110  *  @return the evaluated central moment
00111  */
00112 // ============================================================================
00113 double Gaudi::Utils::HistoStats::centralMoment 
00114 ( const AIDA::IHistogram1D* histo , 
00115   const unsigned int        order ) 
00116 {
00117   if ( 0 == histo ) { return s_bad ; }                        // RETURN
00118   if ( 0 == order ) { return 1.0   ; }                        // RETURN
00119   if ( 1 == order ) { return 0.0   ; }                        // RETURN
00120   if ( 2 == order ) 
00121   {
00122     const double sigma = histo->rms() ;
00123     return sigma * sigma ;                                    // RETURN
00124   }
00125   // delegate the actual evaluation to another method:
00126   return moment ( histo , order , mean ( histo ) ) ;
00127 }
00128 // ============================================================================
00129 /*  evaluate the uncertanty for 'bin-by-bin'-central momentum 
00130  *  (around the mean value)  
00131  *  ( the uncertanty is calculated with O(1/n2) precision)
00132  *  @param histo histogram
00133  *  @param order the moment parameter 
00134  *  @param value central value 
00135  *  @return the evaluated uncertanty in the central moment
00136  */
00137 // ============================================================================
00138 double Gaudi::Utils::HistoStats::centralMomentErr
00139 ( const AIDA::IHistogram1D* histo , 
00140   const unsigned int        order ) 
00141 {
00142   if ( 0 == histo ) { return s_bad ; }                    // RETURN
00143   const double n    = nEff ( histo ) ;
00144   if ( 0 >= n     ) { return 0.0   ; }                    // RETURN
00145   const double mu2  = centralMoment ( histo , 2             ) ; // mu(2)
00146   const double muo  = centralMoment ( histo ,     order     ) ; // mu(o)
00147   const double mu2o = centralMoment ( histo , 2 * order     ) ; // mu(2o)
00148   const double muom = centralMoment ( histo ,     order - 1 ) ; // mu(o-1)
00149   const double muop = centralMoment ( histo ,     order + 1 ) ; // mu(o+1)
00150   double result  =  mu2o  ;
00151   result        -=  2.0   * order * muom * muop ;
00152   result        -=  muo   * muo   ;
00153   result        +=  order * order * mu2  * muom * muom ;
00154   result        /=  n     ;
00155   result = std::max ( 0.0 , result ) ;
00156   return std:: sqrt ( result ) ;                            // RETURN
00157 }
00158 // ============================================================================
00159 // get the skewness for the histogram 
00160 // ============================================================================
00161 double Gaudi::Utils::HistoStats::skewness        
00162 ( const AIDA::IHistogram1D* histo ) 
00163 {
00164   if ( 0 == histo ) { return s_bad ; }                      // RETURN
00165   const double mu3 = centralMoment ( histo , 3 ) ;
00166   const double s3  = std::pow ( rms ( histo ) , 3 ) ;
00167   return ( std::fabs(s3)>0 ? mu3/s3 : 0.0 );
00168 }
00169 // ============================================================================
00170 // get the error in skewness 
00171 // ============================================================================
00172 double Gaudi::Utils::HistoStats::skewnessErr 
00173 ( const AIDA::IHistogram1D* histo ) 
00174 {
00175   if ( 0 == histo ) { return s_bad ; }                     // RETURN 
00176   const double n = nEff ( histo ) ;
00177   if ( 2 > n      ) { return 0.0   ; }                     // RETURN
00178   double result = 6 ;
00179   result *= ( n - 2 )  ;
00180   result /= ( n + 1 ) * ( n + 3 ) ;    
00181   return std::sqrt ( result ) ;  
00182 }
00183 // ============================================================================
00184 // get the kurtosis for the histogram 
00185 // ============================================================================
00186 double Gaudi::Utils::HistoStats::kurtosis          
00187 ( const AIDA::IHistogram1D* histo ) 
00188 {
00189   if ( 0 == histo ) { return s_bad ; }                    // RETURN 
00190   const double mu4 = centralMoment ( histo , 4 ) ;
00191   const double s4  = std::pow ( rms ( histo ) , 4 ) ;
00192   return ( std::fabs(s4)>0 ? mu4/s4 - 3.0 : 0.0 );
00193 }
00194 // ============================================================================
00195 // get the error in kurtosis
00196 // ============================================================================
00197 double Gaudi::Utils::HistoStats::kurtosisErr 
00198 ( const AIDA::IHistogram1D* histo ) 
00199 {
00200   if ( 0 == histo ) { return s_bad ; }                    // RETURN 
00201   const double n = nEff ( histo ) ;
00202   if ( 3 > n      ) { return 0.0 ; }                      // RETURN   
00203   double result = 24 * n ;
00204   result *= ( n - 2 ) * ( n - 3 ) ;
00205   result /= ( n + 1 ) * ( n + 1 ) ;
00206   result /= ( n + 3 ) * ( n + 5 ) ;
00207   return std::sqrt ( result ) ;  
00208 }
00209 // ============================================================================
00210 // get the effective entries 
00211 // ============================================================================
00212 double Gaudi::Utils::HistoStats::nEff 
00213 ( const AIDA::IHistogram1D* histo ) 
00214 {
00215   if ( 0 == histo ) { return s_bad ; }
00216   return histo -> equivalentBinEntries () ;
00217 }
00218 // ============================================================================
00219 // get the mean value for the histogram 
00220 // ============================================================================
00221 double Gaudi::Utils::HistoStats::mean              
00222 ( const AIDA::IHistogram1D* histo ) 
00223 {
00224   if ( 0 == histo ) { return s_bad ; }
00225   return histo -> mean() ;    
00226 }
00227 // ============================================================================
00228 // get an error in the mean value 
00229 // ============================================================================
00230 double Gaudi::Utils::HistoStats::meanErr 
00231 ( const AIDA::IHistogram1D* histo ) 
00232 {
00233   if ( 0 == histo ) { return s_bad ; }
00234   const double n = nEff ( histo ) ;
00235   return 0 >= n ? 0.0 : rms ( histo ) / std::sqrt ( n ) ;
00236 }
00237 // ============================================================================
00238 // get the rms value for the histogram 
00239 // ============================================================================
00240 double Gaudi::Utils::HistoStats::rms
00241 ( const AIDA::IHistogram1D* histo ) 
00242 {
00243   if ( 0 == histo ) { return s_bad ; }
00244   return histo -> rms () ;    
00245 }
00246 // ============================================================================
00247 // get the error in rms 
00248 // ============================================================================
00249 double Gaudi::Utils::HistoStats::rmsErr  
00250 ( const AIDA::IHistogram1D* histo ) 
00251 {
00252   if ( 0 == histo ) { return s_bad ; }  
00253   const double n = nEff ( histo ) ;    
00254   if ( 1 >=  n ) { return 0.0 ; }
00255   double result = 2 + kurtosis ( histo ) ;
00256   result += 2.0 /( n - 1 ) ;
00257   result /= 4.0 * n ;
00258   result = std::max ( result , 0.0 ) ;
00259   return histo -> rms() * std::sqrt ( result ) ;
00260 }
00261 // ============================================================================
00262 // get an error in the sum bin height ("in range integral")
00263 // ============================================================================
00264 double Gaudi::Utils::HistoStats::sumBinHeightErr
00265 ( const AIDA::IHistogram1D* histo ) 
00266 {
00267   if ( 0 == histo ) { return s_bad ; }  
00268   //
00269   double error2 = 0 ;
00270   // get the exis 
00271   const AIDA::IAxis& axis = histo -> axis () ;
00272   // number of bins 
00273   const int nBins = axis.bins() ;
00274   // loop over all bins 
00275   for ( int i = 0 ; i < nBins ; ++i ) 
00276   {
00277     // get the error in each bin 
00278     const double berr = histo->binError ( i ) ;
00279     // accumulate the errors: 
00280     error2 += berr * berr ;    
00281   } 
00282   return std::sqrt ( error2 ) ;
00283 }
00284 // ============================================================================
00285 // get an error in the sum all bin height ("integral")
00286 // ============================================================================
00287 double Gaudi::Utils::HistoStats::sumAllBinHeightErr
00288 ( const AIDA::IHistogram1D* histo ) 
00289 {
00290   if ( 0 == histo ) { return s_bad ; }  
00291   //
00292   const double error = sumBinHeightErr( histo ) ;
00293   if ( 0 > error ) { return s_bad ; }
00295   const double err1 = histo->binError ( AIDA::IAxis::UNDERFLOW_BIN ) ;
00296   const double err2 = histo->binError ( AIDA::IAxis::OVERFLOW_BIN  ) ;
00297   //
00298   return std::sqrt ( error * error + err1 * err1 + err2 * err2 ) ;
00299 }
00300 // ============================================================================
00301 // the fraction of overflow entries  (useful for shape comparison)
00302 // ============================================================================
00303 double Gaudi::Utils::HistoStats::overflowEntriesFrac
00304 ( const AIDA::IHistogram1D* histo     ) 
00305 {
00306   if ( 0 == histo ) { return s_bad ; }                                // REUTRN  
00307   const long overflow = histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )  ;
00308   if ( 0 == overflow ) { return 0 ; }                                 // REUTRN 
00309   const long all      = histo->allEntries() ;
00310   if ( 0 == all      ) { return 0 ; }                  // "CONVENTION?"  RETURN 
00311   if ( 0 >  all      ) { return s_bad ; }     // Lets be a bit paranoic, RETURN
00312   //
00313   double _tmp = (double) overflow ;
00314   _tmp /= all ;
00315   //
00316   return _tmp ;
00317 }
00318 // ============================================================================
00319 // the fraction of underflow entries  (useful for shape comparison)
00320 // ============================================================================
00321 double Gaudi::Utils::HistoStats::underflowEntriesFrac
00322 ( const AIDA::IHistogram1D* histo     ) 
00323 {
00324   if ( 0 == histo ) { return s_bad ; }                                // REUTRN  
00325   const long underflow = histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )  ;
00326   if ( 0 == underflow ) { return 0 ; }                                // REUTRN 
00327   const long all      = histo->allEntries() ;
00328   if ( 0 == all      ) { return 0 ; }                  // "CONVENTION?"  RETURN 
00329   if ( 0 >  all      ) { return s_bad ; }     // Lets be a bit paranoic, RETURN
00330   //
00331   double _tmp = (double) underflow ;
00332   _tmp /= all ;
00333   //
00334   return _tmp ;
00335 }
00336 // ============================================================================
00337 // the fraction of overflow integral (useful for shape comparison)
00338 // ============================================================================
00339 double Gaudi::Utils::HistoStats::overflowIntegralFrac
00340 ( const AIDA::IHistogram1D* histo     ) 
00341 {
00342   if ( 0 == histo ) { return s_bad ; }                                // REUTRN  
00343   const double overflow = histo -> binHeight ( AIDA::IAxis::OVERFLOW_BIN )  ;
00344   if ( 0 == overflow ) { return 0 ; }                                 // REUTRN
00345   const double all      = histo -> sumAllBinHeights() ;
00346   if ( 0 == all      ) { return 0 ; }                  // "CONVENTION?"  RETURN 
00347   //
00348   return overflow / all ;
00349 }
00350 // ============================================================================
00351 // the fraction of underflow entries  (useful for shape comparison)
00352 // ============================================================================
00353 double Gaudi::Utils::HistoStats::underflowIntegralFrac
00354 ( const AIDA::IHistogram1D* histo     ) 
00355 {
00356   if ( 0 == histo ) { return s_bad ; }                                // REUTRN  
00357   const double underflow = histo -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN )  ;
00358   if ( 0 == underflow ) { return 0 ; }                                // REUTRN 
00359   const double all      = histo -> sumAllBinHeights() ;
00360   if ( 0 == all      ) { return 0 ; }                  // "CONVENTION?"  RETURN 
00361   //
00362   return underflow / all ; 
00363 }
00364 // ============================================================================
00365 // error on fraction of overflow entries  (useful for shape comparison)
00366 // ============================================================================
00367 double Gaudi::Utils::HistoStats::overflowEntriesFracErr 
00368 ( const AIDA::IHistogram1D* histo ) 
00369 {
00370   if ( 0 == histo ) { return s_bad ; } // RETURN 
00371   // 
00372   const double overflow = histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN );
00373   const double all      = histo -> allEntries () ;
00374   //
00375   if ( 0 > overflow || 0 >= all || overflow > all ) { return s_bad ; }
00376   // 
00377   const double n  = std::max ( overflow , 1.0 ) ;
00378   const double N  = all ;
00379   const double n1 = std::max ( N - n , 1.0 ) ;
00380   //
00381   return std::sqrt ( n * n1 / N ) / N ; // use the binomial formula 
00382 }
00383 // ============================================================================
00384 // error on fraction of underflow entries  (useful for shape comparison)
00385 // ============================================================================
00386 double Gaudi::Utils::HistoStats::underflowEntriesFracErr 
00387 ( const AIDA::IHistogram1D* histo ) 
00388 {
00389   if ( 0 == histo ) { return s_bad ; } // RETURN 
00390   // 
00391   const double underflow = histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN );
00392   const double all       = histo -> allEntries () ;
00393   //
00394   if ( 0 > underflow || 0 >= all || underflow > all ) { return s_bad ; }
00395   // 
00396   const double n  = std::max ( underflow , 1.0 ) ;
00397   const double N  = all ;
00398   const double n1 = std::max ( N - n , 1.0 ) ;
00399   //
00400   return std::sqrt ( n * n1 / N ) / N ; // use the binomial formula 
00401 }
00402 // ============================================================================
00403 // the error on fraction of overflow intergal 
00404 // ============================================================================
00405 double Gaudi::Utils::HistoStats::overflowIntegralFracErr 
00406 ( const AIDA::IHistogram1D* histo     ) 
00407 {
00408   if ( 0 == histo ) { return s_bad ; }                                // RETURN
00409   //
00410   const double all       = histo -> sumAllBinHeights () ;
00411   if ( 0 == all       ) { return s_bad ; }                            // RETURN 
00412   const double overflow  = histo -> binHeight ( AIDA::IAxis::OVERFLOW_BIN )  ;
00413   const double oErr      = histo -> binError  ( AIDA::IAxis::OVERFLOW_BIN )  ;
00414   if ( 0 > oErr       ) { return s_bad ; }                            // RETURN 
00415   const double aErr      = sumAllBinHeightErr ( histo ) ;
00416   if ( 0 > aErr       ) { return s_bad ; }                            // RETURN 
00417   //
00418   double error2  = oErr * oErr ;
00419   error2        += aErr * aErr * overflow * overflow / all / all ;
00420   error2        /=  all *  all ;
00421   
00422   return std::sqrt ( error2 ) ;
00423 }
00424 // ============================================================================
00425 // the error on fraction of overflow intergal 
00426 // ============================================================================
00427 double Gaudi::Utils::HistoStats::underflowIntegralFracErr 
00428 ( const AIDA::IHistogram1D* histo     ) 
00429 {
00430   if ( 0 == histo ) { return s_bad ; }                                // RETURN
00431   //
00432   const double all       = histo -> sumAllBinHeights () ;
00433   if ( 0 == all       ) { return s_bad ; }                            // RETURN 
00434   const double underflow  = histo -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN )  ;
00435   const double oErr       = histo -> binError  ( AIDA::IAxis::UNDERFLOW_BIN )  ;
00436   if ( 0 > oErr       ) { return s_bad ; }                            // RETURN 
00437   const double aErr      = sumAllBinHeightErr ( histo ) ;
00438   if ( 0 > aErr       ) { return s_bad ; }                            // RETURN 
00439   //
00440   double error2  = oErr * oErr ;
00441   error2        += aErr * aErr * underflow * underflow / all / all ;
00442   error2        /=  all *  all ;
00443   //
00444   return std::sqrt ( error2 ) ;
00445 }
00446 // ============================================================================
00447 /*  get number of entries in histogram up to the certain 
00448  *  bin (not-included)
00449  *  @attention underflow bin is included! 
00450  *  @param histo the pointer to the histogram 
00451  *  @param imax  the bin number (not included) 
00452  *  @param number of entries 
00453  */
00454 // ============================================================================
00455 long Gaudi::Utils::HistoStats::nEntries 
00456 ( const AIDA::IHistogram1D* histo , 
00457   const int                 imax  ) 
00458 {
00459   if ( 0 == histo ) { return s_long_bad ; }                            // RETURN 
00460   if ( 0 > imax   ) { return 0          ; }                            // RETURN 
00461   long result = histo -> binEntries( AIDA::IAxis::UNDERFLOW_BIN )  ;
00462   
00463   // get the exis 
00464   const AIDA::IAxis& axis = histo -> axis () ;
00465   // number of bins 
00466   const int nBins = axis.bins() ;
00467   // loop over all bins 
00468   for ( int i = 0 ; i < nBins ; ++i ) 
00469   { if ( i < imax ) { result += histo->binEntries ( i ) ; } }
00470   // 
00471   if ( nBins  < imax )
00472   { result += histo -> binEntries( AIDA::IAxis::OVERFLOW_BIN ) ; }
00473   //
00474   return result ;
00475 }
00476 // ============================================================================
00477 /*  get number of entries in histogram form the certain 
00478  *  minimal bin up to the certain maximal bin (not-included)
00479  *  @param histo the pointer to the histogram 
00480  *  @param imin  the minimal bin number (included) 
00481  *  @param imax  the maximal bin number (not included) 
00482  *  @param number of entries 
00483  */
00484 // ============================================================================
00485 long Gaudi::Utils::HistoStats::nEntries 
00486 ( const AIDA::IHistogram1D* histo , 
00487   const int                 imin  ,         //     minimal bin number (included) 
00488   const int                 imax  )         // maximal bin number (not included) 
00489 {
00490   if ( 0 == histo   ) { return s_long_bad ; }                         // RETURN 
00491   if ( imin == imax ) { return 0          ; }                         // RETURN 
00492   if ( imax < imin  ) { return nEntries  ( histo , imax ,imin ) ; }   // RETURN 
00493   //
00494   long result = 0 ;
00495   if ( 0 > imin  ) 
00496   { result += histo -> binEntries( AIDA::IAxis::UNDERFLOW_BIN )  ; }
00497   // get the exis 
00498   const AIDA::IAxis& axis = histo -> axis () ;
00499   // number of bins 
00500   const int nBins = axis.bins() ;
00501   if ( nBins  < imin ) { return 0 ; }                                 // RETURN 
00502   // loop over all bins 
00503   for ( int i = 0 ; i < nBins ; ++i ) 
00504   { if ( imin <= i && i < imax ) { result += histo->binEntries ( i ) ; } }
00505   //  
00506   if ( nBins  < imax )
00507   { result += histo -> binEntries( AIDA::IAxis::OVERFLOW_BIN ) ; }
00508   //
00509   return result ;                                                      // RETURN 
00510 }
00511 // ============================================================================
00512 /*  get the fraction of entries in histogram up to the certain 
00513  *  bin (not-included)
00514  *  @attention underflow bin is included! 
00515  *  @param histo the pointer to the histogram 
00516  *  @param imax  the bin number (not included) 
00517  *  @param fraction of entries 
00518  */
00519 // ============================================================================
00520 double Gaudi::Utils::HistoStats::nEntriesFrac 
00521 ( const AIDA::IHistogram1D* histo , 
00522   const int                 imax  ) 
00523 {
00524   if ( 0 == histo   ) { return s_bad ; }                              // RETURN
00525   //
00526   const double N = histo->allEntries () ;
00527   if ( 0 >= N       ) { return s_bad ; }                              // RETURN 
00528   const long   n = nEntries ( histo , imax ) ;
00529   if ( 0 >  n       ) { return s_bad ; }                              // RETURN 
00530   if ( n >  N       ) { return s_bad ; }                              // RETURN 
00531   //
00532   return n / N ;                                                      // REUTRN 
00533 }
00534 // ============================================================================
00535 /*  get fraction of entries in histogram form the certain 
00536  *  minimal bin up to the certain maximal bin (not-included)
00537  *  @param histo the pointer to the histogram 
00538  *  @param imin  the minimal bin number (included) 
00539  *  @param imax  the maximal bin number (not included) 
00540  *  @param fraction of entries 
00541  */
00542 // ============================================================================
00543 double Gaudi::Utils::HistoStats::nEntriesFrac 
00544 ( const AIDA::IHistogram1D* histo , 
00545   const int                 imin  ,        //     minimal bin number (included) 
00546   const int                 imax  )        // maximal bin number (not included) 
00547 {
00548   if ( 0 == histo   ) { return s_bad ; }                              // RETURN
00549   const double N = histo->allEntries () ;
00550   if ( 0 >= N       ) { return s_bad ; }                              // RETURN 
00551   const long   n = nEntries ( histo , imin , imax ) ;
00552   if ( 0 >  n       ) { return s_bad ; }                              // RETURN 
00553   if ( n >  N       ) { return s_bad ; }                              // RETURN 
00554   //
00555   return n / N ;                                                      // REUTRN 
00556 }
00557 // ============================================================================
00558 /*  get the (binominal) error for the fraction of entries 
00559  *  in histogram up to the certain bin (not-included)
00560  *  @attention underflow bin is included! 
00561  *  @param histo the pointer to the histogram 
00562  *  @param imax  the bin number (not included) 
00563  *  @param error for the fraction of entries 
00564  */
00565 // ============================================================================
00566 double Gaudi::Utils::HistoStats::nEntriesFracErr 
00567 ( const AIDA::IHistogram1D* histo , 
00568   const int                 imax  ) 
00569 {
00570   if ( 0 == histo   ) { return s_bad ; }                              // RETURN
00571   //
00572   const double N = histo->allEntries () ;
00573   if ( 0 >= N       ) { return s_bad ; }                              // RETURN 
00574   const long   n = nEntries ( histo , imax ) ;
00575   if ( 0 >  n       ) { return s_bad ; }                              // RETURN 
00576   if ( n >  N       ) { return s_bad ; }                              // RETURN 
00577   //
00578   const double _n1 = std::max ( (double)       n   , 1.0 ) ;
00579   const double _n2 = std::max (          ( N - n ) , 1.0 ) ;
00580   //
00581   return std::sqrt ( _n1 * _n2 / N ) / N ;                             // RETURN 
00582 }
00583 // ============================================================================
00584 /*  get the (binomial) error for the fraction of entries in histogram 
00585  *  from the certain minimal bin up to the certain maximal bin (not-included)
00586  *  @param histo the pointer to the histogram 
00587  *  @param imin  the minimal bin number (included) 
00588  *  @param imax  the maximal bin number (not included) 
00589  *  @param error for the fraction of entries 
00590  */
00591  // ============================================================================
00592 double Gaudi::Utils::HistoStats::nEntriesFracErr 
00593 ( const AIDA::IHistogram1D* histo , 
00594   const int                 imin  ,        //     minimal bin number (included) 
00595   const int                 imax  )        // maximal bin number (not included) 
00596 {
00597   if ( 0 == histo   ) { return s_bad ; }                              // RETURN
00598   //
00599   const double N = histo->allEntries () ;
00600   if ( 0 >= N       ) { return s_bad ; }                              // RETURN 
00601   const long   n = nEntries ( histo , imin , imax ) ;
00602   if ( 0 >  n       ) { return s_bad ; }                              // RETURN 
00603   if ( n >  N       ) { return s_bad ; }                              // RETURN 
00604   //
00605   const double _n1 = std::max ( (double)       n   , 1.0 ) ;
00606   const double _n2 = std::max (          ( N - n ) , 1.0 ) ;
00607   //
00608   return std::sqrt ( _n1 * _n2 / N ) / N ;                             // RETURN 
00609 }
00610 // ============================================================================
00611 // The END 
00612 // ============================================================================

Generated at Fri Jan 22 20:28:12 2010 for Gaudi Framework, version v21r7 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004