Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf505_asciicfg.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Organisation and simultaneous fits: reading and writing ASCII configuration files

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooPolynomial.h"
#include "RooAddPdf.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;
{
// C r e a t e p d f
// ------------------
// Construct gauss(x,m,s)
RooRealVar x("x", "x", -10, 10);
RooRealVar m("m", "m", 0, -10, 10);
RooRealVar s("s", "s", 1, -10, 10);
RooGaussian gauss("g", "g", x, m, s);
// Construct poly(x,p0)
RooRealVar p0("p0", "p0", 0.01, 0., 1.);
RooPolynomial poly("p", "p", x, p0);
// Construct model = f*gauss(x) + (1-f)*poly(x)
RooRealVar f("f", "f", 0.5, 0., 1.);
RooAddPdf model("model", "model", RooArgSet(gauss, poly), f);
// F i t m o d e l t o t o y d a t a
// -----------------------------------------
std::unique_ptr<RooDataSet> d{model.generate(x, 1000)};
model.fitTo(*d, PrintLevel(-1));
// W r i t e p a r a m e t e r s t o a s c i i f i l e
// -----------------------------------------------------------
// Obtain set of parameters
std::unique_ptr<RooArgSet> params{model.getParameters(x)};
// Write parameters to file
params->writeToFile("rf505_asciicfg_example.txt");
TString dir1 = gROOT->GetTutorialDir() ;
dir1.Append("/roofit/rf505_asciicfg.txt") ;
TString dir2 = "rf505_asciicfg_example.txt";
// R e a d p a r a m e t e r s f r o m a s c i i f i l e
// ----------------------------------------------------------------
// Read parameters from file
params->readFromFile(dir2);
params->Print("v");
// Read parameters from section 'Section2' of file
params->readFromFile(dir1, 0, "Section2");
params->Print("v");
// Read parameters from section 'Section3' of file. Mark all
// variables that were processed with the "READ" attribute
params->readFromFile(dir1, "READ", "Section3");
// Print the list of parameters that were not read from Section3
cout << "The following parameters of the were _not_ read from Section3: "
<< (*params->selectByAttrib("READ", false)) << endl;
// Read parameters from section 'Section4' of file, which contains
// 'include file' statement of rf505_asciicfg_example.txt
// so that we effective read the same
params->readFromFile(dir1, 0, "Section4");
params->Print("v");
}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define gROOT
Definition TROOT.h:406
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:33
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
RooPolynomial implements a polynomial p.d.f of the form.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Basic string class.
Definition TString.h:139
TString & Append(const char *cs)
Definition TString.h:572
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64
TMarker m
Definition textangle.C:8
[#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:Fitting -- RooAbsPdf::fitTo(model) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
1) 0x7ffd793de9b8 RooRealVar:: f = 0.50733 +/- 0.020971 L(0 - 1) "f"
2) 0x7ffd793dde00 RooRealVar:: m = 0.0064018 +/- 0.053686 L(-10 - 10) "m"
3) 0x7ffd793de5d0 RooRealVar:: p0 = 0.0073509 +/- 0.0078312 L(0 - 1) "p0"
4) 0x7ffd793de1e8 RooRealVar:: s = 0.96516 +/- 0.047052 L(-10 - 10) "s"
[#1] INFO:InputArguments -- RooArgSet::readFromStream(parameters): processing include file rf505_asciicfg_example.txt
1) 0x7ffd793de9b8 RooRealVar:: f = 0.45 +/- 0.03 L(0 - 1) "f"
2) 0x7ffd793dde00 RooRealVar:: m = 0.025 +/- 0.02 L(-10 - 10) "m"
3) 0x7ffd793de5d0 RooRealVar:: p0 = 0.0022 +/- 0.0001 L(0 - 1) "p0"
4) 0x7ffd793de1e8 RooRealVar:: s = 0.98 +/- 0.03 L(-10 - 10) "s"
[#1] INFO:InputArguments -- RooArgSet::readFromStream(parameters): processing include file rf505_asciicfg_example.txt
The following parameters of the were _not_ read from Section3: (p0,s)
[#1] INFO:InputArguments -- RooArgSet::readFromStream(parameters): processing include file rf505_asciicfg_example.txt
1) 0x7ffd793de9b8 RooRealVar:: f = 0.372 C L(0 - 1) "f"
2) 0x7ffd793dde00 RooRealVar:: m = 0.195 C L(-10 - 10) "m"
3) 0x7ffd793de5d0 RooRealVar:: p0 = 0.0022 +/- 0.0001 L(0 - 1) "p0"
4) 0x7ffd793de1e8 RooRealVar:: s = 0.98 +/- 0.03 L(-10 - 10) "s"
Date
July 2008
Author
Wouter Verkerke

Definition in file rf505_asciicfg.C.