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"
29 using namespace RooFit;
30 
31 void 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 }
c
#define c(i)
Definition: RSha256.hxx:119
m
auto * m
Definition: textangle.C:8
RooWorkspace.h
RooAddPdf
Definition: RooAddPdf.h:32
f
#define f(i)
Definition: RSha256.hxx:122
RooSimultaneous.h
RooAbsArg::Print
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
Definition: RooAbsArg.h:320
RooGaussian.h
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
RooAddPdf.h
TCanvas.h
RooDataSet.h
TFile.h
RooPolynomial.h
TGeant4Unit::gauss
static constexpr double gauss
Definition: TGeant4SystemOfUnits.h:269
RooFit
Definition: RooCFunction1Binding.h:29
RooPolynomial
Definition: RooPolynomial.h:28
RooPlot.h
rf504_simwstool
Definition: rf504_simwstool.py:1
RooCategory.h
RooRealVar.h
RooConstVar.h
RooWorkspace
Definition: RooWorkspace.h:43
RooCategory
Definition: RooCategory.h:27
TAxis.h
d
#define d(i)
Definition: RSha256.hxx:120
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooFit::SplitParam
RooCmdArg SplitParam(const char *varname, const char *catname)
Definition: RooGlobalFunc.cxx:320
RooSimWSTool
Definition: RooSimWSTool.h:37
RooSimWSTool.h
RooSimultaneous
Definition: RooSimultaneous.h:37
RooRealVar
Definition: RooRealVar.h:35
TH1.h
RooArgSet
Definition: RooArgSet.h:28