rf208_convolution

'ADDITION AND CONVOLUTION' RooFit tutorial macro #208 One-dimensional numeric convolution (require ROOT to be compiled with --enable-fftw3)

pdf = landau(t) (x) gauss(t)

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 Sunday, November 27, 2022 at 11:06 AM.

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

Set up component pdfs

Construct observable

In [2]:
t = ROOT.RooRealVar("t", "t", -10, 30)

Construct landau(t,ml,sl)

In [3]:
ml = ROOT.RooRealVar("ml", "mean landau", 5.0, -20, 20)
sl = ROOT.RooRealVar("sl", "sigma landau", 1, 0.1, 10)
landau = ROOT.RooLandau("lx", "lx", t, ml, sl)

Construct gauss(t,mg,sg)

In [4]:
mg = ROOT.RooRealVar("mg", "mg", 0)
sg = ROOT.RooRealVar("sg", "sg", 2, 0.1, 10)
gauss = ROOT.RooGaussian("gauss", "gauss", t, mg, sg)

Construct convolution pdf

Set #bins to be used for FFT sampling to 10000

In [5]:
t.setBins(10000, "cache")

Construct landau (x) gauss

In [6]:
lxg = ROOT.RooFFTConvPdf("lxg", "landau (X) gauss", t, landau, gauss)

Sample, fit and plot convoluted pdf

Sample 1000 events in x from gxlx

In [7]:
data = lxg.generate({t}, 10000)

Fit gxlx to data

In [8]:
lxg.fitTo(data)
Out[8]:
<cppyy.gbl.RooFitResult object at 0x(nil)>
[#1] INFO:Eval -- RooRealVar::setRange(t) new range named 'refrange_fft_lxg' created with bounds [-10,30]
[#1] INFO:NumericIntegration -- RooRealIntegral::init(lx_Int[t]) using numeric integrator RooIntegrator1D to calculate Int(t)
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lxg) creating new cache 0x80dd180 with pdf lx_CONV_gauss_CACHE_Obs[t]_NORM_t for nset (t) with code 0
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
 **********
 **    1 **SET PRINT           1
 **********
 **********
 **    2 **SET NOGRAD
 **********
 PARAMETER DEFINITIONS:
    NO.   NAME         VALUE      STEP SIZE      LIMITS
     1 ml           5.00000e+00  4.00000e+00   -2.00000e+01  2.00000e+01
     2 sg           2.00000e+00  9.50000e-01    1.00000e-01  1.00000e+01
     3 sl           1.00000e+00  4.50000e-01    1.00000e-01  1.00000e+01
 **********
 **    3 **SET ERR         0.5
 **********
 **********
 **    4 **SET PRINT           1
 **********
 **********
 **    5 **SET STR           1
 **********
 NOW USING STRATEGY  1: TRY TO BALANCE SPEED AGAINST RELIABILITY
 **********
 **    6 **MIGRAD        1500           1
 **********
 FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
 START MIGRAD MINIMIZATION.  STRATEGY  1.  CONVERGENCE WHEN EDM .LT. 1.00e-03
 FCN=28285.6 FROM MIGRAD    STATUS=INITIATE       12 CALLS          13 TOTAL
                     EDM= unknown      STRATEGY= 1      NO ERROR MATRIX       
  EXT PARAMETER               CURRENT GUESS       STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  ml           5.00000e+00   4.00000e+00   2.08372e-01   1.28490e+03
   2  sg           2.00000e+00   9.50000e-01   2.51381e-01   1.33500e+02
   3  sl           1.00000e+00   4.50000e-01   1.63378e-01   8.59464e+01
                               ERR DEF= 0.5
 MIGRAD MINIMIZATION HAS CONVERGED.
 MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=28280.5 FROM MIGRAD    STATUS=CONVERGED      63 CALLS          64 TOTAL
                     EDM=7.08918e-07    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  ml           4.88711e+00   3.70488e-02   1.95153e-04  -4.21500e-01
   2  sg           1.89676e+00   4.61915e-02   9.28724e-04   4.64118e-02
   3  sl           1.03032e+00   2.92154e-02   8.41380e-04   5.88413e-02
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.373e-03  8.103e-04 -3.221e-04 
  8.103e-04  2.134e-03 -9.406e-04 
 -3.221e-04 -9.406e-04  8.536e-04 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.47561   1.000  0.473 -0.298
        2  0.75061   0.473  1.000 -0.697
        3  0.69792  -0.298 -0.697  1.000
 **********
 **    7 **SET ERR         0.5
 **********
 **********
 **    8 **SET PRINT           1
 **********
 **********
 **    9 **HESSE        1500
 **********
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=28280.5 FROM HESSE     STATUS=OK             16 CALLS          80 TOTAL
                     EDM=7.12199e-07    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                INTERNAL      INTERNAL  
  NO.   NAME      VALUE            ERROR       STEP SIZE       VALUE   
   1  ml           4.88711e+00   3.71053e-02   3.90306e-05   2.46855e-01
   2  sg           1.89676e+00   4.64029e-02   3.71490e-05  -6.90624e-01
   3  sl           1.03032e+00   2.93441e-02   3.36552e-05  -9.47669e-01
                               ERR DEF= 0.5
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=0.5
  1.377e-03  8.197e-04 -3.287e-04 
  8.197e-04  2.153e-03 -9.535e-04 
 -3.287e-04 -9.535e-04  8.611e-04 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.47808   1.000  0.476 -0.302
        2  0.75324   0.476  1.000 -0.700
        3  0.70113  -0.302 -0.700  1.000
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization

Plot data, pdf, landau (X) gauss pdf

In [9]:
frame = t.frame(Title="landau (x) gauss convolution")
data.plotOn(frame)
lxg.plotOn(frame)
landau.plotOn(frame, LineStyle="--")
Out[9]:
<cppyy.gbl.RooPlot object at 0x82c9c70>
[#1] INFO:NumericIntegration -- RooRealIntegral::init(lx_Int[t]) using numeric integrator RooIntegrator1D to calculate Int(t)
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lxg) creating new cache 0x86c0900 with pdf lx_CONV_gauss_CACHE_Obs[t]_NORM_t for nset (t) with code 0
[#1] INFO:NumericIntegration -- RooRealIntegral::init(lx_Int[t]) using numeric integrator RooIntegrator1D to calculate Int(t)

Draw frame on canvas

In [10]:
c = ROOT.TCanvas("rf208_convolution", "rf208_convolution", 600, 600)
ROOT.gPad.SetLeftMargin(0.15)
frame.GetYaxis().SetTitleOffset(1.4)
frame.Draw()

c.SaveAs("rf208_convolution.png")
Info in <TCanvas::Print>: png file rf208_convolution.png has been created

Draw all canvases

In [11]:
from ROOT import gROOT 
gROOT.GetListOfCanvases().Draw()