Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_code
9/// \macro_output
10///
11/// \date July 2008
12/// \author Wouter Verkerke
13
14#include "RooRealVar.h"
15#include "RooDataSet.h"
16#include "RooGaussian.h"
17#include "RooPolynomial.h"
18#include "RooProdPdf.h"
19#include "TCanvas.h"
20#include "TAxis.h"
21#include "RooPlot.h"
22using namespace RooFit;
23
25{
26
27 // C r e a t e 3 D p d f
28 // -------------------------
29
30 // Define observable (x,y,z)
31 RooRealVar x("x", "x", 0, 10);
32 RooRealVar y("y", "y", 0, 10);
33 RooRealVar z("z", "z", 0, 10);
34
35 // Define 3 dimensional pdf
36 RooRealVar z0("z0", "z0", -0.1, 1);
37 RooPolynomial px("px", "px", x, RooConst(0.0));
38 RooPolynomial py("py", "py", y, RooConst(0.0));
39 RooPolynomial pz("pz", "pz", z, z0);
40 RooProdPdf pxyz("pxyz", "pxyz", RooArgSet(px, py, pz));
41
42 // 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 )
43 // -------------------------------------------------------------------------------------
44
45 //
46 // R = Z[0 - 0.1*Y^2] * Y[0.1*X - 0.9*X] * X[0 - 10]
47 //
48
49 // Construct range parametrized in "R" in y [ 0.1*x, 0.9*x ]
50 RooFormulaVar ylo("ylo", "0.1*x", x);
51 RooFormulaVar yhi("yhi", "0.9*x", x);
52 y.setRange("R", ylo, yhi);
53
54 // Construct parametrized ranged "R" in z [ 0, 0.1*y^2 ]
55 RooFormulaVar zlo("zlo", "0.0*y", y);
56 RooFormulaVar zhi("zhi", "0.1*y*y", y);
57 z.setRange("R", zlo, zhi);
58
59 // 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
60 // ----------------------------------------------------------------------------------
61
62 // Create integral over normalized pdf model over x,y,z in "R" region
63 std::unique_ptr<RooAbsReal> intPdf{pxyz.createIntegral(RooArgSet(x, y, z), RooArgSet(x, y, z), "R")};
64
65 // Plot value of integral as function of pdf parameter z0
66 RooPlot *frame = z0.frame(Title("Integral of pxyz over x,y,z in region R"));
67 intPdf->plotOn(frame);
68
69 new TCanvas("rf313_paramranges", "rf313_paramranges", 600, 600);
70 gPad->SetLeftMargin(0.15);
71 frame->GetYaxis()->SetTitleOffset(1.6);
72 frame->Draw();
73
74 return;
75}
#define gPad
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:45
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:225
TAxis * GetYaxis() const
Definition RooPlot.cxx:1264
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:637
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
RooConstVar & RooConst(double val)
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...
Definition JSONIO.h:26
const char * Title
Definition TXMLSetup.cxx:68