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
rf505_asciicfg.py
Go to the documentation of this file.
1
## \file rf505_asciicfg.py
2
## \ingroup tutorial_roofit_main
3
## \notebook -nodraw
4
## Organization and simultaneous fits: reading and writing ASCII configuration files
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 pdf
16
# ------------------
17
18
# Construct gauss(x,m,s)
19
x =
ROOT.RooRealVar
(
"x"
,
"x"
, -10, 10)
20
m =
ROOT.RooRealVar
(
"m"
,
"m"
, 0, -10, 10)
21
s =
ROOT.RooRealVar
(
"s"
,
"s"
, 1, -10, 10)
22
gauss =
ROOT.RooGaussian
(
"g"
,
"g"
, x, m, s)
23
24
# Construct poly(x,p0)
25
p0 =
ROOT.RooRealVar
(
"p0"
,
"p0"
, 0.01, 0.0, 1.0)
26
poly =
ROOT.RooPolynomial
(
"p"
,
"p"
, x, [p0])
27
28
# model = f*gauss(x) + (1-f)*poly(x)
29
f =
ROOT.RooRealVar
(
"f"
,
"f"
, 0.5, 0.0, 1.0)
30
model =
ROOT.RooAddPdf
(
"model"
,
"model"
, [gauss, poly], [f])
31
32
# Fit model to toy data
33
# -----------------------------------------
34
35
d =
model.generate
({x}, 1000)
36
model.fitTo
(d, PrintLevel=-1)
37
38
# Write parameters to ASCII file
39
# -----------------------------------------------------------
40
41
# Obtain set of parameters
42
params =
model.getParameters
({x})
43
44
# Write parameters to file
45
params.writeToFile
(
"rf505_asciicfg_example.txt"
)
46
47
# Read parameters from ASCII file
48
# ----------------------------------------------------------------
49
50
# Read parameters from file
51
params.readFromFile
(
"rf505_asciicfg_example.txt"
)
52
params.Print
(
"v"
)
53
54
configFile =
ROOT.gROOT.GetTutorialDir
().Data() +
"/roofit/rf505_asciicfg.txt"
55
56
# Read parameters from section 'Section2' of file
57
params.readFromFile
(configFile,
""
,
"Section2"
)
58
params.Print
(
"v"
)
59
60
# Read parameters from section 'Section3' of file. Mark all
61
# variables that were processed with the "READ" attribute
62
params.readFromFile
(configFile,
"READ"
,
"Section3"
)
63
64
# Print the list of parameters that were not read from Section3
65
print(
"The following parameters of the were _not_ read from Section3: "
,
params.selectByAttrib
(
"READ"
,
False
))
66
67
# Read parameters from section 'Section4' of file, contains
68
# 'include file' statement of rf505_asciicfg_example.txt
69
# so that we effective read the same
70
params.readFromFile
(configFile,
""
,
"Section4"
)
71
params.Print
(
"v"
)
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
rf505_asciicfg.py
ROOT master - Reference Guide Generated on Mon Mar 10 2025 15:21:31 (GVA Time) using Doxygen 1.10.0