Logo 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"
18 #include "RooAddPdf.h"
19 #include "RooPolynomial.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "RooPlot.h"
23 #include "RooFitResult.h"
24 using 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 }
RooAddPdf
Definition: RooAddPdf.h:32
f
#define f(i)
Definition: RSha256.hxx:122
RooArgList
Definition: RooArgList.h:21
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
RooAddPdf.h
TCanvas.h
RooDataSet.h
RooFitResult
Definition: RooFitResult.h:40
RooPolynomial.h
RooProdPdf.h
RooFit
Definition: RooCFunction1Binding.h:29
RooPolynomial
Definition: RooPolynomial.h:28
RooPlot.h
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooFitResult.h
RooConstVar.h
TAxis.h
RooFit::Range
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Definition: RooGlobalFunc.cxx:52
RooFitResult::Print
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFitResult.h:66
RooDataSet
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
rf312_multirangefit
Definition: rf312_multirangefit.py:1
RooRealVar
Definition: RooRealVar.h:35
RooFit::Save
RooCmdArg Save(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:187
RooProdPdf
Definition: RooProdPdf.h:33
RooArgSet
Definition: RooArgSet.h:28
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341