14 # pragma warning( disable : 1572 ) 27 #include "AIDA/IAxis.h" 28 #include "AIDA/IHistogram1D.h" 29 #include "AIDA/IProfile1D.h" 52 double _nEff(
const AIDA::IHistogram1D* histo ) {
return ( histo ? histo->equivalentBinEntries() : s_bad ); }
53 double _nEff(
const AIDA::IProfile1D* histo ) {
55 return ( histo ? histo->sumBinHeights() : s_bad );
60 template <
typename HISTO>
61 double _rms(
const HISTO* histo ) {
62 return ( histo ? histo->rms() : s_bad );
67 template <
typename HISTO>
68 double _mean(
const HISTO* histo ) {
69 return ( histo ? histo->mean() : s_bad );
74 template <
typename HISTO>
75 double _moment(
const HISTO* histo,
const unsigned int order,
const double value = 0 ) {
76 if (
UNLIKELY( !histo ) ) {
return s_bad; }
77 if ( 0 == order ) {
return 1.0; }
78 if ( 1 == order ) {
return _mean( histo ) - value; }
80 const auto _r = _rms( histo );
81 const auto _d = value - _mean( histo );
84 const auto n = _nEff( histo );
85 if ( 0 >=
n ) {
return 0.0; }
87 const auto& axis = histo->axis();
89 const auto nBins = axis.bins();
90 double result{0}, weight{0};
92 for (
int i = 0; i < nBins; ++i ) {
93 const auto lE = axis.binLowerEdge( i );
94 const auto uE = axis.binUpperEdge( i );
96 const auto yBin = histo->binHeight( i );
97 const auto xBin = 0.5 * double( lE + uE );
100 result += yBin *
std::pow( xBin - value, order );
102 if ( 0 != weight ) { result /= weight; }
108 template <
typename HISTO>
109 double _momentErr(
const HISTO* histo,
const unsigned int order ) {
110 if (
UNLIKELY( !histo ) ) {
return s_bad; }
111 const auto n = _nEff( histo );
112 if ( 0 >=
n ) {
return 0.0; }
113 const auto a2o = _moment( histo, 2 * order );
114 const auto ao = _moment( histo, order );
121 template <
typename HISTO>
122 double _centralMoment(
const HISTO* histo,
const unsigned int order ) {
123 if (
UNLIKELY( !histo ) ) {
return s_bad; }
124 if ( 0 == order ) {
return 1.0; }
125 if ( 1 == order ) {
return 0.0; }
127 return std::pow( _rms( histo ), 2 );
130 return _moment( histo, order, _mean( histo ) );
135 template <
typename HISTO>
136 double _centralMomentErr(
const HISTO* histo,
const unsigned int order ) {
137 if (
UNLIKELY( !histo ) ) {
return s_bad; }
138 const auto n = _nEff( histo );
139 if ( 0 >=
n ) {
return 0.0; }
140 const auto mu2 = _centralMoment( histo, 2 );
141 const auto muo = _centralMoment( histo, order );
142 const auto mu2o = _centralMoment( histo, 2 * order );
143 const auto muom = _centralMoment( histo, order - 1 );
144 const auto muop = _centralMoment( histo, order + 1 );
146 ( mu2o - ( 2.0 * order * muom * muop ) -
std::pow( muo, 2 ) + ( order * order * mu2 * muom * muom ) ) /
n;
152 template <
typename HISTO>
153 double _skewness(
const HISTO* histo ) {
154 if (
UNLIKELY( !histo ) ) {
return s_bad; }
155 const auto mu3 = _centralMoment( histo, 3 );
156 const auto s3 =
std::pow( _rms( histo ), 3 );
157 return (
std::fabs( s3 ) > 0 ? mu3 / s3 : 0.0 );
162 template <
typename HISTO>
163 double _skewnessErr(
const HISTO* histo ) {
164 if (
UNLIKELY( !histo ) ) {
return s_bad; }
165 const auto n = _nEff( histo );
166 if ( 2 >
n ) {
return 0.0; }
167 const auto result = 6.0 * (
n - 2 ) / ( (
n + 1 ) * (
n + 3 ) );
173 template <
typename HISTO>
174 double _kurtosis(
const HISTO* histo ) {
175 if (
UNLIKELY( !histo ) ) {
return s_bad; }
176 const auto mu4 = _centralMoment( histo, 4 );
177 const auto s4 =
std::pow( _rms( histo ), 4 );
178 return (
std::fabs( s4 ) > 0 ? mu4 / s4 - 3.0 : 0.0 );
183 template <
typename HISTO>
184 double _kurtosisErr(
const HISTO* histo ) {
185 if (
UNLIKELY( !histo ) ) {
return s_bad; }
186 const auto n = _nEff( histo );
187 if ( 3 >
n ) {
return 0.0; }
188 auto result = 24.0 *
n;
189 result *= (
n - 2 ) * (
n - 3 );
190 result /= (
n + 1 ) * (
n + 1 );
191 result /= (
n + 3 ) * (
n + 5 );
197 template <
typename HISTO>
198 double _meanErr(
const HISTO* histo ) {
199 if (
UNLIKELY( !histo ) ) {
return s_bad; }
200 const auto n = _nEff( histo );
201 return ( 0 >=
n ? 0.0 : _rms( histo ) /
std::sqrt(
n ) );
206 template <
typename HISTO>
207 double _rmsErr(
const HISTO* histo ) {
208 if (
UNLIKELY( !histo ) ) {
return s_bad; }
209 const auto n = _nEff( histo );
210 if ( 1 >=
n ) {
return 0.0; }
211 auto result = 2.0 + _kurtosis( histo );
212 result += 2.0 / (
n - 1 );
219 template <
typename HISTO>
220 double _sumBinHeightErr(
const HISTO* histo ) {
221 if (
UNLIKELY( !histo ) ) {
return s_bad; }
225 const auto& axis = histo->axis();
227 const auto nBins = axis.bins();
229 for (
int i = 0; i < nBins; ++i ) {
231 error2 +=
std::pow( histo->binError( i ), 2 );
238 template <
typename HISTO>
239 double _sumAllBinHeightErr(
const HISTO* histo ) {
240 if (
UNLIKELY( !histo ) ) {
return s_bad; }
242 const auto error = _sumBinHeightErr( histo );
243 if ( 0 > error ) {
return s_bad; }
245 const auto err1 = histo->binError( AIDA::IAxis::UNDERFLOW_BIN );
246 const auto err2 = histo->binError( AIDA::IAxis::OVERFLOW_BIN );
253 template <
typename HISTO>
254 double _overflowEntriesFrac(
const HISTO* histo ) {
255 if (
UNLIKELY( !histo ) ) {
return s_bad; }
256 const auto overflow = histo->binEntries( AIDA::IAxis::OVERFLOW_BIN );
257 if ( 0 == overflow ) {
return 0; }
258 const auto all = histo->allEntries();
259 if ( 0 == all ) {
return 0; }
260 if ( 0 > all ) {
return s_bad; }
262 return (
double)overflow / (double)all;
267 template <
typename HISTO>
268 double _underflowEntriesFrac(
const HISTO* histo ) {
269 if (
UNLIKELY( !histo ) ) {
return s_bad; }
270 const auto underflow = histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN );
271 if ( 0 == underflow ) {
return 0; }
272 const auto all = histo->allEntries();
273 if ( 0 == all ) {
return 0; }
274 if ( 0 > all ) {
return s_bad; }
276 return (
double)underflow / (double)all;
281 template <
typename HISTO>
282 double _overflowIntegralFrac(
const HISTO* histo ) {
283 if (
UNLIKELY( !histo ) ) {
return s_bad; }
284 const auto overflow = histo->binHeight( AIDA::IAxis::OVERFLOW_BIN );
285 if ( 0 == overflow ) {
return 0; }
286 const auto all = histo->sumAllBinHeights();
287 if ( 0 == all ) {
return 0; }
289 return (
double)overflow / (double)all;
294 template <
typename HISTO>
295 double _underflowIntegralFrac(
const HISTO* histo ) {
296 if (
UNLIKELY( !histo ) ) {
return s_bad; }
297 const auto underflow = histo->binHeight( AIDA::IAxis::UNDERFLOW_BIN );
298 if ( 0 == underflow ) {
return 0; }
299 const auto all = histo->sumAllBinHeights();
300 if ( 0 == all ) {
return 0; }
302 return (
double)underflow / (double)all;
307 template <
typename HISTO>
308 double _overflowEntriesFracErr(
const HISTO* histo ) {
309 if (
UNLIKELY( !histo ) ) {
return s_bad; }
311 const auto overflow = histo->binEntries( AIDA::IAxis::OVERFLOW_BIN );
312 const auto all = histo->allEntries();
314 if ( 0 > overflow || 0 >= all || overflow > all ) {
return s_bad; }
316 const double n =
std::max( (
double)overflow, 1.0 );
317 const double N = all;
325 template <
typename HISTO>
326 double _underflowEntriesFracErr(
const HISTO* histo ) {
327 if (
UNLIKELY( !histo ) ) {
return s_bad; }
329 const auto underflow = histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN );
330 const auto all = histo->allEntries();
332 if ( 0 > underflow || 0 >= all || underflow > all ) {
return s_bad; }
334 const double n =
std::max( (
double)underflow, 1.0 );
335 const double N = all;
343 template <
typename HISTO>
344 double _overflowIntegralFracErr(
const HISTO* histo ) {
345 if (
UNLIKELY( !histo ) ) {
return s_bad; }
347 const auto all = histo->sumAllBinHeights();
348 if ( 0 == all ) {
return s_bad; }
349 const auto overflow = histo->binHeight( AIDA::IAxis::OVERFLOW_BIN );
350 const auto oErr = histo->binError( AIDA::IAxis::OVERFLOW_BIN );
351 if ( 0 > oErr ) {
return s_bad; }
352 const auto aErr = _sumAllBinHeightErr( histo );
353 if ( 0 > aErr ) {
return s_bad; }
355 auto error2 =
std::pow( (
double)oErr, 2 );
357 error2 /=
std::pow( (
double)all, 2 );
364 template <
typename HISTO>
365 double _underflowIntegralFracErr(
const HISTO* histo ) {
366 if (
UNLIKELY( !histo ) ) {
return s_bad; }
368 const auto all = histo->sumAllBinHeights();
369 if ( 0 == all ) {
return s_bad; }
370 const auto underflow = histo->binHeight( AIDA::IAxis::UNDERFLOW_BIN );
371 const auto oErr = histo->binError( AIDA::IAxis::UNDERFLOW_BIN );
372 if ( 0 > oErr ) {
return s_bad; }
373 const auto aErr = _sumAllBinHeightErr( histo );
374 if ( 0 > aErr ) {
return s_bad; }
376 auto error2 =
std::pow( (
double)oErr, 2 );
378 error2 /=
std::pow( (
double)all, 2 );
385 template <
typename HISTO>
386 long _nEntries(
const HISTO* histo,
const int imax ) {
387 if (
UNLIKELY( !histo ) ) {
return s_long_bad; }
388 if ( 0 > imax ) {
return 0; }
389 long result = histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN );
392 const auto& axis = histo->axis();
394 const auto nBins = axis.bins();
396 for (
int i = 0; i < nBins && i < imax; ++i ) { result += histo->binEntries( i ); }
398 if ( nBins < imax ) { result += histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ); }
405 template <
typename HISTO>
406 long _nEntries(
const HISTO* histo,
410 if (
UNLIKELY( !histo ) ) {
return s_long_bad; }
411 if ( imin == imax ) {
return 0; }
412 if ( imax < imin ) {
return _nEntries( histo, imax, imin ); }
415 if ( 0 > imin ) { result += histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ); }
417 const auto& axis = histo->axis();
419 const auto nBins = axis.bins();
420 if ( nBins < imin ) {
return 0; }
422 for (
int i = imin; i < nBins && imin <= i && i < imax; ++i ) { result += histo->binEntries( i ); }
424 if ( nBins < imax ) { result += histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ); }
431 template <
typename HISTO>
432 double _nEntriesFrac(
const HISTO* histo,
const int imax ) {
433 if (
UNLIKELY( !histo ) ) {
return s_bad; }
435 const auto N = histo->allEntries();
436 if ( 0 >=
N ) {
return s_bad; }
437 const auto n = _nEntries( histo, imax );
438 if ( 0 >
n ) {
return s_bad; }
439 if (
n >
N ) {
return s_bad; }
441 return (
double)
n / (double)
N;
447 template <
typename HISTO>
448 double _nEntriesFrac(
const HISTO* histo,
452 if (
UNLIKELY( !histo ) ) {
return s_bad; }
453 const auto N = histo->allEntries();
454 if ( 0 >=
N ) {
return s_bad; }
455 const auto n = _nEntries( histo, imin, imax );
456 if ( 0 >
n ) {
return s_bad; }
457 if (
n >
N ) {
return s_bad; }
459 return (
double)
n / (double)
N;
464 template <
typename HISTO>
465 double _nEntriesFracErr(
const HISTO* histo,
const int imax ) {
466 if (
UNLIKELY( !histo ) ) {
return s_bad; }
468 const auto N = histo->allEntries();
469 if ( 0 >=
N ) {
return s_bad; }
470 const auto n = _nEntries( histo, imax );
471 if ( 0 >
n ) {
return s_bad; }
472 if (
n >
N ) {
return s_bad; }
474 const auto _n1 =
std::max( (
double)
n, 1.0 );
475 const auto _n2 =
std::max( (
double)(
N -
n ), 1.0 );
482 template <
typename HISTO>
483 double _nEntriesFracErr(
const HISTO* histo,
487 if (
UNLIKELY( !histo ) ) {
return s_bad; }
489 const auto N = histo->allEntries();
490 if ( 0 >=
N ) {
return s_bad; }
491 const auto n = _nEntries( histo, imin, imax );
492 if ( 0 >
n ) {
return s_bad; }
493 if (
n >
N ) {
return s_bad; }
495 const auto _n1 =
std::max( (
double)
n, 1.0 );
496 const auto _n2 =
std::max( (
double)(
N -
n ), 1.0 );
510 const double value ) {
511 return _moment( histo, order, value );
522 return _moment( histo, order, value );
533 return _momentErr( histo, order );
544 return _momentErr( histo, order );
555 return _centralMoment( histo, order );
566 return _centralMoment( histo, order );
579 return _centralMomentErr( histo, order );
592 return _centralMomentErr( histo, order );
670 return _sumBinHeightErr( histo );
680 return _sumAllBinHeightErr( histo );
686 return _sumAllBinHeightErr( histo );
692 return _overflowEntriesFrac( histo );
698 return _overflowEntriesFrac( histo );
704 return _underflowEntriesFrac( histo );
710 return _underflowEntriesFrac( histo );
716 return _overflowIntegralFrac( histo );
722 return _overflowIntegralFrac( histo );
728 return _underflowIntegralFrac( histo );
734 return _underflowIntegralFrac( histo );
740 return _overflowEntriesFracErr( histo );
746 return _overflowEntriesFracErr( histo );
752 return _underflowEntriesFracErr( histo );
758 return _underflowEntriesFracErr( histo );
764 return _overflowIntegralFracErr( histo );
770 return _overflowIntegralFracErr( histo );
776 return _underflowIntegralFracErr( histo );
782 return _underflowIntegralFracErr( histo );
794 return _nEntries( histo, imax );
806 return _nEntries( histo, imax );
821 return _nEntries( histo, imin, imax );
836 return _nEntries( histo, imin, imax );
848 return _nEntriesFrac( histo, imax );
860 return _nEntriesFrac( histo, imax );
875 return _nEntriesFrac( histo, imin, imax );
890 return _nEntriesFrac( histo, imin, imax );
902 return _nEntriesFracErr( histo, imax );
914 return _nEntriesFracErr( histo, imax );
929 return _nEntriesFracErr( histo, imin, imax );
944 return _nEntriesFracErr( histo, imin, imax );
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