{ "cells": [ { "cell_type": "markdown", "id": "0164f42e", "metadata": {}, "source": [ "# Zbi_Zgamma\n", "Demonstrate Z_Bi = Z_Gamma\n", "\n", "\n", "\n", "\n", "**Author:** Kyle Cranmer, Wouter Verkerke \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:36 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "77b34be0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:40.796390Z", "iopub.status.busy": "2026-05-19T20:36:40.796263Z", "iopub.status.idle": "2026-05-19T20:36:40.812869Z", "shell.execute_reply": "2026-05-19T20:36:40.812409Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooProdPdf.h\"\n", "#include \"RooWorkspace.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TH1.h\"\n", "\n", "using namespace RooFit;\n", "using namespace RooStats;" ] }, { "cell_type": "markdown", "id": "8936525c", "metadata": {}, "source": [ "Make model for prototype on/off problem\n", "Pois(x | s+b) * Pois(y | tau b )\n", "for Z_Gamma, use uniform prior on b." ] }, { "cell_type": "code", "execution_count": 2, "id": "37c1beed", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:40.820436Z", "iopub.status.busy": "2026-05-19T20:36:40.820302Z", "iopub.status.idle": "2026-05-19T20:36:41.165687Z", "shell.execute_reply": "2026-05-19T20:36:41.164785Z" } }, "outputs": [], "source": [ "RooWorkspace *w1 = new RooWorkspace(\"w\");\n", "w1->factory(\"Poisson::px(x[150,0,500],sum::splusb(s[0,0,100],b[100,0,300]))\");\n", "w1->factory(\"Poisson::py(y[100,0,500],prod::taub(tau[1.],b))\");\n", "w1->factory(\"Uniform::prior_b(b)\");" ] }, { "cell_type": "markdown", "id": "2052d385", "metadata": {}, "source": [ "construct the Bayesian-averaged model (eg. a projection pdf)\n", "p'(x|s) = \\int db p(x|s+b) * [ p(y|b) * prior(b) ]" ] }, { "cell_type": "code", "execution_count": 3, "id": "033365bd", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:41.167085Z", "iopub.status.busy": "2026-05-19T20:36:41.166968Z", "iopub.status.idle": "2026-05-19T20:36:41.384991Z", "shell.execute_reply": "2026-05-19T20:36:41.378614Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b_X_px]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n" ] } ], "source": [ "w1->factory(\"PROJ::averagedModel(PROD::foo(px|b,py,prior_b),b)\");" ] }, { "cell_type": "markdown", "id": "b1f35e78", "metadata": {}, "source": [ "plot it, blue is averaged model, red is b known exactly" ] }, { "cell_type": "code", "execution_count": 4, "id": "d9417d6b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:41.389936Z", "iopub.status.busy": "2026-05-19T20:36:41.389802Z", "iopub.status.idle": "2026-05-19T20:36:41.600037Z", "shell.execute_reply": "2026-05-19T20:36:41.599542Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(SPECINT[GENPROJ_[py_X_prior_b]_Norm[b]_X_px_NORM[x]]_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "RooPlot *frame = w1->var(\"x\")->frame();\n", "w1->pdf(\"averagedModel\")->plotOn(frame);\n", "w1->pdf(\"px\")->plotOn(frame, LineColor(kRed));\n", "frame->Draw();" ] }, { "cell_type": "markdown", "id": "5a99c53f", "metadata": {}, "source": [ "compare analytic calculation of Z_Bi\n", "with the numerical RooFit implementation of Z_Gamma\n", "for an example with x = 150, y = 100" ] }, { "cell_type": "markdown", "id": "d4df82f4", "metadata": {}, "source": [ "numeric RooFit Z_Gamma" ] }, { "cell_type": "code", "execution_count": 5, "id": "b557ecf4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:41.601234Z", "iopub.status.busy": "2026-05-19T20:36:41.601110Z", "iopub.status.idle": "2026-05-19T20:36:41.816008Z", "shell.execute_reply": "2026-05-19T20:36:41.815523Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(SPECINT[GENPROJ_[py_X_prior_b]_Norm[b]_X_px_cdf_NORM[x_prime]]_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(SPECINT[GENPROJ_[py_X_prior_b]_Norm[b]_X_px_cdf_Int[x_prime|CDF]_Norm[x_prime]]_Int[b|CDF]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "[#1] INFO:NumericIntegration -- RooRealIntegral::init(GENPROJ_[py_X_prior_b]_Norm[b]_denominator_Int[b]) using numeric integrator RooIntegrator1D to calculate Int(b)\n", "Hybrid p-value = 0.999226\n", "Z_Gamma Significance = 3.1655\n" ] } ], "source": [ "w1->var(\"y\")->setVal(100);\n", "w1->var(\"x\")->setVal(150);\n", "std::unique_ptr cdf{w1->pdf(\"averagedModel\")->createCdf(*w1->var(\"x\"))};\n", "cdf->getVal(); // get ugly print messages out of the way\n", "\n", "cout << \"Hybrid p-value = \" << cdf->getVal() << endl;\n", "cout << \"Z_Gamma Significance = \" << PValueToSignificance(1 - cdf->getVal()) << endl;" ] }, { "cell_type": "markdown", "id": "4ec21431", "metadata": {}, "source": [ "analytic Z_Bi" ] }, { "cell_type": "code", "execution_count": 6, "id": "b761424c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:41.817180Z", "iopub.status.busy": "2026-05-19T20:36:41.817061Z", "iopub.status.idle": "2026-05-19T20:36:42.027282Z", "shell.execute_reply": "2026-05-19T20:36:42.026785Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Z_Bi significance estimation: 3.10804\n" ] } ], "source": [ "double Z_Bi = NumberCountingUtils::BinomialWithTauObsZ(150, 100, 1);\n", "std::cout << \"Z_Bi significance estimation: \" << Z_Bi << std::endl;" ] }, { "cell_type": "markdown", "id": "a5a1c2b4", "metadata": {}, "source": [ "OUTPUT\n", "Hybrid p-value = 0.999058\n", "Z_Gamma Significance = 3.10804\n", "Z_Bi significance estimation: 3.10804" ] }, { "cell_type": "markdown", "id": "4603a144", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 7, "id": "92d408d1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:42.028932Z", "iopub.status.busy": "2026-05-19T20:36:42.028800Z", "iopub.status.idle": "2026-05-19T20:36:42.262579Z", "shell.execute_reply": "2026-05-19T20:36:42.262054Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }