ROOT
Version v6.34
master
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
rf106_plotdecoration.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit
3
## \notebook
4
## Basic functionality: adding boxes with parameters to RooPlots and decorating with arrows, etc...
5
##
6
## \macro_image
7
## \macro_code
8
## \macro_output
9
##
10
## \authors Clemens Lange, Wouter Verkerke (C++ version)
11
12
import
ROOT
13
14
# Set up model
15
# ---------------------
16
17
# Create observables
18
x =
ROOT.RooRealVar
(
"x"
,
"x"
, -10, 10)
19
20
# Create Gaussian
21
sigma =
ROOT.RooRealVar
(
"sigma"
,
"sigma"
, 1, 0.1, 10)
22
mean =
ROOT.RooRealVar
(
"mean"
,
"mean"
, -3, -10, 10)
23
gauss =
ROOT.RooGaussian
(
"gauss"
,
"gauss"
, x, mean, sigma)
24
25
# Generate a sample of 1000 events with sigma=3
26
data =
gauss.generate
({x}, 1000)
27
28
# Fit pdf to data
29
gauss.fitTo
(data, PrintLevel=-1)
30
31
# Plot pdf and data
32
# -------------------------------------
33
34
# Overlay projection of gauss on data
35
frame =
x.frame
(Name=
"xframe"
, Title=
"RooPlot with decorations"
, Bins=40)
36
data.plotOn
(frame)
37
gauss.plotOn
(frame)
38
39
# Add box with pdf parameters
40
# -----------------------------------------------------
41
42
# Left edge of box starts at 55% of Xaxis)
43
gauss.paramOn
(frame, Layout=0.55)
44
45
# Add box with data statistics
46
# -------------------------------------------------------
47
48
# X size of box is from 55% to 99% of Xaxis range, of box is at 80% of
49
# Yaxis range)
50
data.statOn
(frame, Layout=(0.55, 0.99, 0.8))
51
52
# Add text and arrow
53
# -----------------------------------
54
55
# Add text to frame
56
txt =
ROOT.TText
(2, 100,
"Signal"
)
57
txt.SetTextSize
(0.04)
58
txt.SetTextColor
(
ROOT.kRed
)
59
frame.addObject
(txt)
60
61
# Add arrow to frame
62
arrow =
ROOT.TArrow
(2, 100, -1, 50, 0.01,
"|>"
)
63
arrow.SetLineColor
(
ROOT.kRed
)
64
arrow.SetFillColor
(
ROOT.kRed
)
65
arrow.SetLineWidth
(3)
66
frame.addObject
(arrow)
67
68
# Persist frame with all decorations in ROOT file
69
# ---------------------------------------------------------------------------------------------
70
71
f =
ROOT.TFile
(
"rf106_plotdecoration.root"
,
"RECREATE"
)
72
frame.Write
()
73
f.Close
()
74
75
# To read back and plot frame with all decorations in clean root session do
76
# root> ROOT.TFile f("rf106_plotdecoration.root")
77
# root> xframe.Draw()
78
79
c =
ROOT.TCanvas
(
"rf106_plotdecoration"
,
"rf106_plotdecoration"
, 600, 600)
80
ROOT.gPad.SetLeftMargin
(0.15)
81
frame.GetYaxis
().SetTitleOffset(1.6)
82
frame.Draw
()
83
84
c.SaveAs
(
"rf106_plotdecoration.png"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
roofit
rf106_plotdecoration.py
ROOT v6-34 - Reference Guide Generated on Mon Mar 31 2025 06:04:15 (GVA Time) using Doxygen 1.10.0