ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Zbi_Zgamma.C
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // Demonstraite Z_Bi = Z_Gamma
4 // author: Kyle Cranmer & Wouter Verkerke
5 // date May 2010
6 //
7 //
8 /////////////////////////////////////////////////////////////////////////
9 
10 #ifndef __CINT__
11 #include "RooGlobalFunc.h"
12 #endif
13 #include "RooRealVar.h"
14 #include "RooProdPdf.h"
15 #include "RooWorkspace.h"
16 #include "RooDataSet.h"
17 #include "TCanvas.h"
18 #include "TH1.h"
19 
20 using namespace RooFit;
21 using namespace RooStats;
22 
23 void Zbi_Zgamma() {
24 
25  // Make model for prototype on/off problem
26  // Pois(x | s+b) * Pois(y | tau b )
27  // for Z_Gamma, use uniform prior on b.
28  RooWorkspace* w = new RooWorkspace("w",true);
29  w->factory("Poisson::px(x[150,0,500],sum::splusb(s[0,0,100],b[100,0,300]))");
30  w->factory("Poisson::py(y[100,0,500],prod::taub(tau[1.],b))");
31  w->factory("Uniform::prior_b(b)");
32 
33  // construct the Bayesian-averaged model (eg. a projection pdf)
34  // p'(x|s) = \int db p(x|s+b) * [ p(y|b) * prior(b) ]
35  w->factory("PROJ::averagedModel(PROD::foo(px|b,py,prior_b),b)") ;
36 
37  // plot it, blue is averaged model, red is b known exactly
38  RooPlot* frame = w->var("x")->frame() ;
39  w->pdf("averagedModel")->plotOn(frame) ;
40  w->pdf("px")->plotOn(frame,LineColor(kRed)) ;
41  frame->Draw() ;
42 
43  // compare analytic calculation of Z_Bi
44  // with the numerical RooFit implementation of Z_Gamma
45  // for an example with x = 150, y = 100
46 
47  // numeric RooFit Z_Gamma
48  w->var("y")->setVal(100);
49  w->var("x")->setVal(150);
50  RooAbsReal* cdf = w->pdf("averagedModel")->createCdf(*w->var("x"));
51  cdf->getVal(); // get ugly print messages out of the way
52 
53  cout << "Hybrid p-value = " << cdf->getVal() << endl;
54  cout << "Z_Gamma Significance = " <<
55  PValueToSignificance(1-cdf->getVal()) << endl;
56 
57  // analytic Z_Bi
58  double Z_Bi = NumberCountingUtils::BinomialWithTauObsZ(150, 100, 1);
59  std::cout << "Z_Bi significance estimation: " << Z_Bi << std::endl;
60 
61  // OUTPUT
62  // Hybrid p-value = 0.999058
63  // Z_Gamma Significance = 3.10804
64  // Z_Bi significance estimation: 3.10804
65 
66 
67 }
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:61
Double_t PValueToSignificance(Double_t pvalue)
Definition: RooStatsUtils.h:59
RooAbsReal * createCdf(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Create a cumulative distribution function of this p.d.f in terms of the observables listed in iset...
Definition: RooAbsPdf.cxx:3027
void Zbi_Zgamma()
Definition: Zbi_Zgamma.C:23
double cdf(double *x, double *p)
Definition: unuranDistr.cxx:44
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
Double_t BinomialWithTauObsZ(Double_t nObs, Double_t bExp, Double_t tau)
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:203
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none(), const RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Plot (project) PDF on specified frame.
Definition: RooAbsPdf.h:105
tuple w
Definition: qtexample.py:51
RooPlot * frame(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found...
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooFactoryWSTool & factory()
Return instance to factory tool.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559