Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf211_paramconv.py File Reference

Namespaces

namespace  rf211_paramconv
 

Detailed Description

View in nbviewer Open in SWAN
'ADDITION AND CONVOLUTION' RooFit tutorial macro #211 Working a with a p.d.f.

with a convolution operator in terms of a parameter

(require ROOT to be compiled with –enable-fftw3)

import ROOT
# Set up component pdfs
# ---------------------------------------
# Gaussian g(x ; mean,sigma)
x = ROOT.RooRealVar("x", "x", -10, 10)
mean = ROOT.RooRealVar("mean", "mean", -3, 3)
sigma = ROOT.RooRealVar("sigma", "sigma", 0.5, 0.1, 10)
modelx = ROOT.RooGaussian("gx", "gx", x, mean, sigma)
# Block function in mean
a = ROOT.RooRealVar("a", "a", 2, 1, 10)
model_mean = ROOT.RooGenericPdf("model_mean", "abs(mean)<a", [mean, a])
# Convolution in mean model = g(x,mean,sigma) (x) block(mean)
x.setBins(1000, "cache")
mean.setBins(50, "cache")
model = ROOT.RooFFTConvPdf("model", "model", mean, modelx, model_mean)
# Configure convolution to construct a 2-D cache in (x,mean)
# rather than a 1-d cache in mean that needs to be recalculated
# for each value of x
model.setCacheObservables({x})
model.setBufferFraction(1.0)
# Integrate model over projModel = Int model dmean
projModel = model.createProjection({mean})
# Generate 1000 toy events
d = projModel.generateBinned({x}, 1000)
# Fit p.d.f. to toy data
projModel.fitTo(d, Verbose=True, PrintLevel=-1)
# Plot data and fitted p.d.f.
frame = x.frame(Bins=25)
d.plotOn(frame)
projModel.plotOn(frame)
# Make 2d histogram of model(x;mean)
hh = model.createHistogram(
"hh",
x,
Binning=50,
YVar=dict(var=mean, Binning=50),
ConditionalObservables={mean},
)
hh.SetTitle("histogram of model(x|mean)")
hh.SetLineColor(ROOT.kBlue)
# Draw frame on canvas
c = ROOT.TCanvas("rf211_paramconv", "rf211_paramconv", 800, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
frame.GetYaxis().SetTitleOffset(1.4)
frame.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.20)
hh.GetZaxis().SetTitleOffset(2.5)
hh.Draw("surf")
c.SaveAs("rf211_paramconv.png")
[#1] INFO:Eval -- RooRealVar::setRange(mean) new range named 'refrange_fft_model' created with bounds [-3,3]
[#0] WARNING:Eval -- The FFT convolution 'model' will run with 50 bins. A decent accuracy for difficult convolutions is typically only reached with n >= 1000. Suggest to increase the number of bins of the observable 'mean'.
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gx_Int[mean,x]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_mean_Int[mean]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(model) creating new cache 0x70fd2e0 with pdf gx_CONV_model_mean_CACHE_Obs[mean,x]_NORM_mean for nset (mean) with code 0
[#0] WARNING:Eval -- The FFT convolution 'model' will run with 50 bins. A decent accuracy for difficult convolutions is typically only reached with n >= 1000. Suggest to increase the number of bins of the observable 'mean'.
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gx_Int[mean,x]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_mean_Int[mean]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(model) creating new cache 0x7408540 with pdf gx_CONV_model_mean_CACHE_Obs[x,mean]_NORM_x_mean for nset (x,mean) with code 1
[#0] WARNING:Eval -- The FFT convolution 'model' will run with 50 bins. A decent accuracy for difficult convolutions is typically only reached with n >= 1000. Suggest to increase the number of bins of the observable 'mean'.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(model) creating new cache 0x81b8e10 with pdf gx_CONV_model_mean_CACHE_Obs[x,mean]_NORM_x_mean for nset (x,mean) with code 1 from preexisting content.
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for a: using 0.5
[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for sigma: using 0.2
prevFCN = 2171.275755 a=2.012, sigma=0.5, [#1] INFO:NumericIntegration -- RooRealIntegral::init(gx_Int[mean,x]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_mean_Int[mean]) using numeric integrator RooIntegrator1D to calculate Int(mean)
prevFCN = 2171.275755 a=1.988,
prevFCN = 2171.275755 a=2.121,
prevFCN = 2171.861215 a=1.886,
prevFCN = 2172.184717 a=2.012,
prevFCN = 2171.275755 a=1.988,
prevFCN = 2171.275755 a=2, sigma=0.5047,
prevFCN = 2171.286528 sigma=0.4953,
prevFCN = 2171.267762 sigma=0.5029,
prevFCN = 2171.281998 sigma=0.4971,
prevFCN = 2171.270547 a=2.012, sigma=0.5,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.012,
prevFCN = 2171.275755 a=2.121,
prevFCN = 2171.861215 a=1.886,
prevFCN = 2172.184717 a=2.012,
prevFCN = 2171.275755 a=1.988,
prevFCN = 2171.275755 a=2.121,
prevFCN = 2171.861215 a=1.886,
prevFCN = 2172.184717 a=2, sigma=0.5029,
prevFCN = 2171.281998 sigma=0.4971,
prevFCN = 2171.270547 a=2.013, sigma=0.4843,
prevFCN = 2171.259881 a=2.009, sigma=0.4884,
prevFCN = 2171.260992 a=2.025, sigma=0.4843,
prevFCN = 2171.259881 a=2.001,
prevFCN = 2171.259881 a=2.134,
prevFCN = 2171.692149 a=1.898,
prevFCN = 2172.378568 a=2.025,
prevFCN = 2171.259881 a=2.001,
prevFCN = 2171.259881 a=2.013, sigma=0.4871,
prevFCN = 2171.26042 sigma=0.4815,
prevFCN = 2171.260367 sigma=0.4843,
prevFCN = 2171.259881 a=2.025,
prevFCN = 2171.259881 a=2.001,
prevFCN = 2171.259881 a=2.134,
prevFCN = 2171.692149 a=1.898,
prevFCN = 2172.378568 a=2.013, sigma=0.4871,
prevFCN = 2171.26042 sigma=0.4815,
prevFCN = 2171.260367 a=2.015, sigma=0.4843,
prevFCN = 2171.259881 a=2.011,
prevFCN = 2171.259881 a=2.013, sigma=0.4848,
prevFCN = 2171.259907 sigma=0.4837,
prevFCN = 2171.259896 a=2.134, sigma=0.4871,
prevFCN = 2171.720718 a=2.065, sigma=0.4512,
prevFCN = 2171.332894 a=2.03, sigma=0.473,
prevFCN = 2171.26812 a=2.02, sigma=0.4794,
prevFCN = 2171.261381 a=2.016, sigma=0.482,
prevFCN = 2171.260198 a=2.014, sigma=0.4832,
prevFCN = 2171.25995 a=2.014, sigma=0.4837,
prevFCN = 2171.259895 a=2.013, sigma=0.484,
prevFCN = 2171.259883 a=2.013, sigma=0.4841,
prevFCN = 2171.259881 a=2.013, sigma=0.4842,
prevFCN = 2171.25988 a=2.025,
prevFCN = 2171.25988 a=2.001,
prevFCN = 2171.25988 a=2.134,
prevFCN = 2171.691427 a=1.898,
prevFCN = 2172.379556 a=2.025,
prevFCN = 2171.25988 a=2.001,
prevFCN = 2171.25988 a=2.013, sigma=0.487,
prevFCN = 2171.260398 sigma=0.4814,
prevFCN = 2171.260398 sigma=0.4842,
prevFCN = 2171.25988 a=2.025,
prevFCN = 2171.25988 a=2.001,
prevFCN = 2171.25988 a=2.134,
prevFCN = 2171.691427 a=1.898,
prevFCN = 2172.379556 a=2.013, sigma=0.487,
prevFCN = 2171.260398 sigma=0.4814,
prevFCN = 2171.260398 a=2.015, sigma=0.4842,
prevFCN = 2171.25988 a=2.011,
prevFCN = 2171.25988 a=2.013, sigma=0.4848,
prevFCN = 2171.259901 sigma=0.4836,
prevFCN = 2171.259901 sigma=0.4843,
prevFCN = 2171.259881 sigma=0.4841,
prevFCN = 2171.259881 a=2.134, sigma=0.487,
prevFCN = 2171.720107 a=2.013, sigma=0.4842, [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#0] WARNING:Eval -- The FFT convolution 'model' will run with 50 bins. A decent accuracy for difficult convolutions is typically only reached with n >= 1000. Suggest to increase the number of bins of the observable 'mean'.
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gx_Int[mean,x]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(model_mean_Int[mean]) using numeric integrator RooIntegrator1D to calculate Int(mean)
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(model) creating new cache 0x8424520 with pdf gx_CONV_model_mean_CACHE_Obs[x,mean]_NORM_x_mean for nset (x,mean) with code 1
[#0] WARNING:Eval -- The FFT convolution 'model' will run with 50 bins. A decent accuracy for difficult convolutions is typically only reached with n >= 1000. Suggest to increase the number of bins of the observable 'mean'.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(model) creating new cache 0x848d5f0 with pdf gx_CONV_model_mean_CACHE_Obs[x,mean]_NORM_x for nset (x) with code 1 from preexisting content.
Date
February 2018
Authors
Clemens Lange, Wouter Verkerke (C version)

Definition in file rf211_paramconv.py.