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

Detailed Description

View in nbviewer Open in SWAN
'SPECIAL PDFS' RooFit tutorial macro #705

Linear interpolation between p.d.f shapes using the 'Alex Read' algorithm

import ROOT
# Create end point pdf shapes
# ------------------------------------------------------
# Observable
x = ROOT.RooRealVar("x", "x", -20, 20)
# Lower end point shape: a Gaussian
g1mean = ROOT.RooRealVar("g1mean", "g1mean", -10)
g1 = ROOT.RooGaussian("g1", "g1", x, g1mean, 2.0)
# Upper end point shape: a Polynomial
g2 = ROOT.RooPolynomial("g2", "g2", x, [-0.03, -0.001])
# Create interpolating pdf
# -----------------------------------------------
# Create interpolation variable
alpha = ROOT.RooRealVar("alpha", "alpha", 0, 1.0)
# Specify sampling density on observable and interpolation variable
x.setBins(1000, "cache")
alpha.setBins(50, "cache")
# Construct interpolating pdf in (x,a) represent g1(x) at a=a_min
# and g2(x) at a=a_max
lmorph = ROOT.RooIntegralMorph("lmorph", "lmorph", g1, g2, x, alpha)
# Plot interpolating pdf aat various alphas a l p h a
# -----------------------------------------------------------------------------
# Show end points as blue curves
frame1 = x.frame()
g1.plotOn(frame1)
g2.plotOn(frame1)
# Show interpolated shapes in red
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
lmorph.plotOn(frame1, LineColor="r")
# Show 2D distribution of pdf(x,alpha)
# -----------------------------------------------------------------------
# Create 2D histogram
hh = lmorph.createHistogram("hh", x, Binning=40, YVar=dict(var=alpha, Binning=40))
# Fit pdf to dataset with alpha=0.8
# -----------------------------------------------------------------
# Generate a toy dataset alpha = 0.8
data = lmorph.generate(x, 1000)
# Fit pdf to toy data
lmorph.fitTo(data, Verbose=True, PrintLevel=-1)
# Plot fitted pdf and data overlaid
frame2 = x.frame(Bins=100)
data.plotOn(frame2)
# Scan -log(L) vs alpha
# -----------------------------------------
# Show scan -log(L) of dataset w.r.t alpha
frame3 = alpha.frame(Bins=100, Range=(0.1, 0.9))
# Make 2D pdf of histogram
nll = lmorph.createNLL(data)
nll.plotOn(frame3, ShiftToZero=True)
c = ROOT.TCanvas("rf705_linearmorph", "rf705_linearmorph", 800, 800)
c.Divide(2, 2)
c.cd(1)
frame1.GetYaxis().SetTitleOffset(1.6)
c.cd(2)
hh.GetZaxis().SetTitleOffset(2.5)
hh.Draw("surf")
c.cd(3)
frame3.GetYaxis().SetTitleOffset(1.4)
c.cd(4)
frame2.GetYaxis().SetTitleOffset(1.4)
c.SaveAs("rf705_linearmorph.png")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f628f000 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f64dd850 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x_alpha for nset (x,alpha) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f68ba8e0 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f673b1a0 with pdf g1_MORPH_g2_CACHE_Obs[x]_NORM_x for nset (x) with code 0
[#0] PROGRESS:Eval -- RooIntegralMorph::fillCacheObject(lmorph) filling multi-dimensional cache..................................................
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f62a1c70 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x]_NORM_x for nset (x) with code 0
[#1] INFO:Fitting -- RooAbsPdf::fitTo(lmorph_over_lmorph_Int[x]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using generic CPU library compiled with no vectorizations
[#1] INFO:Fitting -- Creation of NLL object took 252.511 ms
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_lmorph_over_lmorph_Int[x]_lmorphData) Summation contains a RooNLLVar, using its error level
[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for alpha: using 0.1
[#1] INFO:Minimization -- [fitFCN] No discrete parameters, performing continuous minimization only
prevFCN = 9770.877306 alpha=0.807,
prevFCN = 9770.136802 alpha=0.7929,
prevFCN = 9771.987074 alpha=0.8008,
prevFCN = 9770.763751 alpha=0.7992,
prevFCN = 9770.751345 alpha=0.8001,
prevFCN = 9770.860999 alpha=0.7999,
prevFCN = 9770.646422
prevFCN = 9770.646422 alpha=0.7994,
prevFCN = 9770.713784 alpha=0.7997,
prevFCN = 9770.676938 alpha=0.8004,
prevFCN = 9770.81299 alpha=0.8002,
prevFCN = 9770.852903 alpha=0.8,
prevFCN = 9770.873215 alpha=0.8,
prevFCN = 9770.636117 alpha=0.8,
prevFCN = 9770.874033 alpha=0.8,
prevFCN = 9770.631397 alpha=0.8,
prevFCN = 9770.874851 alpha=0.8,
prevFCN = 9770.876795 alpha=0.8,
prevFCN = 9770.876491 alpha=0.8,
prevFCN = 9770.633649 alpha=0.8,
prevFCN = 9770.631088 alpha=0.8,
prevFCN = 9770.631706 alpha=0.8,
prevFCN = 9770.875654 alpha=0.8,
prevFCN = 9770.634489 alpha=0.8,
prevFCN = 9770.632904 alpha=0.8,
prevFCN = 9770.632131 alpha=0.8,
prevFCN = 9770.631755 alpha=0.8,
prevFCN = 9770.631571 alpha=0.8,
prevFCN = 9770.631482 alpha=0.8,
prevFCN = 9770.631438 alpha=0.8,
prevFCN = 9770.631417 alpha=0.8,
prevFCN = 9770.631407 alpha=0.8,
prevFCN = 9770.631402 alpha=0.8,
prevFCN = 9770.631399 alpha=0.8,
prevFCN = 9770.631397 alpha=0.8,
prevFCN = 9770.875654 alpha=0.8,
prevFCN = 9770.634489 alpha=0.8,
prevFCN = 9770.631097 alpha=0.8,
prevFCN = 9770.631697 alpha=0.8,
prevFCN = 9770.631337 alpha=0.8,
prevFCN = 9770.631457 alpha=0.8,
prevFCN = 9770.631397 alpha=0.8,
prevFCN = 9770.631337 alpha=0.8,
prevFCN = 9770.631457 alpha=0.8,
prevFCN = 9770.630797 alpha=0.8,
prevFCN = 9770.631997 alpha=0.8,
prevFCN = 9770.631277 alpha=0.8,
prevFCN = 9770.631517 alpha=0.8, [#0] PROGRESS:Eval -- RooIntegralMorph::fillCacheObject(lmorph) filling multi-dimensional cache..................................................
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f695e130 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x]_NORM_x for nset (x) with code 0
[#0] PROGRESS:Eval -- RooIntegralMorph::fillCacheObject(lmorph) filling multi-dimensional cache..................................................
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x55f8f695e130 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x]_NORM_x for nset (x) with code 0
[#1] INFO:Fitting -- RooAbsPdf::fitTo(lmorph_over_lmorph_Int[x]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- Creation of NLL object took 248.362 ms
Date
February 2018
Authors
Clemens Lange, Wouter Verkerke (C version)

Definition in file rf705_linearmorph.py.