ROOT
Version v6.32
master
v6.34
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
rf405_realtocatfuncs.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit
3
## \notebook
4
## Data and categories: demonstration of real-discrete mapping functions
5
##
6
## \macro_image
7
## \macro_code
8
## \macro_output
9
##
10
## \date February 2018
11
## \authors Clemens Lange, Wouter Verkerke (C++ version)
12
13
import
ROOT
14
15
16
# Define pdf in x, sample dataset in x
17
# ------------------------------------------------------------------------
18
19
# Define a dummy PDF in x
20
x =
ROOT.RooRealVar
(
"x"
,
"x"
, 0, 10)
21
a =
ROOT.RooArgusBG
(
"a"
,
"argus(x)"
, x, 10.0, -1.0)
22
23
# Generate a dummy dataset
24
data =
a.generate
({x}, 10000)
25
26
# Create a threshold real -> cat function
27
# --------------------------------------------------------------------------
28
29
# A RooThresholdCategory is a category function that maps regions in a real-valued
30
# input observable observables to state names. At construction time a 'default'
31
# state name must be specified to which all values of x are mapped that are not
32
# otherwise assigned
33
xRegion =
ROOT.RooThresholdCategory
(
"xRegion"
,
"region of x"
, x,
"Background"
)
34
35
# Specify thresholds and state assignments one-by-one.
36
# Each statement specifies that all values _below_ the given value
37
# (and above any lower specified threshold) are mapped to the
38
# category state with the given name
39
#
40
# Background | SideBand | Signal | SideBand | Background
41
# 4.23 5.23 8.23 9.23
42
xRegion.addThreshold
(4.23,
"Background"
)
43
xRegion.addThreshold
(5.23,
"SideBand"
)
44
xRegion.addThreshold
(8.23,
"Signal"
)
45
xRegion.addThreshold
(9.23,
"SideBand"
)
46
47
# Use threshold function to plot data regions
48
# ----------------------------------------------
49
50
# Add values of threshold function to dataset so that it can be used as
51
# observable
52
data.addColumn
(xRegion)
53
54
# Make plot of data in x
55
xframe =
x.frame
(Title=
"Demo of threshold and binning mapping functions"
)
56
data.plotOn
(xframe)
57
58
# Use calculated category to select sideband data
59
data.plotOn
(xframe, Cut=
"xRegion==xRegion::SideBand"
, MarkerColor=
"r"
, LineColor=
"r"
)
60
61
# Create a binning real -> cat function
62
# ----------------------------------------------------------------------
63
64
# A RooBinningCategory is a category function that maps bins of a (named) binning definition
65
# in a real-valued input observable observables to state names. The state names are automatically
66
# constructed from the variable name, binning name and the bin number. If no binning name
67
# is specified the default binning is mapped
68
69
x.setBins
(10,
"coarse"
)
70
xBins =
ROOT.RooBinningCategory
(
"xBins"
,
"coarse bins in x"
, x,
"coarse"
)
71
72
# Use binning function for tabulation and plotting
73
# -----------------------------------------------------------------------------------------------
74
75
# Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data
76
# it can be a function of observables in data as well
77
xbtable =
data.table
(xBins)
78
xbtable.Print
(
"v"
)
79
80
# Add values of xBins function to dataset so that it can be used as
81
# observable
82
xb =
data.addColumn
(xBins)
83
84
# Define range "alt" as including bins 1,3,5,7,9
85
xb.setRange
(
"alt"
,
"x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9"
)
86
87
# Construct subset of data matching range "alt" but only for the first
88
# 5000 events and plot it on the frame
89
dataSel =
data.reduce
(CutRange=
"alt"
, EventRange=(0, 5000))
90
dataSel.plotOn
(xframe, MarkerColor=
"g"
, LineColor=
"g"
)
91
92
c =
ROOT.TCanvas
(
"rf405_realtocatfuncs"
,
"rf405_realtocatfuncs"
, 600, 600)
93
xframe.SetMinimum
(0.01)
94
ROOT.gPad.SetLeftMargin
(0.15)
95
xframe.GetYaxis
().SetTitleOffset(1.4)
96
xframe.Draw
()
97
98
c.SaveAs
(
"rf405_realtocatfuncs.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
rf405_realtocatfuncs.py
ROOT v6-32 - Reference Guide Generated on Sun Mar 30 2025 15:10:43 (GVA Time) using Doxygen 1.10.0