ROOT   Reference Guide
Searching...
No Matches
rf505_asciicfg.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Organisation and simultaneous fits: reading and writing ASCII configuration files
5///
6/// \macro_code
7/// \macro_output
8///
9/// \date July 2008
10/// \author Wouter Verkerke
11
12#include "RooRealVar.h"
13#include "RooDataSet.h"
14#include "RooGaussian.h"
15#include "RooPolynomial.h"
17#include "TCanvas.h"
18#include "TAxis.h"
19#include "RooPlot.h"
20using namespace RooFit;
21
22void rf505_asciicfg()
23{
24 // C r e a t e p d f
25 // ------------------
26
27 // Construct gauss(x,m,s)
28 RooRealVar x("x", "x", -10, 10);
29 RooRealVar m("m", "m", 0, -10, 10);
30 RooRealVar s("s", "s", 1, -10, 10);
31 RooGaussian gauss("g", "g", x, m, s);
32
33 // Construct poly(x,p0)
34 RooRealVar p0("p0", "p0", 0.01, 0., 1.);
35 RooPolynomial poly("p", "p", x, p0);
36
37 // Construct model = f*gauss(x) + (1-f)*poly(x)
38 RooRealVar f("f", "f", 0.5, 0., 1.);
39 RooAddPdf model("model", "model", RooArgSet(gauss, poly), f);
40
41 // F i t m o d e l t o t o y d a t a
42 // -----------------------------------------
43
44 std::unique_ptr<RooDataSet> d{model.generate(x, 1000)};
45 model.fitTo(*d, PrintLevel(-1));
46
47 // 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
48 // -----------------------------------------------------------
49
50 // Obtain set of parameters
51 std::unique_ptr<RooArgSet> params{model.getParameters(x)};
52
53 // Write parameters to file
54 params->writeToFile("rf505_asciicfg_example.txt");
55
56 TString dir1 = gROOT->GetTutorialDir() ;
57 dir1.Append("/roofit/rf505_asciicfg.txt") ;
58 TString dir2 = "rf505_asciicfg_example.txt";
59
60 // 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
61 // ----------------------------------------------------------------
62
63 // Read parameters from file
65 params->Print("v");
66
67 // Read parameters from section 'Section2' of file
69 params->Print("v");
70
71 // Read parameters from section 'Section3' of file. Mark all
72 // variables that were processed with the "READ" attribute
74
75 // Print the list of parameters that were not read from Section3
76 cout << "The following parameters of the were _not_ read from Section3: "
77 << (*params->selectByAttrib("READ", false)) << endl;
78
79 // Read parameters from section 'Section4' of file, which contains
80 // 'include file' statement of rf505_asciicfg_example.txt
81 // so that we effective read the same
82
84 params->Print("v");
85}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define gROOT
Definition TROOT.h:407
Efficient implementation of a sum of PDFs of the form.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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
RooCmdArg PrintLevel(Int_t code)
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 JSONIO.h:26
TMarker m
Definition textangle.C:8