Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooHistError.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooHistError.h,v 1.14 2007/05/11 09:11:30 verkerke Exp $
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_HIST_ERROR
17#define ROO_HIST_ERROR
18
19#include "Rtypes.h"
20#include "RooNumber.h"
21#include "RooAbsFunc.h"
22#include <cmath>
23#include <iostream>
24
26public:
27 static const RooHistError &instance();
28 virtual ~RooHistError() {} ;
29
30 bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma= 1) const;
31 bool getBinomialIntervalAsym(Int_t n, Int_t m, double &a1, double &a2, double nSigma= 1) const;
32 bool getBinomialIntervalEff(Int_t n, Int_t m, double &a1, double &a2, double nSigma= 1) const;
33 bool getInterval(const RooAbsFunc *Qu, const RooAbsFunc *Ql, double pointEstimate, double stepSize,
34 double &lo, double &hi, double nSigma) const;
35
37 static RooAbsFunc *createBinomialSum(Int_t n, Int_t m, bool eff) ;
38
39private:
40
41
42 bool getPoissonIntervalCalc(Int_t n, double &mu1, double &mu2, double nSigma= 1) const;
43 double _poissonLoLUT[1000] ;
44 double _poissonHiLUT[1000] ;
45
47 double seek(const RooAbsFunc &f, double startAt, double step, double value) const;
48
49 // -----------------------------------------------------------
50 // Define a 1-dim RooAbsFunc of mu that evaluates the sum:
51 //
52 // Q(n|mu) = Sum_{k=nullptr}^{n} P(k|mu)
53 //
54 // where P(n|mu) = exp(-mu) mu**n / n! is the Poisson PDF.
55 // -----------------------------------------------------------
56 class PoissonSum : public RooAbsFunc {
57 public:
58 inline PoissonSum(Int_t n) : RooAbsFunc(1), _n(n) { }
59 inline double operator()(const double xvec[]) const override {
60 double mu(xvec[0]);
61 double result(1);
62 double factorial(1);
63 for (Int_t k = 1; k <= _n; k++) {
64 factorial *= k;
65 result += pow(mu, k) / factorial;
66 }
67 return exp(-mu)*result;
68 };
69 inline double getMinLimit(UInt_t /*index*/) const override { return 0; }
70 inline double getMaxLimit(UInt_t /*index*/) const override { return RooNumber::infinity() ; }
71 private:
73 };
74
75 // -----------------------------------------------------------
76 // Define a 1-dim RooAbsFunc of a that evaluates the sum:
77 //
78 // Q(n|n+m,a) = Sum_{k=nullptr}^{n} B(k|n+m,a)
79 //
80 // where B(n|n+m,a) = (n+m)!/(n!m!) ((1+a)/2)**n ((1-a)/2)**m
81 // is the Binomial PDF.
82 // -----------------------------------------------------------
83 class BinomialSumAsym : public RooAbsFunc {
84 public:
86 }
87 inline double operator()(const double xvec[]) const override
88 {
89 double p1(0.5 * (1 + xvec[0]));
90 double p2(1 - p1);
91 double result(0);
92 double fact1(1);
93 double fact2(1);
94 for (Int_t k = 0; k <= _n1; k++) {
95 if (k > 0) {
96 fact2 *= k;
97 fact1 *= _N1 - k + 1;
98 }
99 result += fact1 / fact2 * pow(p1, k) * pow(p2, _N1 - k);
100 }
101 return result;
102 };
103
104 inline double getMinLimit(UInt_t /*index*/) const override { return -1; }
105 inline double getMaxLimit(UInt_t /*index*/) const override { return +1; }
106
107 private:
108 Int_t _n1 ; ///< WVE Solaris CC5 doesn't want _n or _N here (likely compiler bug)
110 } ;
111
112
113 // -----------------------------------------------------------
114 // Define a 1-dim RooAbsFunc of a that evaluates the sum:
115 //
116 // Q(n|n+m,a) = Sum_{k=nullptr}^{n} B(k|n+m,a)
117 //
118 // where B(n|n+m,a) = (n+m)!/(n!m!) ((1+a)/2)**n ((1-a)/2)**m
119 // is the Binomial PDF.
120 // -----------------------------------------------------------
121 class BinomialSumEff : public RooAbsFunc {
122 public:
124 }
125 inline double operator()(const double xvec[]) const override
126 {
127 double p1(xvec[0]);
128 double p2(1 - p1);
129 double result(0);
130 double fact1(1);
131 double fact2(1);
132 for(Int_t k= 0; k <= _n1; k++) {
133 if(k > 0) { fact2*= k; fact1*= _N1-k+1; }
134 result+= fact1/fact2*pow(p1,k)*pow(p2,_N1-k);
135 }
136 return result;
137 };
138
139 inline double getMinLimit(UInt_t /*index*/) const override { return 0; }
140 inline double getMaxLimit(UInt_t /*index*/) const override { return +1; }
141
142 private:
143 Int_t _n1 ; ///< WVE Solaris CC5 doesn't want _n or _N here (likely compiler bug)
145 } ;
146
147};
148
149#endif
#define f(i)
Definition RSha256.hxx:104
int Int_t
Definition RtypesCore.h:45
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
#define hi
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition RooAbsFunc.h:27
double getMaxLimit(UInt_t) const override
Int_t _n1
WVE Solaris CC5 doesn't want _n or _N here (likely compiler bug)
BinomialSumAsym(Int_t n, Int_t m)
double operator()(const double xvec[]) const override
double getMinLimit(UInt_t) const override
BinomialSumEff(Int_t n, Int_t m)
double operator()(const double xvec[]) const override
double getMinLimit(UInt_t) const override
double getMaxLimit(UInt_t) const override
Int_t _n1
WVE Solaris CC5 doesn't want _n or _N here (likely compiler bug)
double getMinLimit(UInt_t) const override
double getMaxLimit(UInt_t) const override
double operator()(const double xvec[]) const override
Singleton class used to calculate the error bars for each bin of a RooHist object.
bool getBinomialIntervalAsym(Int_t n, Int_t m, double &a1, double &a2, double nSigma=1) const
Return 'nSigma' binomial confidence interval for (n,m).
double _poissonLoLUT[1000]
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
virtual ~RooHistError()
bool getBinomialIntervalEff(Int_t n, Int_t m, double &a1, double &a2, double nSigma=1) const
Return 'nSigma' binomial confidence interval for (n,m).
bool getPoissonIntervalCalc(Int_t n, double &mu1, double &mu2, double nSigma=1) const
Calculate a confidence interval for the expected number of events given n observed (unweighted) event...
bool getInterval(const RooAbsFunc *Qu, const RooAbsFunc *Ql, double pointEstimate, double stepSize, double &lo, double &hi, double nSigma) const
Calculate a confidence interval using the cumulative functions provided.
double seek(const RooAbsFunc &f, double startAt, double step, double value) const
Scan f(x)-value until it changes sign.
bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma=1) const
Return a confidence interval for the expected number of events given n observed (unweighted) events.
static RooAbsFunc * createPoissonSum(Int_t n)
Create and return a PoissonSum function binding.
RooHistError()
Construct our singleton object.
double _poissonHiLUT[1000]
static RooAbsFunc * createBinomialSum(Int_t n, Int_t m, bool eff)
Create and return a BinomialSum function binding.
static constexpr double infinity()
Return internal infinity representation.
Definition RooNumber.h:25
const Int_t n
Definition legend1.C:16
TMarker m
Definition textangle.C:8