Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Zbi_Zgamma.py
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## \date July 2022
11## \authors Artem Busorgin, Kyle Cranmer and Wouter Verkerke (C++ version)
12
13import ROOT
14
15# Make model for prototype on/off problem
16# Pois(x | s+b) * Pois(y | tau b )
17# for Z_Gamma, use uniform prior on b.
18w1 = ROOT.RooWorkspace("w")
19w1.factory("Poisson::px(x[150,0,500],sum::splusb(s[0,0,100],b[100,0,300]))")
20w1.factory("Poisson::py(y[100,0,500],prod::taub(tau[1.],b))")
21w1.factory("Uniform::prior_b(b)")
22
23# construct the Bayesian-averaged model (eg. a projection pdf)
24# p'(x|s) = \int db p(x|s+b) * [ p(y|b) * prior(b) ]
25w1.factory("PROJ::averagedModel(PROD::foo(px|b,py,prior_b),b)")
26
27c = ROOT.TCanvas()
28
29# plot it, blue is averaged model, red is b known exactly
30frame = w1["x"].frame()
31w1["averagedModel"].plotOn(frame)
32w1["px"].plotOn(frame, LineColor=ROOT.kRed)
33frame.Draw()
34
35# compare analytic calculation of Z_Bi
36# with the numerical RooFit implementation of Z_Gamma
37# for an example with x = 150, y = 100
38
39# numeric RooFit Z_Gamma
40w1["y"].setVal(100)
41w1["x"].setVal(150)
42cdf = w1["averagedModel"].createCdf(w1["x"])
43cdf.getVal() # get ugly print messages out of the way
44
45print("Hybrid p-value = ", cdf.getVal())
46print("Z_Gamma Significance = ", ROOT.RooStats.PValueToSignificance(1 - cdf.getVal()))
47
48# analytic Z_Bi
49Z_Bi = ROOT.RooStats.NumberCountingUtils.BinomialWithTauObsZ(150, 100, 1)
50print("Z_Bi significance estimation: ", Z_Bi)
51
52c.SaveAs("Zbi_Zgamma.png")