ROOT
Version master
master
v6.34
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
v6.04
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
rf502_wspacewrite.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit_main
3
## \notebook -nodraw
4
## Organization and simultaneous fits: creating and writing a workspace
5
##
6
## \macro_code
7
## \macro_output
8
##
9
## \date February 2018
10
## \authors Clemens Lange, Wouter Verkerke (C++ version)
11
12
import
ROOT
13
14
15
# Create model and dataset
16
# -----------------------------------------------
17
18
# Declare observable x
19
x =
ROOT.RooRealVar
(
"x"
,
"x"
, 0, 10)
20
21
# Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and
22
# their parameters
23
mean =
ROOT.RooRealVar
(
"mean"
,
"mean of gaussians"
, 5, 0, 10)
24
sigma1 =
ROOT.RooRealVar
(
"sigma1"
,
"width of gaussians"
, 0.5)
25
sigma2 =
ROOT.RooRealVar
(
"sigma2"
,
"width of gaussians"
, 1)
26
27
sig1 =
ROOT.RooGaussian
(
"sig1"
,
"Signal component 1"
, x, mean, sigma1)
28
sig2 =
ROOT.RooGaussian
(
"sig2"
,
"Signal component 2"
, x, mean, sigma2)
29
30
# Build Chebychev polynomial pdf
31
a0 =
ROOT.RooRealVar
(
"a0"
,
"a0"
, 0.5, 0.0, 1.0)
32
a1 =
ROOT.RooRealVar
(
"a1"
,
"a1"
, -0.2, 0.0, 1.0)
33
bkg =
ROOT.RooChebychev
(
"bkg"
,
"Background"
, x, [a0, a1])
34
35
# Sum the signal components into a composite signal pdf
36
sig1frac =
ROOT.RooRealVar
(
"sig1frac"
,
"fraction of component 1 in signal"
, 0.8, 0.0, 1.0)
37
sig =
ROOT.RooAddPdf
(
"sig"
,
"Signal"
, [sig1, sig2], [sig1frac])
38
39
# Sum the composite signal and background
40
bkgfrac =
ROOT.RooRealVar
(
"bkgfrac"
,
"fraction of background"
, 0.5, 0.0, 1.0)
41
model =
ROOT.RooAddPdf
(
"model"
,
"g1+g2+a"
, [bkg, sig], [bkgfrac])
42
43
# Generate a data sample of 1000 events in x from model
44
data =
model.generate
({x}, 1000)
45
46
# Create workspace, import data and model
47
# -----------------------------------------------------------------------------
48
49
# Create a empty workspace
50
w =
ROOT.RooWorkspace
(
"w"
,
"workspace"
)
51
52
# Import model and all its components into the workspace
53
w.Import
(model)
54
55
# Import data into the workspace
56
w.Import
(data)
57
58
# Print workspace contents
59
w.Print
()
60
61
# Save workspace in file
62
# -------------------------------------------
63
64
# Save the workspace into a ROOT file
65
w.writeToFile
(
"rf502_workspace_py.root"
)
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
roofit
rf502_wspacewrite.py
ROOT master - Reference Guide Generated on Tue Mar 11 2025 15:57:22 (GVA Time) using Doxygen 1.10.0