Logo ROOT   6.10/09
Reference Guide
rf504_simwstool.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 /// 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #504
5 ///
6 /// Using RooSimWSTool to construct a simultaneous p.d.f that is built
7 /// of variations of an input p.d.f
8 ///
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
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 
32 void rf504_simwstool()
33 {
34  // C r e a t e m a s t e r p d f
35  // ---------------------------------
36 
37  // Construct gauss(x,m,s)
38  RooRealVar x("x","x",-10,10) ;
39  RooRealVar m("m","m",0,-10,10) ;
40  RooRealVar s("s","s",1,-10,10) ;
41  RooGaussian gauss("g","g",x,m,s) ;
42 
43  // Construct poly(x,p0)
44  RooRealVar p0("p0","p0",0.01,0.,1.) ;
45  RooPolynomial poly("p","p",x,p0) ;
46 
47  // Construct model = f*gauss(x) + (1-f)*poly(x)
48  RooRealVar f("f","f",0.5,0.,1.) ;
49  RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;
50 
51 
52 
53  // 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
54  // ----------------------------------------------------------------------------------
55 
56  // Define two categories that can be used for splitting
57  RooCategory c("c","c") ;
58  c.defineType("run1") ;
59  c.defineType("run2") ;
60 
61  RooCategory d("d","d") ;
62  d.defineType("foo") ;
63  d.defineType("bar") ;
64 
65 
66 
67  // S e t u p S i m W S T o o l
68  // -----------------------------
69 
70  // Import ingredients in a workspace
71  RooWorkspace w("w","w") ;
72  w.import(RooArgSet(model,c,d)) ;
73 
74  // Make Sim builder tool
75  RooSimWSTool sct(w) ;
76 
77 
78  // 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
79  // ---------------------------------------------------------------------------------
80 
81  // Construct a simultaneous p.d.f with the following form
82  //
83  // model_run1(x) = f*gauss_run1(x,m_run1,s) + (1-f)*poly
84  // model_run2(x) = f*gauss_run2(x,m_run2,s) + (1-f)*poly
85  // simpdf(x,c) = model_run1(x) if c=="run1"
86  // = model_run2(x) if c=="run2"
87  //
88  // Returned p.d.f is owned by the workspace
89  RooSimultaneous* model_sim = sct.build("model_sim","model",SplitParam("m","c")) ;
90 
91  // Print tree structure of model
92  model_sim->Print("t") ;
93 
94  // Adjust model_sim parameters in workspace
95  w.var("m_run1")->setVal(-3) ;
96  w.var("m_run2")->setVal(+3) ;
97 
98  // Print contents of workspace
99  w.Print("v") ;
100 
101 
102 
103  // 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
104  // -----------------------------------------------------------------------------------------
105 
106  // Build another simultaneous p.d.f using a composite split in states c X d
107  RooSimultaneous* model_sim2 = sct.build("model_sim2","model",SplitParam("p0","c,d")) ;
108 
109  // Print tree structure of this model
110  model_sim2->Print("t") ;
111 
112 }
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooCmdArg SplitParam(const char *varname, const char *catname)
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooAbsArg.h:227
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
TMarker * m
Definition: textangle.C:8
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
double f(double x)
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
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:42