5 #pragma warning(disable:1572)
18 #include "AIDA/IHistogram1D.h"
19 #include "AIDA/IAxis.h"
35 const double s_bad = -1 * std::numeric_limits<double>::max() ;
49 (
const AIDA::IHistogram1D* histo ,
50 const unsigned int order ,
53 if ( 0 == histo ) {
return s_bad ; }
54 if ( 0 == order ) {
return 1.0 ; }
55 if ( 1 == order ) {
return mean( histo ) -
value ; }
58 const double _r = rms ( histo ) ;
59 const double _d = value - mean ( histo ) ;
60 return _r *_r + _d * _d ;
62 const double n = nEff ( histo ) ;
63 if ( 0 >= n ) {
return 0.0 ; }
65 const int _order = (int) order ;
68 const AIDA::IAxis& axis = histo -> axis () ;
70 const int nBins = axis.bins() ;
74 for (
int i = 0 ;
i < nBins ; ++
i )
76 const double lE = axis . binLowerEdge (
i ) ;
77 const double uE = axis . binUpperEdge (
i ) ;
79 const double yBin = histo -> binHeight (
i ) ;
80 const double xBin = 0.5 * ( lE + uE ) ;
83 result += yBin * std::pow ( xBin - value , _order ) ;
85 if ( 0 != weight ) { result /= weight ; }
97 (
const AIDA::IHistogram1D* histo ,
98 const unsigned int order )
100 if ( 0 == histo ) {
return s_bad ; }
101 const double n = nEff ( histo ) ;
102 if ( 0 >= n ) {
return 0.0 ; }
103 const double a2o = moment ( histo , 2 * order ) ;
104 const double ao = moment ( histo , order ) ;
105 double result = a2o - ao*ao ;
107 result = std::max ( 0.0 , result ) ;
108 return std:: sqrt ( result ) ;
119 (
const AIDA::IHistogram1D* histo ,
120 const unsigned int order )
122 if ( 0 == histo ) {
return s_bad ; }
123 if ( 0 == order ) {
return 1.0 ; }
124 if ( 1 == order ) {
return 0.0 ; }
127 const double sigma = histo->rms() ;
128 return sigma * sigma ;
131 return moment ( histo , order , mean ( histo ) ) ;
144 (
const AIDA::IHistogram1D* histo ,
145 const unsigned int order )
147 if ( 0 == histo ) {
return s_bad ; }
148 const double n = nEff ( histo ) ;
149 if ( 0 >= n ) {
return 0.0 ; }
150 const double mu2 = centralMoment ( histo , 2 ) ;
151 const double muo = centralMoment ( histo , order ) ;
152 const double mu2o = centralMoment ( histo , 2 * order ) ;
153 const double muom = centralMoment ( histo , order - 1 ) ;
154 const double muop = centralMoment ( histo , order + 1 ) ;
155 double result = mu2o ;
156 result -= 2.0 * order * muom * muop ;
157 result -= muo * muo ;
158 result += order * order * mu2 * muom * muom ;
160 result = std::max ( 0.0 , result ) ;
161 return std:: sqrt ( result ) ;
167 (
const AIDA::IHistogram1D* histo )
169 if ( 0 == histo ) {
return s_bad ; }
170 const double mu3 = centralMoment ( histo , 3 ) ;
171 const double s3 = std::pow ( rms ( histo ) , 3 ) ;
172 return ( std::fabs(s3)>0 ? mu3/s3 : 0.0 );
178 (
const AIDA::IHistogram1D* histo )
180 if ( 0 == histo ) {
return s_bad ; }
181 const double n = nEff ( histo ) ;
182 if ( 2 > n ) {
return 0.0 ; }
184 result *= ( n - 2 ) ;
185 result /= ( n + 1 ) * ( n + 3 ) ;
186 return std::sqrt ( result ) ;
192 (
const AIDA::IHistogram1D* histo )
194 if ( 0 == histo ) {
return s_bad ; }
195 const double mu4 = centralMoment ( histo , 4 ) ;
196 const double s4 = std::pow ( rms ( histo ) , 4 ) ;
197 return ( std::fabs(s4)>0 ? mu4/s4 - 3.0 : 0.0 );
203 (
const AIDA::IHistogram1D* histo )
205 if ( 0 == histo ) {
return s_bad ; }
206 const double n = nEff ( histo ) ;
207 if ( 3 > n ) {
return 0.0 ; }
208 double result = 24 *
n ;
209 result *= ( n - 2 ) * ( n - 3 ) ;
210 result /= ( n + 1 ) * ( n + 1 ) ;
211 result /= ( n + 3 ) * ( n + 5 ) ;
212 return std::sqrt ( result ) ;
218 (
const AIDA::IHistogram1D* histo )
220 if ( 0 == histo ) {
return s_bad ; }
221 return histo -> equivalentBinEntries () ;
227 (
const AIDA::IHistogram1D* histo )
229 if ( 0 == histo ) {
return s_bad ; }
230 return histo -> mean() ;
236 (
const AIDA::IHistogram1D* histo )
238 if ( 0 == histo ) {
return s_bad ; }
239 const double n = nEff ( histo ) ;
240 return 0 >= n ? 0.0 : rms ( histo ) / std::sqrt ( n ) ;
246 (
const AIDA::IHistogram1D* histo )
248 if ( 0 == histo ) {
return s_bad ; }
249 return histo -> rms () ;
255 (
const AIDA::IHistogram1D* histo )
257 if ( 0 == histo ) {
return s_bad ; }
258 const double n = nEff ( histo ) ;
259 if ( 1 >= n ) {
return 0.0 ; }
260 double result = 2 + kurtosis ( histo ) ;
261 result += 2.0 /( n - 1 ) ;
263 result = std::max ( result , 0.0 ) ;
264 return histo -> rms() * std::sqrt ( result ) ;
270 (
const AIDA::IHistogram1D* histo )
272 if ( 0 == histo ) {
return s_bad ; }
276 const AIDA::IAxis& axis = histo -> axis () ;
278 const int nBins = axis.bins() ;
280 for (
int i = 0 ;
i < nBins ; ++
i )
283 const double berr = histo->binError (
i ) ;
285 error2 += berr * berr ;
287 return std::sqrt ( error2 ) ;
293 (
const AIDA::IHistogram1D* histo )
295 if ( 0 == histo ) {
return s_bad ; }
297 const double error = sumBinHeightErr( histo ) ;
298 if ( 0 > error ) {
return s_bad ; }
300 const double err1 = histo->binError ( AIDA::IAxis::UNDERFLOW_BIN ) ;
301 const double err2 = histo->binError ( AIDA::IAxis::OVERFLOW_BIN ) ;
303 return std::sqrt ( error * error + err1 * err1 + err2 * err2 ) ;
309 (
const AIDA::IHistogram1D* histo )
311 if ( 0 == histo ) {
return s_bad ; }
312 const long overflow = histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN ) ;
313 if ( 0 == overflow ) {
return 0 ; }
314 const long all = histo->allEntries() ;
315 if ( 0 == all ) {
return 0 ; }
316 if ( 0 > all ) {
return s_bad ; }
318 double _tmp = (double) overflow ;
327 (
const AIDA::IHistogram1D* histo )
329 if ( 0 == histo ) {
return s_bad ; }
330 const long underflow = histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) ;
331 if ( 0 == underflow ) {
return 0 ; }
332 const long all = histo->allEntries() ;
333 if ( 0 == all ) {
return 0 ; }
334 if ( 0 > all ) {
return s_bad ; }
336 double _tmp = (double) underflow ;
345 (
const AIDA::IHistogram1D* histo )
347 if ( 0 == histo ) {
return s_bad ; }
348 const double overflow = histo -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) ;
349 if ( 0 == overflow ) {
return 0 ; }
350 const double all = histo -> sumAllBinHeights() ;
351 if ( 0 == all ) {
return 0 ; }
353 return overflow / all ;
359 (
const AIDA::IHistogram1D* histo )
361 if ( 0 == histo ) {
return s_bad ; }
362 const double underflow = histo -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ;
363 if ( 0 == underflow ) {
return 0 ; }
364 const double all = histo -> sumAllBinHeights() ;
365 if ( 0 == all ) {
return 0 ; }
367 return underflow / all ;
373 (
const AIDA::IHistogram1D* histo )
375 if ( 0 == histo ) {
return s_bad ; }
377 const double overflow = histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN );
378 const double all = histo -> allEntries () ;
380 if ( 0 > overflow || 0 >= all || overflow > all ) {
return s_bad ; }
382 const double n = std::max ( overflow , 1.0 ) ;
383 const double N = all ;
384 const double n1 = std::max ( N - n , 1.0 ) ;
386 return std::sqrt ( n * n1 / N ) /
N ;
392 (
const AIDA::IHistogram1D* histo )
394 if ( 0 == histo ) {
return s_bad ; }
396 const double underflow = histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN );
397 const double all = histo -> allEntries () ;
399 if ( 0 > underflow || 0 >= all || underflow > all ) {
return s_bad ; }
401 const double n = std::max ( underflow , 1.0 ) ;
402 const double N = all ;
403 const double n1 = std::max ( N - n , 1.0 ) ;
405 return std::sqrt ( n * n1 / N ) /
N ;
411 (
const AIDA::IHistogram1D* histo )
413 if ( 0 == histo ) {
return s_bad ; }
415 const double all = histo -> sumAllBinHeights () ;
416 if ( 0 == all ) {
return s_bad ; }
417 const double overflow = histo -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) ;
418 const double oErr = histo -> binError ( AIDA::IAxis::OVERFLOW_BIN ) ;
419 if ( 0 > oErr ) {
return s_bad ; }
420 const double aErr = sumAllBinHeightErr ( histo ) ;
421 if ( 0 > aErr ) {
return s_bad ; }
423 double error2 = oErr * oErr ;
424 error2 += aErr * aErr * overflow * overflow / all / all ;
425 error2 /= all * all ;
427 return std::sqrt ( error2 ) ;
433 (
const AIDA::IHistogram1D* histo )
435 if ( 0 == histo ) {
return s_bad ; }
437 const double all = histo -> sumAllBinHeights () ;
438 if ( 0 == all ) {
return s_bad ; }
439 const double underflow = histo -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ;
440 const double oErr = histo -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) ;
441 if ( 0 > oErr ) {
return s_bad ; }
442 const double aErr = sumAllBinHeightErr ( histo ) ;
443 if ( 0 > aErr ) {
return s_bad ; }
445 double error2 = oErr * oErr ;
446 error2 += aErr * aErr * underflow * underflow / all / all ;
447 error2 /= all * all ;
449 return std::sqrt ( error2 ) ;
461 (
const AIDA::IHistogram1D* histo ,
464 if ( 0 == histo ) {
return s_long_bad ; }
465 if ( 0 > imax ) {
return 0 ; }
466 long result = histo -> binEntries( AIDA::IAxis::UNDERFLOW_BIN ) ;
469 const AIDA::IAxis& axis = histo -> axis () ;
471 const int nBins = axis.bins() ;
473 for (
int i = 0 ;
i < nBins ; ++
i )
474 {
if (
i < imax ) { result += histo->binEntries (
i ) ; } }
477 { result += histo -> binEntries( AIDA::IAxis::OVERFLOW_BIN ) ; }
491 (
const AIDA::IHistogram1D* histo ,
495 if ( 0 == histo ) {
return s_long_bad ; }
496 if ( imin == imax ) {
return 0 ; }
497 if ( imax < imin ) {
return nEntries ( histo , imax ,imin ) ; }
501 { result += histo -> binEntries( AIDA::IAxis::UNDERFLOW_BIN ) ; }
503 const AIDA::IAxis& axis = histo -> axis () ;
505 const int nBins = axis.bins() ;
506 if ( nBins < imin ) {
return 0 ; }
508 for (
int i = 0 ;
i < nBins ; ++
i )
509 {
if ( imin <=
i &&
i < imax ) { result += histo->binEntries (
i ) ; } }
512 { result += histo -> binEntries( AIDA::IAxis::OVERFLOW_BIN ) ; }
526 (
const AIDA::IHistogram1D* histo ,
529 if ( 0 == histo ) {
return s_bad ; }
531 const double N = histo->allEntries () ;
532 if ( 0 >= N ) {
return s_bad ; }
533 const long n = nEntries ( histo , imax ) ;
534 if ( 0 > n ) {
return s_bad ; }
535 if ( n > N ) {
return s_bad ; }
549 (
const AIDA::IHistogram1D* histo ,
553 if ( 0 == histo ) {
return s_bad ; }
554 const double N = histo->allEntries () ;
555 if ( 0 >= N ) {
return s_bad ; }
556 const long n = nEntries ( histo , imin , imax ) ;
557 if ( 0 > n ) {
return s_bad ; }
558 if ( n > N ) {
return s_bad ; }
572 (
const AIDA::IHistogram1D* histo ,
575 if ( 0 == histo ) {
return s_bad ; }
577 const double N = histo->allEntries () ;
578 if ( 0 >= N ) {
return s_bad ; }
579 const long n = nEntries ( histo , imax ) ;
580 if ( 0 > n ) {
return s_bad ; }
581 if ( n > N ) {
return s_bad ; }
583 const double _n1 = std::max ( (
double) n , 1.0 ) ;
584 const double _n2 = std::max ( ( N - n ) , 1.0 ) ;
586 return std::sqrt ( _n1 * _n2 / N ) /
N ;
598 (
const AIDA::IHistogram1D* histo ,
602 if ( 0 == histo ) {
return s_bad ; }
604 const double N = histo->allEntries () ;
605 if ( 0 >= N ) {
return s_bad ; }
606 const long n = nEntries ( histo , imin , imax ) ;
607 if ( 0 > n ) {
return s_bad ; }
608 if ( n > N ) {
return s_bad ; }
610 const double _n1 = std::max ( (
double) n , 1.0 ) ;
611 const double _n2 = std::max ( ( N - n ) , 1.0 ) ;
613 return std::sqrt ( _n1 * _n2 / N ) /
N ;
static double underflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow integral
static double overflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of overflow intergal
static double momentErr(const AIDA::IHistogram1D *histo, const unsigned int order)
evaluate the uncertanty for 'bin-by-bin'-moment
static double underflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow entries (useful for shape comparison)
static long nEntries(const AIDA::IHistogram1D *histo, const int imax)
get number of entries in histogram up to the certain bin (not-included)
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
static double underflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow integral (useful for shape comparison)
static double moment(const AIDA::IHistogram1D *histo, const unsigned int order, const double value=0)
get the "bin-by-bin"-moment around the specified "value"
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
static double nEntriesFrac(const AIDA::IHistogram1D *histo, const int imax)
get the fraction of entries in histogram up to the certain bin (not-included)
static double overflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow intergal (useful for shape comparison)
static double centralMoment(const AIDA::IHistogram1D *histo, const unsigned int order)
evaluate the 'bin-by-bin'-central moment (around the mean value)
static double centralMomentErr(const AIDA::IHistogram1D *histo, const unsigned int order)
evaluate the uncertanty for 'bin-by-bin'-central moment (around the mean value) ( the uncertanty is c...
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
static double overflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow entries (useful for shape comparison)
static double nEntriesFracErr(const AIDA::IHistogram1D *histo, const int imax)
get the (binominal) error for the fraction of entries in histogram up to the certain bin (not-include...
static double sumBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum bin height ("in-range integral")
static double overflowEntriesFracErr(const AIDA::IHistogram1D *histo)
error on fraction of overflow entries (useful for shape comparison)
static double sumAllBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum of all bin height ("integral")
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
static double mean(const AIDA::IHistogram1D *histo)
get the mean value for the histogram (just for completeness)
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
static double underflowEntriesFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow entries (useful for shape comparison)
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
static double nEff(const AIDA::IHistogram1D *histo)
get the effective entries (just for completeness)
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram