Multidimensional models: using the likelihood ratio techique to construct a signal enhanced one-dimensional projection of a multi-dimensional pdf

Author: Clemens Lange, Wouter Verkerke (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, November 30, 2022 at 11:23 AM.

In [1]:
import ROOT
Welcome to JupyROOT 6.27/01

Create 3D pdf and data

Create observables

In [2]:
x = ROOT.RooRealVar("x", "x", -5, 5)
y = ROOT.RooRealVar("y", "y", -5, 5)
z = ROOT.RooRealVar("z", "z", -5, 5)

Create signal pdf gauss(x)gauss(y)gauss(z)

In [3]:
gx = ROOT.RooGaussian("gx", "gx", x, ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(1))
gy = ROOT.RooGaussian("gy", "gy", y, ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(1))
gz = ROOT.RooGaussian("gz", "gz", z, ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(1))
sig = ROOT.RooProdPdf("sig", "sig", [gx, gy, gz])

Create background pdf poly(x)poly(y)poly(z)

In [4]:
px = ROOT.RooPolynomial("px", "px", x, [-0.1, 0.004])
py = ROOT.RooPolynomial("py", "py", y, [0.1, -0.004])
pz = ROOT.RooPolynomial("pz", "pz", z)
bkg = ROOT.RooProdPdf("bkg", "bkg", [px, py, pz])

Create composite pdf sig+bkg

In [5]:
fsig = ROOT.RooRealVar("fsig", "signal fraction", 0.1, 0.0, 1.0)
model = ROOT.RooAddPdf("model", "model", [sig, bkg], [fsig])

data = model.generate({x, y, z}, 20000)

Project pdf and data on x

Make plain projection of data and pdf on x observable

In [6]:
frame = x.frame(Title="Projection of 3D data and pdf on X", Bins=40)
<cppyy.gbl.RooPlot object at 0x93f9b90>
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on x integrates over variables (y,z)

Define projected signal likelihood ratio

Calculate projection of signal and total likelihood on (y,z) observables i.e. integrate signal and composite model over x

In [7]:
sigyz = sig.createProjection({x})
totyz = model.createProjection({x})

Construct the log of the signal / signal+background probability

In [8]:
llratio_func = ROOT.RooFormulaVar("llratio", "log10(@0)-log10(@1)", [sigyz, totyz])

Plot data with a LL ratio cut

Calculate the llratio value for each event in the dataset

In [9]:
<cppyy.gbl.RooRealVar object at 0x966ece0>

Extract the subset of data with large signal likelihood

In [10]:
dataSel = data.reduce(Cut="llratio>0.7")
[#1] INFO:InputArguments -- The formula llratio>0.7 claims to use the variables (y,z,x,llratio) but only (llratio) seem to be in use.
  inputs:         llratio>0.7

Make plot frame

In [11]:
frame2 = x.frame(Title="Same projection on X with LLratio(y,z)>0.7", Bins=40)

Plot select data on frame

In [12]:
<cppyy.gbl.RooPlot object at 0x979a0e0>

Make MC projection of pdf with same LL ratio cut

Generate large number of events for MC integration of pdf projection

In [13]:
mcprojData = model.generate({x, y, z}, 10000)

Calculate LL ratio for each generated event and select MC events with llratio)0.7

In [14]:
mcprojDataSel = mcprojData.reduce(Cut="llratio>0.7")
[#1] INFO:InputArguments -- The formula llratio>0.7 claims to use the variables (y,z,x,llratio) but only (llratio) seem to be in use.
  inputs:         llratio>0.7

Project model on x, projected observables (y,z) with Monte Carlo technique on set of events with the same llratio cut as was applied to data

In [15]:
model.plotOn(frame2, ProjWData=mcprojDataSel)

c = ROOT.TCanvas("rf316_llratioplot", "rf316_llratioplot", 800, 400)
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on x averages using data variables (y,z)
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) only the following components of the projection data will be used: (y,z)
[#1] INFO:Plotting -- RooDataWeightedAverage::ctor(modelDataWgtAvg) constructing data weighted average of function model_Norm[x] over 767 data points of (y,z) with a total weight of 767
[#1] INFO:Minimization --  The following expressions have been identified as constant and will be precalculated and cached: (gy,gz,py,pz)
Info in <TCanvas::Print>: png file rf316_llratioplot.png has been created

Draw all canvases

In [16]:
from ROOT import gROOT