Rf 1 0 6_Plotdecoration¶

Basic functionality: adding boxes with parameters to RooPlots and decorating with arrows, etc...

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 Saturday, November 28, 2020 at 10:37 AM.

In [1]:
import ROOT

Welcome to JupyROOT 6.23/01


Set up model¶

Create observables

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

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University



Create Gaussian

In [3]:
sigma = ROOT.RooRealVar("sigma", "sigma", 1, 0.1, 10)
mean = ROOT.RooRealVar("mean", "mean", -3, -10, 10)
gauss = ROOT.RooGaussian("gauss", "gauss", x, mean, sigma)


Generate a sample of 1000 events with sigma=3

In [4]:
data = gauss.generate(ROOT.RooArgSet(x), 1000)


Fit pdf to data

In [5]:
gauss.fitTo(data)

Out[5]:
<cppyy.gbl.RooFitResult object at 0x(nil)>
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
**********
**    1 **SET PRINT           1
**********
**********
**********
PARAMETER DEFINITIONS:
NO.   NAME         VALUE      STEP SIZE      LIMITS
1 mean        -3.00000e+00  2.00000e+00   -1.00000e+01  1.00000e+01
2 sigma        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
**********
**********
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=1457.87 FROM MIGRAD    STATUS=INITIATE        8 CALLS           9 TOTAL
EDM= unknown      STRATEGY= 1      NO ERROR MATRIX
EXT PARAMETER               CURRENT GUESS       STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  mean        -3.00000e+00   2.00000e+00   2.11716e-01  -2.55667e+02
2  sigma        1.00000e+00   4.50000e-01   1.63378e-01  -2.21584e+02
ERR DEF= 0.5
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1456.09 FROM MIGRAD    STATUS=CONVERGED      31 CALLS          32 TOTAL
EDM=1.47238e-07    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  mean        -2.97319e+00   3.28196e-02   9.04112e-05   1.05544e-01
2  sigma        1.03785e+00   2.32067e-02   2.10225e-04  -1.56386e-02
ERR DEF= 0.5
EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  2    ERR DEF=0.5
1.077e-03  4.600e-07
4.600e-07  5.386e-04
PARAMETER  CORRELATION COEFFICIENTS
NO.  GLOBAL      1      2
1  0.00060   1.000  0.001
2  0.00060   0.001  1.000
**********
**    7 **SET ERR         0.5
**********
**********
**    8 **SET PRINT           1
**********
**********
**    9 **HESSE        1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1456.09 FROM HESSE     STATUS=OK             10 CALLS          42 TOTAL
EDM=1.47267e-07    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                INTERNAL      INTERNAL
NO.   NAME      VALUE            ERROR       STEP SIZE       VALUE
1  mean        -2.97319e+00   3.28196e-02   1.80822e-05  -3.01883e-01
2  sigma        1.03785e+00   2.32067e-02   8.40899e-06  -9.45066e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  2    ERR DEF=0.5
1.077e-03  1.019e-07
1.019e-07  5.386e-04
PARAMETER  CORRELATION COEFFICIENTS
NO.  GLOBAL      1      2
1  0.00013   1.000  0.000
2  0.00013   0.000  1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization


Plot pdf and data¶

Overlay projection of gauss on data

In [6]:
frame = x.frame(ROOT.RooFit.Name("xframe"), ROOT.RooFit.Title(
"RooPlot with decorations"), ROOT.RooFit.Bins(40))
data.plotOn(frame)
gauss.plotOn(frame)

Out[6]:
<cppyy.gbl.RooPlot object at 0x7822960>

Left edge of box starts at 55% of Xaxis)

In [7]:
gauss.paramOn(frame, ROOT.RooFit.Layout(0.55))

Out[7]:
<cppyy.gbl.RooPlot object at 0x7822960>

X size of box is from 55% to 99% of Xaxis range, of box is at 80% of Yaxis range)

In [8]:
data.statOn(frame, ROOT.RooFit.Layout(0.55, 0.99, 0.8))

Out[8]:
<cppyy.gbl.RooPlot object at 0x7822960>

In [9]:
txt = ROOT.TText(2, 100, "Signal")
txt.SetTextSize(0.04)
txt.SetTextColor(ROOT.kRed)


In [10]:
arrow = ROOT.TArrow(2, 100, -1, 50, 0.01, "|>")
arrow.SetLineColor(ROOT.kRed)
arrow.SetFillColor(ROOT.kRed)
arrow.SetLineWidth(3)


Persist frame with all decorations in ROOT file¶

In [11]:
f = ROOT.TFile("rf106_plotdecoration.root", "RECREATE")
frame.Write()
f.Close()


To read back and plot frame with all decorations in clean root session do root> ROOT.TFile f("rf106_plotdecoration.root") root> xframe.Draw()

In [12]:
c = ROOT.TCanvas("rf106_plotdecoration", "rf106_plotdecoration", 600, 600)
frame.GetYaxis().SetTitleOffset(1.6)
frame.Draw()

c.SaveAs("rf106_plotdecoration.png")

Info in <TCanvas::Print>: png file rf106_plotdecoration.png has been created


Draw all canvases

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