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