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