Logo ROOT   6.12/07
Reference Guide
Zbi_Zgamma.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roostats
3 /// \notebook -js
4 /// Demonstrate Z_Bi = Z_Gamma
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \author Kyle Cranmer & Wouter Verkerke
11 
12 #include "RooRealVar.h"
13 #include "RooProdPdf.h"
14 #include "RooWorkspace.h"
15 #include "RooDataSet.h"
16 #include "TCanvas.h"
17 #include "TH1.h"
18 
19 using namespace RooFit;
20 using namespace RooStats;
21 
22 void Zbi_Zgamma() {
23 
24  // Make model for prototype on/off problem
25  // Pois(x | s+b) * Pois(y | tau b )
26  // for Z_Gamma, use uniform prior on b.
27  RooWorkspace* w1 = new RooWorkspace("w",true);
28  w1->factory("Poisson::px(x[150,0,500],sum::splusb(s[0,0,100],b[100,0,300]))");
29  w1->factory("Poisson::py(y[100,0,500],prod::taub(tau[1.],b))");
30  w1->factory("Uniform::prior_b(b)");
31 
32  // construct the Bayesian-averaged model (eg. a projection pdf)
33  // p'(x|s) = \int db p(x|s+b) * [ p(y|b) * prior(b) ]
34  w1->factory("PROJ::averagedModel(PROD::foo(px|b,py,prior_b),b)") ;
35 
36  // plot it, blue is averaged model, red is b known exactly
37  RooPlot* frame = w1->var("x")->frame() ;
38  w1->pdf("averagedModel")->plotOn(frame) ;
39  w1->pdf("px")->plotOn(frame,LineColor(kRed)) ;
40  frame->Draw() ;
41 
42  // compare analytic calculation of Z_Bi
43  // with the numerical RooFit implementation of Z_Gamma
44  // for an example with x = 150, y = 100
45 
46  // numeric RooFit Z_Gamma
47  w1->var("y")->setVal(100);
48  w1->var("x")->setVal(150);
49  RooAbsReal* cdf = w1->pdf("averagedModel")->createCdf(*w1->var("x"));
50  cdf->getVal(); // get ugly print messages out of the way
51 
52  cout << "Hybrid p-value = " << cdf->getVal() << endl;
53  cout << "Z_Gamma Significance = " <<
54  PValueToSignificance(1-cdf->getVal()) << endl;
55 
56  // analytic Z_Bi
57  double Z_Bi = NumberCountingUtils::BinomialWithTauObsZ(150, 100, 1);
58  std::cout << "Z_Bi significance estimation: " << Z_Bi << std::endl;
59 
60  // OUTPUT
61  // Hybrid p-value = 0.999058
62  // Z_Gamma Significance = 3.10804
63  // Z_Bi significance estimation: 3.10804
64 }
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:59
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
Double_t PValueToSignificance(Double_t pvalue)
returns one-sided significance corresponding to a p-value
Definition: RooStatsUtils.h:44
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
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:3050
Double_t BinomialWithTauObsZ(Double_t nObs, Double_t bExp, Double_t tau)
virtual void setVal(Double_t value)
Set value of variable to &#39;value&#39;.
Definition: RooRealVar.cxx:205
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
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
Namespace for the RooStats classes.
Definition: Asimov.h:20
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found...
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