Logo ROOT   6.14/05
Reference Guide
rf804_mcstudy_constr.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'VALIDATION AND MC STUDIES' RooFit tutorial macro #804
5 ///
6 /// Using RooMCStudy on models with constrains
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooPolynomial.h"
19 #include "RooAddPdf.h"
20 #include "RooProdPdf.h"
21 #include "RooMCStudy.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "TH1.h"
26 using namespace RooFit ;
27 
28 
29 void rf804_mcstudy_constr()
30 {
31  // C r e a t e m o d e l w i t h p a r a m e t e r c o n s t r a i n t
32  // ---------------------------------------------------------------------------
33 
34  // Observable
35  RooRealVar x("x","x",-10,10) ;
36 
37  // Signal component
38  RooRealVar m("m","m",0,-10,10) ;
39  RooRealVar s("s","s",2,0.1,10) ;
40  RooGaussian g("g","g",x,m,s) ;
41 
42  // Background component
43  RooPolynomial p("p","p",x) ;
44 
45  // Composite model
46  RooRealVar f("f","f",0.4,0.,1.) ;
47  RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ;
48 
49  // Construct constraint on parameter f
50  RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.7),RooConst(0.1)) ;
51 
52  // Multiply constraint with p.d.f
53  RooProdPdf sumc("sumc","sum with constraint",RooArgSet(sum,fconstraint)) ;
54 
55 
56 
57  // S e t u p t o y s t u d y w i t h m o d e l
58  // ---------------------------------------------------
59 
60  // Perform toy study with internal constraint on f
62 
63  // Run 500 toys of 2000 events.
64  // Before each toy is generated, a value for the f is sampled from the constraint pdf and
65  // that value is used for the generation of that toy.
66  mcs.generateAndFit(500,2000) ;
67 
68  // Make plot of distribution of generated value of f parameter
69  TH1* h_f_gen = mcs.fitParDataSet().createHistogram("f_gen",-40) ;
70 
71  // Make plot of distribution of fitted value of f parameter
72  RooPlot* frame1 = mcs.plotParam(f,Bins(40)) ;
73  frame1->SetTitle("Distribution of fitted f values") ;
74 
75  // Make plot of pull distribution on f
76  RooPlot* frame2 = mcs.plotPull(f,Bins(40),FitGauss()) ;
77  frame1->SetTitle("Distribution of f pull values") ;
78 
79 
80 
81  TCanvas* c = new TCanvas("rf804_mcstudy_constr","rf804_mcstudy_constr",1200,400) ;
82  c->Divide(3) ;
83  c->cd(1) ; gPad->SetLeftMargin(0.15) ; h_f_gen->GetYaxis()->SetTitleOffset(1.4) ; h_f_gen->Draw() ;
84  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
85  c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
86 
87 }
88 
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:294
RooMCStudy is a help class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies...
Definition: RooMCStudy.h:32
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
static long int sum(long int i)
Definition: Factory.cxx:2258
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1117
RooCmdArg Binned(Bool_t flag=kTRUE)
auto * m
Definition: textangle.C:8
#define g(i)
Definition: RSha256.hxx:105
RooCmdArg PrintLevel(Int_t code)
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
#define f(i)
Definition: RSha256.hxx:104
void SetTitle(const char *name)
Set the title of the RooPlot to 'title'.
Definition: RooPlot.cxx:1098
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooCmdArg Silence(Bool_t flag=kTRUE)
RooCmdArg FitOptions(const char *opts)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
TAxis * GetYaxis()
Definition: TH1.h:316
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooCmdArg FitGauss(Bool_t flag=kTRUE)
The Canvas class.
Definition: TCanvas.h:31
The TH1 histogram class.
Definition: TH1.h:56
static constexpr double s
RooConstVar & RooConst(Double_t val)
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
RooCmdArg Bins(Int_t nbin)
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
RooCmdArg Constrain(const RooArgSet &params)
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558