Logo ROOT  
Reference Guide
rf504_simwstool.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4/// Organisation and simultaneous fits: using RooSimWSTool to construct a simultaneous pdf
5/// that is built of variations of an input pdf
6///
7/// \macro_output
8/// \macro_code
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooCategory.h"
15#include "RooDataSet.h"
16#include "RooGaussian.h"
17#include "RooConstVar.h"
18#include "RooPolynomial.h"
19#include "RooSimultaneous.h"
20#include "RooAddPdf.h"
21#include "RooWorkspace.h"
22#include "RooSimWSTool.h"
23#include "RooPlot.h"
24#include "TCanvas.h"
25#include "TAxis.h"
26#include "TFile.h"
27#include "TH1.h"
28using namespace RooFit;
29
30void rf504_simwstool()
31{
32 // C r e a t e m a s t e r p d f
33 // ---------------------------------
34
35 // Construct gauss(x,m,s)
36 RooRealVar x("x", "x", -10, 10);
37 RooRealVar m("m", "m", 0, -10, 10);
38 RooRealVar s("s", "s", 1, -10, 10);
39 RooGaussian gauss("g", "g", x, m, s);
40
41 // Construct poly(x,p0)
42 RooRealVar p0("p0", "p0", 0.01, 0., 1.);
43 RooPolynomial poly("p", "p", x, p0);
44
45 // Construct model = f*gauss(x) + (1-f)*poly(x)
46 RooRealVar f("f", "f", 0.5, 0., 1.);
47 RooAddPdf model("model", "model", RooArgSet(gauss, poly), f);
48
49 // C r e a t e c a t e g o r y o b s e r v a b l e s f o r s p l i t t i n g
50 // ----------------------------------------------------------------------------------
51
52 // Define two categories that can be used for splitting
53 RooCategory c("c", "c");
54 c.defineType("run1");
55 c.defineType("run2");
56
57 RooCategory d("d", "d");
58 d.defineType("foo");
59 d.defineType("bar");
60
61 // S e t u p S i m W S T o o l
62 // -----------------------------
63
64 // Import ingredients in a workspace
65 RooWorkspace w("w", "w");
66 w.import(RooArgSet(model, c, d));
67
68 // Make Sim builder tool
69 RooSimWSTool sct(w);
70
71 // B u i l d a s i m u l t a n e o u s m o d e l w i t h o n e s p l i t
72 // ---------------------------------------------------------------------------------
73
74 // Construct a simultaneous pdf with the following form
75 //
76 // model_run1(x) = f*gauss_run1(x,m_run1,s) + (1-f)*poly
77 // model_run2(x) = f*gauss_run2(x,m_run2,s) + (1-f)*poly
78 // simpdf(x,c) = model_run1(x) if c=="run1"
79 // = model_run2(x) if c=="run2"
80 //
81 // Returned pdf is owned by the workspace
82 RooSimultaneous *model_sim = sct.build("model_sim", "model", SplitParam("m", "c"));
83
84 // Print tree structure of model
85 model_sim->Print("t");
86
87 // Adjust model_sim parameters in workspace
88 w.var("m_run1")->setVal(-3);
89 w.var("m_run2")->setVal(+3);
90
91 // Print contents of workspace
92 w.Print("v");
93
94 // B u i l d a s i m u l t a n e o u s m o d e l w i t h p r o d u c t s p l i t
95 // -----------------------------------------------------------------------------------------
96
97 // Build another simultaneous pdf using a composite split in states c X d
98 RooSimultaneous *model_sim2 = sct.build("model_sim2", "model", SplitParam("p0", "c,d"));
99
100 // Print tree structure of this model
101 model_sim2->Print("t");
102}
#define d(i)
Definition: RSha256.hxx:102
#define f(i)
Definition: RSha256.hxx:104
#define c(i)
Definition: RSha256.hxx:101
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
Definition: RooAbsArg.h:340
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:32
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:27
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
The RooSimWSTool is a tool operating on RooWorkspace objects that can clone PDFs into a series of var...
Definition: RooSimWSTool.h:37
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooCmdArg SplitParam(const char *varname, const char *catname)
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static constexpr double s
static constexpr double gauss
auto * m
Definition: textangle.C:8