<jupyter_start><jupyter_text>Convert a RooAbsPdf to a python callableThis is a simple demonstration that the wrapper function `convert_rf_pdf` does what we expect  Make a dummy RooFit model<jupyter_code>import ROOT as r
from ROOT import RooFit as rf

# observable
mass = r.RooRealVar("m", "m", 5000, 5800)

# gaussian
mean = r.RooRealVar("mu", "mu", 5350, 5300, 5400)
sigma = r.RooRealVar("sg", "sg", 25, 0, 100)
spdf = r.RooGaussian("sig", "sig", mass, mean, sigma)

# exponential
slope = r.RooRealVar("lb", "lb", -0.002, -0.01, 0)
bpdf = r.RooExponential("bkg", "bkg", mass, slope)

# total
sy = r.RooRealVar("sy", "sy", 1000, 0, 10000)
by = r.RooRealVar("by", "by", 2000, 0, 10000)
pdf = r.RooAddPdf("pdf", "pdf", r.RooArgList(spdf, bpdf), r.RooArgList(sy, by))<jupyter_output>Welcome to JupyROOT 6.22/02

[1mRooFit v3.60 -- Developed by <NAME> and <NAME>[0m 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt<jupyter_text>Plot the dummy RooFit model<jupyter_code>c = r.TCanvas('c','c',450,300)
pl = mass.frame(rf.Bins(800))
pdf.plotOn(
    pl,
    rf.Normalization(1, r.RooAbsReal.NumEvent),
    rf.Precision(-1),
    rf.Components("bkg"),
    rf.LineColor(r.kRed),
    rf.LineStyle(2),
    rf.LineWidth(2)
)
pdf.plotOn(
    pl,
    rf.Normalization(1, r.RooAbsReal.NumEvent),
    rf.Precision(-1),
    rf.Components("sig"),
    rf.LineColor(r.kGreen + 3),
    rf.LineWidth(2)
)
pdf.plotOn(pl, rf.Normalization(1, r.RooAbsReal.NumEvent), rf.Precision(-1), rf.LineWidth(2))
pl.Draw()
c.Draw();<jupyter_output>[#1] INFO:Plotting -- RooAbsPdf::plotOn(pdf) directly selected PDF components: (bkg)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(pdf) indirectly selected PDF components: ()
[#1] INFO:Plotting -- RooAbsPdf::plotOn(pdf) directly selected PDF components: (sig)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(pdf) indirectly selected PDF components: ()<jupyter_text>Convert the RooFit pdfs to python callablesMaking use of the `sweights` package wrapper `convert_rf_pdf`<jupyter_code>from sweights import convert_rf_pdf

_spdf = convert_rf_pdf(spdf, mass)
_bpdf = convert_rf_pdf(bpdf, mass)
_pdf = convert_rf_pdf(pdf, mass)<jupyter_output><empty_output><jupyter_text>Now draw the python function with matplotlib<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

fs = sy.getVal() / (sy.getVal() + by.getVal())
fb = by.getVal() / (sy.getVal() + by.getVal())

x = np.linspace(mass.getMin(), mass.getMax(), 400)
plt.plot(x, fs * _spdf(x), "g-");
plt.plot(x, fb * _bpdf(x), "r--");
plt.plot(x, _pdf(x), "b-");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1613263785394933, 'fraction_numerical': 0.036885245901639344, 'mean_word_length': 4.87527352297593, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '476641', 'license': 'MIT', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1055, 'n_words': 239, 'path': 'doc/check_rf_conversion.ipynb', 'repo_name': 'matthewkenzie/sweights', 'size': '2699'}