Organization and simultaneous fits: reading and writing ASCII configuration files
from __future__ import print_function
import ROOT
x = ROOT.RooRealVar("x", "x", -10, 10)
m = ROOT.RooRealVar("m", "m", 0, -10, 10)
s = ROOT.RooRealVar("s", "s", 1, -10, 10)
gauss = ROOT.RooGaussian("g", "g", x, m, s)
p0 = ROOT.RooRealVar("p0", "p0", 0.01, 0., 1.)
poly = ROOT.RooPolynomial("p", "p", x, ROOT.RooArgList(p0))
f = ROOT.RooRealVar("f", "f", 0.5, 0., 1.)
model = ROOT.RooAddPdf("model", "model", ROOT.RooArgList(
gauss, poly), ROOT.RooArgList(f))
d = model.generate(ROOT.RooArgSet(x), 1000)
model.fitTo(d)
params = model.getParameters(ROOT.RooArgSet(x))
params.writeToFile("rf505_asciicfg_example.txt")
params.readFromFile("rf505_asciicfg_example.txt")
params.Print("v")
configFile = ROOT.gROOT.GetTutorialDir().Data() + "/roofit/rf505_asciicfg.txt"
params.readFromFile(configFile, "", "Section2")
params.Print("v")
params.readFromFile(configFile, "READ", "Section3")
print("The following parameters of the were _not_ read from Section3: ",
params.selectByAttrib("READ", ROOT.kFALSE))
params.readFromFile(configFile, "", "Section4")
params.Print("v")