File indexing completed on 2025-01-18 10:11:23
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
0041
0042 bool getPoissonIntervalCalc(Int_t n, double &mu1, double &mu2, double nSigma= 1) const;
0043 double _poissonLoLUT[1000] ;
0044 double _poissonHiLUT[1000] ;
0045
0046 RooHistError();
0047 double seek(const RooAbsFunc &f, double startAt, double step, double value) const;
0048
0049
0050
0051
0052
0053
0054
0055
0056 class PoissonSum : public RooAbsFunc {
0057 public:
0058 inline PoissonSum(Int_t n) : RooAbsFunc(1), _n(n) { }
0059 inline double operator()(const double xvec[]) const override {
0060 double mu(xvec[0]);
0061 double result(1);
0062 double factorial(1);
0063 for (Int_t k = 1; k <= _n; k++) {
0064 factorial *= k;
0065 result += pow(mu, k) / factorial;
0066 }
0067 return exp(-mu)*result;
0068 };
0069 inline double getMinLimit(UInt_t ) const override { return 0; }
0070 inline double getMaxLimit(UInt_t ) const override { return RooNumber::infinity() ; }
0071 private:
0072 Int_t _n;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 class BinomialSumAsym : public RooAbsFunc {
0084 public:
0085 BinomialSumAsym(Int_t n, Int_t m) : RooAbsFunc(1), _n1(n), _N1(n+m) {
0086 }
0087 inline double operator()(const double xvec[]) const override
0088 {
0089 double p1(0.5 * (1 + xvec[0]));
0090 double p2(1 - p1);
0091 double result(0);
0092 double fact1(1);
0093 double fact2(1);
0094 for (Int_t k = 0; k <= _n1; k++) {
0095 if (k > 0) {
0096 fact2 *= k;
0097 fact1 *= _N1 - k + 1;
0098 }
0099 result += fact1 / fact2 * pow(p1, k) * pow(p2, _N1 - k);
0100 }
0101 return result;
0102 };
0103
0104 inline double getMinLimit(UInt_t ) const override { return -1; }
0105 inline double getMaxLimit(UInt_t ) const override { return +1; }
0106
0107 private:
0108 Int_t _n1 ;
0109 Int_t _N1 ;
0110 } ;
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 class BinomialSumEff : public RooAbsFunc {
0122 public:
0123 BinomialSumEff(Int_t n, Int_t m) : RooAbsFunc(1), _n1(n), _N1(n+m) {
0124 }
0125 inline double operator()(const double xvec[]) const override
0126 {
0127 double p1(xvec[0]);
0128 double p2(1 - p1);
0129 double result(0);
0130 double fact1(1);
0131 double fact2(1);
0132 for(Int_t k= 0; k <= _n1; k++) {
0133 if(k > 0) { fact2*= k; fact1*= _N1-k+1; }
0134 result+= fact1/fact2*pow(p1,k)*pow(p2,_N1-k);
0135 }
0136 return result;
0137 };
0138
0139 inline double getMinLimit(UInt_t ) const override { return 0; }
0140 inline double getMaxLimit(UInt_t ) const override { return +1; }
0141
0142 private:
0143 Int_t _n1 ;
0144 Int_t _N1 ;
0145 } ;
0146
0147 };
0148
0149 #endif