ROOT   Reference Guide
rf312_multirangefit.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -nodraw
4///
5/// Multidimensional models: performing fits in multiple (disjoint) ranges in one or more dimensions
6///
7/// \macro_output
8/// \macro_code
9///
10/// \date 07/2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooConstVar.h"
17#include "RooProdPdf.h"
19#include "RooPolynomial.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "RooPlot.h"
23#include "RooFitResult.h"
24using namespace RooFit;
25
27{
28
29 // C r e a t e 2 D p d f a n d d a t a
30 // -------------------------------------------
31
32 // Define observables x,y
33 RooRealVar x("x", "x", -10, 10);
34 RooRealVar y("y", "y", -10, 10);
35
36 // Construct the signal pdf gauss(x)*gauss(y)
37 RooRealVar mx("mx", "mx", 1, -10, 10);
38 RooRealVar my("my", "my", 1, -10, 10);
39
40 RooGaussian gx("gx", "gx", x, mx, RooConst(1));
41 RooGaussian gy("gy", "gy", y, my, RooConst(1));
42
43 RooProdPdf sig("sig", "sig", gx, gy);
44
45 // Construct the background pdf (flat in x,y)
46 RooPolynomial px("px", "px", x);
47 RooPolynomial py("py", "py", y);
48 RooProdPdf bkg("bkg", "bkg", px, py);
49
50 // Construct the composite model sig+bkg
51 RooRealVar f("f", "f", 0., 1.);
52 RooAddPdf model("model", "model", RooArgList(sig, bkg), f);
53
54 // Sample 10000 events in (x,y) from the model
55 RooDataSet *modelData = model.generate(RooArgSet(x, y), 10000);
56
57 // D e f i n e s i g n a l a n d s i d e b a n d r e g i o n s
58 // -------------------------------------------------------------------
59
60 // Construct the SideBand1,SideBand2,Signal regions
61 //
62 // |
63 // +-------------+-----------+
64 // | | |
65 // | Side | Sig |
66 // | Band1 | nal |
67 // | | |
68 // --+-------------+-----------+--
69 // | |
70 // | Side |
71 // | Band2 |
72 // | |
73 // +-------------+-----------+
74 // |
75
76 x.setRange("SB1", -10, +10);
77 y.setRange("SB1", -10, 0);
78
79 x.setRange("SB2", -10, 0);
80 y.setRange("SB2", 0, +10);
81
82 x.setRange("SIG", 0, +10);
83 y.setRange("SIG", 0, +10);
84
85 x.setRange("FULL", -10, +10);
86 y.setRange("FULL", -10, +10);
87
88 // P e r f o r m f i t s i n i n d i v i d u a l s i d e b a n d r e g i o n s
89 // -------------------------------------------------------------------------------------
90
91 // Perform fit in SideBand1 region (RooAddPdf coefficients will be interpreted in full range)
92 RooFitResult *r_sb1 = model.fitTo(*modelData, Range("SB1"), Save());
93
94 // Perform fit in SideBand2 region (RooAddPdf coefficients will be interpreted in full range)
95 RooFitResult *r_sb2 = model.fitTo(*modelData, Range("SB2"), Save());
96
97 // P e r f o r m f i t s i n j o i n t s i d e b a n d r e g i o n s
98 // -----------------------------------------------------------------------------
99
100 // Now perform fit to joint 'L-shaped' sideband region 'SB1|SB2'
101 // (RooAddPdf coefficients will be interpreted in full range)
102 RooFitResult *r_sb12 = model.fitTo(*modelData, Range("SB1,SB2"), Save());
103
104 // Print results for comparison
105 r_sb1->Print();
106 r_sb2->Print();
107 r_sb12->Print();
108}
#define f(i)
Definition: RSha256.hxx:104
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFitResult.h:66
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
RooConstVar & RooConst(Double_t val)
RooCmdArg Save(Bool_t flag=kTRUE)
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Ta Range(0, 0, 1, 1)