ROOT   Reference Guide
Searching...
No Matches
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: using RooMCStudy on models with constrains
5///
6/// \macro_image
7/// \macro_code
8/// \macro_output
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooPolynomial.h"
18#include "RooProdPdf.h"
19#include "RooMCStudy.h"
20#include "RooPlot.h"
21#include "TCanvas.h"
22#include "TAxis.h"
23#include "TH1.h"
24using namespace RooFit;
25
27{
28 // 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
29 // ---------------------------------------------------------------------------
30
31 // Observable
32 RooRealVar x("x", "x", -10, 10);
33
34 // Signal component
35 RooRealVar m("m", "m", 0, -10, 10);
36 RooRealVar s("s", "s", 2, 0.1, 10);
37 RooGaussian g("g", "g", x, m, s);
38
39 // Background component
40 RooPolynomial p("p", "p", x);
41
42 // Composite model
43 RooRealVar f("f", "f", 0.4, 0., 1.);
44 RooAddPdf sum("sum", "sum", RooArgSet(g, p), f);
45
46 // Construct constraint on parameter f
47 RooGaussian fconstraint("fconstraint", "fconstraint", f, 0.7, 0.1);
48
49 // Multiply constraint with pdf
50 RooProdPdf sumc("sumc", "sum with constraint", RooArgSet(sum, fconstraint));
51
52 // S e t u p t o y s t u d y w i t h m o d e l
53 // ---------------------------------------------------
54
55 // Perform toy study with internal constraint on f
56 RooMCStudy mcs(sumc, x, Constrain(f), Silence(), Binned(), FitOptions(PrintLevel(-1)));
57
58 // Run 500 toys of 2000 events.
59 // Before each toy is generated, a value for the f is sampled from the constraint pdf and
60 // that value is used for the generation of that toy.
61 mcs.generateAndFit(500, 2000);
62
63 // Make plot of distribution of generated value of f parameter
64 TH1 *h_f_gen = mcs.fitParDataSet().createHistogram("f_gen", AutoBinning(40));
65
66 // Make plot of distribution of fitted value of f parameter
67 RooPlot *frame1 = mcs.plotParam(f, Bins(40));
68 frame1->SetTitle("Distribution of fitted f values");
69
70 // Make plot of pull distribution on f
71 RooPlot *frame2 = mcs.plotPull(f, Bins(40), FitGauss());
72 frame1->SetTitle("Distribution of f pull values");
73
74 TCanvas *c = new TCanvas("rf804_mcstudy_constr", "rf804_mcstudy_constr", 1200, 400);
75 c->Divide(3);
76 c->cd(1);
78 h_f_gen->GetYaxis()->SetTitleOffset(1.4);
79 h_f_gen->Draw();
80 c->cd(2);
82 frame1->GetYaxis()->SetTitleOffset(1.4);
83 frame1->Draw();
84 c->cd(3);
86 frame2->GetYaxis()->SetTitleOffset(1.4);
87 frame2->Draw();
88}
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
winID h TVirtualViewer3D TVirtualGLPainter p
Efficient implementation of a sum of PDFs of the form.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies, that involve fittin...
Definition RooMCStudy.h:32
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
void SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
Definition RooPlot.cxx:1255
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
RooPolynomial implements a polynomial p.d.f of the form.
Efficient implementation of a product of PDFs of the form.
Definition RooProdPdf.h:33
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TAxis * GetYaxis()
Definition TH1.h:325
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
RooCmdArg FitGauss(bool flag=true)
RooCmdArg AutoBinning(Int_t nbins=100, double marginFactor=0.1)
RooCmdArg Silence(bool flag=true)
RooCmdArg FitOptions(const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={})
RooCmdArg Binned(bool flag=true)
RooCmdArg Bins(Int_t nbin)
RooCmdArg Constrain(const RooArgSet &params)
RooCmdArg PrintLevel(Int_t code)
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
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345