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.0, 1.0)
poly = ROOT.RooPolynomial("p", "p", x, [p0])
 
f = ROOT.RooRealVar("f", "f", 0.5, 0.0, 1.0)
model = ROOT.RooAddPdf("model", "model", [gauss, poly], [f])
 
 
d = model.generate({x}, 1000)
model.fitTo(d, PrintLevel=-1)
 
 
params = model.getParameters({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", False))
 
params.readFromFile(configFile, "", "Section4")
params.Print("v")
  [#0] WARNING:InputArguments -- The parameter 's' with range [-10, 10] of the RooGaussian 'g' exceeds the safe range of (0, inf). Advise to limit its range.
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization --  The following expressions will be evaluated in cache-and-track mode: (g,p)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
  1) 0x78f3e20 RooRealVar::  f = 0.50735 +/- 0.020971  L(0 - 1)  "f"
  2) 0x727ee80 RooRealVar::  m = 0.0062321 +/- 0.053675  L(-10 - 10)  "m"
  3) 0x6aa7ba0 RooRealVar:: p0 = 0.0072987 +/- 0.0078458  L(0 - 1)  "p0"
  4) 0x72967b0 RooRealVar::  s = 0.9649 +/- 0.047032  L(-10 - 10)  "s"
[#1] INFO:InputArguments -- RooArgSet::readFromStream(parameters): processing include file rf505_asciicfg_example.txt
  1) 0x78f3e20 RooRealVar::  f = 0.45 +/- 0.03  L(0 - 1)  "f"
  2) 0x727ee80 RooRealVar::  m = 0.025 +/- 0.02  L(-10 - 10)  "m"
  3) 0x6aa7ba0 RooRealVar:: p0 = 0.0022 +/- 0.0001  L(0 - 1)  "p0"
  4) 0x72967b0 RooRealVar::  s = 0.98 +/- 0.03  L(-10 - 10)  "s"
[#1] INFO:InputArguments -- RooArgSet::readFromStream(parameters): processing include file rf505_asciicfg_example.txt
[#1] INFO:InputArguments -- RooArgSet::readFromStream(parameters): processing include file rf505_asciicfg_example.txt
  1) 0x78f3e20 RooRealVar::  f = 0.372 C  L(0 - 1)  "f"
  2) 0x727ee80 RooRealVar::  m = 0.195 C  L(-10 - 10)  "m"
  3) 0x6aa7ba0 RooRealVar:: p0 = 0.0022 +/- 0.0001  L(0 - 1)  "p0"
  4) 0x72967b0 RooRealVar::  s = 0.98 +/- 0.03  L(-10 - 10)  "s"
The following parameters of the were _not_ read from Section3:  { @0x83d9630, @0x83d9638 }
- Date
 - February 2018 
 
- Authors
 - Clemens Lange, Wouter Verkerke (C++ version) 
 
Definition in file rf505_asciicfg.py.