ROOT   Reference Guide
rf313_paramranges.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Multidimensional models: working with parametrized ranges to define non-rectangular
5 /// regions for fitting and integration
6 ///
7 /// \macro_image
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date July 2008
12 /// \author Wouter Verkerke
13
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooPolynomial.h"
19 #include "RooProdPdf.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "RooPlot.h"
23 using namespace RooFit;
24
25 void rf313_paramranges()
26 {
27
28  // C r e a t e 3 D p d f
29  // -------------------------
30
31  // Define observable (x,y,z)
32  RooRealVar x("x", "x", 0, 10);
33  RooRealVar y("y", "y", 0, 10);
34  RooRealVar z("z", "z", 0, 10);
35
36  // Define 3 dimensional pdf
37  RooRealVar z0("z0", "z0", -0.1, 1);
38  RooPolynomial px("px", "px", x, RooConst(0));
39  RooPolynomial py("py", "py", y, RooConst(0));
40  RooPolynomial pz("pz", "pz", z, z0);
41  RooProdPdf pxyz("pxyz", "pxyz", RooArgSet(px, py, pz));
42
43  // D e f i n e d n o n - r e c t a n g u l a r r e g i o n R i n ( x , y , z )
44  // -------------------------------------------------------------------------------------
45
46  //
47  // R = Z[0 - 0.1*Y^2] * Y[0.1*X - 0.9*X] * X[0 - 10]
48  //
49
50  // Construct range parametrized in "R" in y [ 0.1*x, 0.9*x ]
51  RooFormulaVar ylo("ylo", "0.1*x", x);
52  RooFormulaVar yhi("yhi", "0.9*x", x);
53  y.setRange("R", ylo, yhi);
54
55  // Construct parametrized ranged "R" in z [ 0, 0.1*y^2 ]
56  RooFormulaVar zlo("zlo", "0.0*y", y);
57  RooFormulaVar zhi("zhi", "0.1*y*y", y);
58  z.setRange("R", zlo, zhi);
59
60  // C a l c u l a t e i n t e g r a l o f n o r m a l i z e d p d f i n R
61  // ----------------------------------------------------------------------------------
62
63  // Create integral over normalized pdf model over x,y,z in "R" region
64  RooAbsReal *intPdf = pxyz.createIntegral(RooArgSet(x, y, z), RooArgSet(x, y, z), "R");
65
66  // Plot value of integral as function of pdf parameter z0
67  RooPlot *frame = z0.frame(Title("Integral of pxyz over x,y,z in region R"));
68  intPdf->plotOn(frame);
69
70  new TCanvas("rf313_paramranges", "rf313_paramranges", 600, 600);
72  frame->GetYaxis()->SetTitleOffset(1.6);
73  frame->Draw();
74
75  return;
76 }
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooAbsReal::createIntegral
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:574
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
TCanvas.h
RooDataSet.h
RooPolynomial.h
RooPlot::frame
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition: RooPlot.cxx:249
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooProdPdf.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPolynomial
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1258
RooPlot
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
rf313_paramranges
Definition: rf313_paramranges.py:1
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooConstVar.h
RooAbsReal::plotOn
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
Definition: RooAbsReal.cxx:1730
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TAxis.h
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooProdPdf
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:37
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:176
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:347