Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_code
8/// \macro_output
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 "RooPolynomial.h"
18#include "RooSimultaneous.h"
19#include "RooAddPdf.h"
20#include "RooWorkspace.h"
21#include "RooSimWSTool.h"
22#include "RooPlot.h"
23#include "TCanvas.h"
24#include "TAxis.h"
25#include "TFile.h"
26#include "TH1.h"
27using namespace RooFit;
28
29void rf504_simwstool()
30{
31 // C r e a t e m a s t e r p d f
32 // ---------------------------------
33
34 // Construct gauss(x,m,s)
35 RooRealVar x("x", "x", -10, 10);
36 RooRealVar m("m", "m", 0, -10, 10);
37 RooRealVar s("s", "s", 1, -10, 10);
38 RooGaussian gauss("g", "g", x, m, s);
39
40 // Construct poly(x,p0)
41 RooRealVar p0("p0", "p0", 0.01, 0., 1.);
42 RooPolynomial poly("p", "p", x, p0);
43
44 // Construct model = f*gauss(x) + (1-f)*poly(x)
45 RooRealVar f("f", "f", 0.5, 0., 1.);
46 RooAddPdf model("model", "model", RooArgSet(gauss, poly), f);
47
48 // 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
49 // ----------------------------------------------------------------------------------
50
51 // Define two categories that can be used for splitting
52 RooCategory c("c", "c");
53 c.defineType("run1");
54 c.defineType("run2");
55
56 RooCategory d("d", "d");
57 d.defineType("foo");
58 d.defineType("bar");
59
60 // S e t u p S i m W S T o o l
61 // -----------------------------
62
63 // Import ingredients in a workspace
64 RooWorkspace w("w", "w");
65 w.import(RooArgSet(model, c, d));
66
67 // Make Sim builder tool
68 RooSimWSTool sct(w);
69
70 // 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
71 // ---------------------------------------------------------------------------------
72
73 // Construct a simultaneous pdf with the following form
74 //
75 // model_run1(x) = f*gauss_run1(x,m_run1,s) + (1-f)*poly
76 // model_run2(x) = f*gauss_run2(x,m_run2,s) + (1-f)*poly
77 // simpdf(x,c) = model_run1(x) if c=="run1"
78 // = model_run2(x) if c=="run2"
79 //
80 // Returned pdf is owned by the workspace
81 RooSimultaneous *model_sim = sct.build("model_sim", "model", SplitParam("m", "c"));
82
83 // Print tree structure of model
84 model_sim->Print("t");
85
86 // Adjust model_sim parameters in workspace
87 w.var("m_run1")->setVal(-3);
88 w.var("m_run2")->setVal(+3);
89
90 // Print contents of workspace
91 w.Print("v");
92
93 // 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
94 // -----------------------------------------------------------------------------------------
95
96 // Build another simultaneous pdf using a composite split in states c X d
97 RooSimultaneous *model_sim2 = sct.build("model_sim2", "model", SplitParam("p0", "c,d"));
98
99 // Print tree structure of this model
100 model_sim2->Print("t");
101}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:294
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
Object to represent discrete states.
Definition RooCategory.h:28
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
The RooSimWSTool is a tool operating on RooWorkspace objects that can clone PDFs into a series of var...
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
Persistable container for RooFit projects.
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...
Definition JSONIO.h:26
TMarker m
Definition textangle.C:8