Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf305_condcorrprod.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Multidimensional models: multi-dimensional pdfs with conditional pdfs in product
5///
6/// `pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx)` with `f(y) = a0 + a1*y`
7///
8/// \macro_image
9/// \macro_code
10/// \macro_output
11///
12/// \date July 2008
13/// \author Wouter Verkerke
14
15#include "RooRealVar.h"
16#include "RooDataSet.h"
17#include "RooGaussian.h"
18#include "RooPolyVar.h"
19#include "RooProdPdf.h"
20#include "RooPlot.h"
21#include "TCanvas.h"
22#include "TAxis.h"
23#include "TH1.h"
24using namespace RooFit;
25
27{
28 // C r e a t e c o n d i t i o n a l p d f g x ( x | y )
29 // -----------------------------------------------------------
30
31 // Create observables
32 RooRealVar x("x", "x", -5, 5);
33 RooRealVar y("y", "y", -5, 5);
34
35 // Create function f(y) = a0 + a1*y
36 RooRealVar a0("a0", "a0", -0.5, -5, 5);
37 RooRealVar a1("a1", "a1", -0.5, -1, 1);
38 RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
39
40 // Create gaussx(x,f(y),sx)
41 RooRealVar sigmax("sigma", "width of gaussian", 0.5);
42 RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax);
43
44 // C r e a t e p d f g y ( y )
45 // -----------------------------------------------------------
46
47 // Create gaussy(y,0,5)
48 RooGaussian gaussy("gaussy", "Gaussian in y", y, 0.0, 3.0);
49
50 // C r e a t e p r o d u c t g x ( x | y ) * g y ( y )
51 // -------------------------------------------------------
52
53 // Create gaussx(x,sx|y) * gaussy(y)
54 RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x));
55
56 // S a m p l e , f i t a n d p l o t p r o d u c t p d f
57 // ---------------------------------------------------------------
58
59 // Generate 1000 events in x and y from model
60 std::unique_ptr<RooDataSet> data{model.generate({x, y}, 10000)};
61
62 // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
63 RooPlot *xframe = x.frame();
64 data->plotOn(xframe);
65 model.plotOn(xframe);
66
67 // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
68 RooPlot *yframe = y.frame();
69 data->plotOn(yframe);
70 model.plotOn(yframe);
71
72 // Make two-dimensional plot in x vs y
73 TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
74 hh_model->SetLineColor(kBlue);
75
76 // Make canvas and draw RooPlots
77 TCanvas *c = new TCanvas("rf305_condcorrprod", "rf05_condcorrprod", 1200, 400);
78 c->Divide(3);
79 c->cd(1);
80 gPad->SetLeftMargin(0.15);
81 xframe->GetYaxis()->SetTitleOffset(1.6);
82 xframe->Draw();
83 c->cd(2);
84 gPad->SetLeftMargin(0.15);
85 yframe->GetYaxis()->SetTitleOffset(1.6);
86 yframe->Draw();
87 c->cd(3);
88 gPad->SetLeftMargin(0.20);
89 hh_model->GetZaxis()->SetTitleOffset(2.5);
90 hh_model->Draw("surf");
91}
#define c(i)
Definition RSha256.hxx:101
double fy() const
@ kBlue
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
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:237
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
A RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficients.
Definition RooPolyVar.h:25
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
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TAxis * GetZaxis()
Definition TH1.h:326
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3062
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg={})
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)
RooCmdArg Binning(const RooAbsBinning &binning)
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