File indexing completed on 2026-08-20 09:22:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROO_HIST_ERROR
0017 #define ROO_HIST_ERROR
0018
0019 #include "Rtypes.h"
0020 #include "RooNumber.h"
0021 #include "RooAbsFunc.h"
0022 #include <cmath>
0023 #include <iostream>
0024
0025 class RooHistError {
0026 public:
0027 static const RooHistError &instance();
0028 virtual ~RooHistError() {} ;
0029
0030 bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma= 1) const;
0031 bool getBinomialIntervalAsym(Int_t n, Int_t m, double &a1, double &a2, double nSigma= 1) const;
0032 bool getBinomialIntervalEff(Int_t n, Int_t m, double &a1, double &a2, double nSigma= 1) const;
0033 bool getInterval(const RooAbsFunc *Qu, const RooAbsFunc *Ql, double pointEstimate, double stepSize,
0034 double &lo, double &hi, double nSigma) const;
0035
0036 static RooAbsFunc *createPoissonSum(Int_t n) ;
0037 static RooAbsFunc *createBinomialSum(Int_t n, Int_t m, bool eff) ;
0038
0039 private:
0040 double seek(const RooAbsFunc &f, double startAt, double step, double value) const;
0041
0042
0043
0044
0045
0046
0047
0048
0049 class PoissonSum : public RooAbsFunc {
0050 public:
0051 inline PoissonSum(Int_t n) : RooAbsFunc(1), _n(n) { }
0052 inline double operator()(const double xvec[]) const override {
0053 double mu(xvec[0]);
0054 double result(1);
0055 double factorial(1);
0056 for (Int_t k = 1; k <= _n; k++) {
0057 factorial *= k;
0058 result += pow(mu, k) / factorial;
0059 }
0060 return exp(-mu)*result;
0061 };
0062 inline double getMinLimit(UInt_t ) const override { return 0; }
0063 inline double getMaxLimit(UInt_t ) const override { return RooNumber::infinity() ; }
0064 private:
0065 Int_t _n;
0066 };
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 class BinomialSumAsym : public RooAbsFunc {
0077 public:
0078 BinomialSumAsym(Int_t n, Int_t m) : RooAbsFunc(1), _n1(n), _N1(n+m) {
0079 }
0080 inline double operator()(const double xvec[]) const override
0081 {
0082 double p1(0.5 * (1 + xvec[0]));
0083 double p2(1 - p1);
0084 double result(0);
0085 double fact1(1);
0086 double fact2(1);
0087 for (Int_t k = 0; k <= _n1; k++) {
0088 if (k > 0) {
0089 fact2 *= k;
0090 fact1 *= _N1 - k + 1;
0091 }
0092 result += fact1 / fact2 * pow(p1, k) * pow(p2, _N1 - k);
0093 }
0094 return result;
0095 };
0096
0097 inline double getMinLimit(UInt_t ) const override { return -1; }
0098 inline double getMaxLimit(UInt_t ) const override { return +1; }
0099
0100 private:
0101 Int_t _n1 ;
0102 Int_t _N1 ;
0103 } ;
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 class BinomialSumEff : public RooAbsFunc {
0115 public:
0116 BinomialSumEff(Int_t n, Int_t m) : RooAbsFunc(1), _n1(n), _N1(n+m) {
0117 }
0118 inline double operator()(const double xvec[]) const override
0119 {
0120 double p1(xvec[0]);
0121 double p2(1 - p1);
0122 double result(0);
0123 double fact1(1);
0124 double fact2(1);
0125 for(Int_t k= 0; k <= _n1; k++) {
0126 if(k > 0) { fact2*= k; fact1*= _N1-k+1; }
0127 result+= fact1/fact2*pow(p1,k)*pow(p2,_N1-k);
0128 }
0129 return result;
0130 };
0131
0132 inline double getMinLimit(UInt_t ) const override { return 0; }
0133 inline double getMaxLimit(UInt_t ) const override { return +1; }
0134
0135 private:
0136 Int_t _n1 ;
0137 Int_t _N1 ;
0138 } ;
0139
0140 };
0141
0142 #endif