 ROOT   Reference Guide 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_output
10 /// \macro_code
11 ///
12 /// \date July 2008
13 /// \author Wouter Verkerke
14
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "RooConstVar.h"
19 #include "RooPolyVar.h"
20 #include "RooProdPdf.h"
21 #include "RooPlot.h"
22 #include "TCanvas.h"
23 #include "TAxis.h"
24 #include "TH1.h"
25 using namespace RooFit;
26
27 void rf305_condcorrprod()
28 {
29  // C r e a t e c o n d i t i o n a l p d f g x ( x | y )
30  // -----------------------------------------------------------
31
32  // Create observables
33  RooRealVar x("x", "x", -5, 5);
34  RooRealVar y("y", "y", -5, 5);
35
36  // Create function f(y) = a0 + a1*y
37  RooRealVar a0("a0", "a0", -0.5, -5, 5);
38  RooRealVar a1("a1", "a1", -0.5, -1, 1);
39  RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
40
41  // Create gaussx(x,f(y),sx)
42  RooRealVar sigmax("sigma", "width of gaussian", 0.5);
43  RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax);
44
45  // C r e a t e p d f g y ( y )
46  // -----------------------------------------------------------
47
48  // Create gaussy(y,0,5)
49  RooGaussian gaussy("gaussy", "Gaussian in y", y, RooConst(0), RooConst(3));
50
51  // C r e a t e p r o d u c t g x ( x | y ) * g y ( y )
52  // -------------------------------------------------------
53
54  // Create gaussx(x,sx|y) * gaussy(y)
55  RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x));
56
57  // 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
58  // ---------------------------------------------------------------
59
60  // Generate 1000 events in x and y from model
61  RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
62
63  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
64  RooPlot *xframe = x.frame();
65  data->plotOn(xframe);
66  model.plotOn(xframe);
67
68  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
69  RooPlot *yframe = y.frame();
70  data->plotOn(yframe);
71  model.plotOn(yframe);
72
73  // Make two-dimensional plot in x vs y
74  TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
75  hh_model->SetLineColor(kBlue);
76
77  // Make canvas and draw RooPlots
78  TCanvas *c = new TCanvas("rf305_condcorrprod", "rf05_condcorrprod", 1200, 400);
79  c->Divide(3);
80  c->cd(1);
82  xframe->GetYaxis()->SetTitleOffset(1.6);
83  xframe->Draw();
84  c->cd(2);
86  yframe->GetYaxis()->SetTitleOffset(1.6);
87  yframe->Draw();
88  c->cd(3);
90  hh_model->GetZaxis()->SetTitleOffset(2.5);
91  hh_model->Draw("surf");
92 }
c
#define c(i)
Definition: RSha256.hxx:101
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
TCanvas.h
RooFit::YVar
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Definition: RooGlobalFunc.cxx:246
RooFit::Binning
RooCmdArg Binning(const RooAbsBinning &binning)
Definition: RooGlobalFunc.cxx:83
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:322
RooDataSet.h
RooPolyVar.h
RooProdPdf.h
rf305_condcorrprod
Definition: rf305_condcorrprod.py:1
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooAbsData::plotOn
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), 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
Definition: RooAbsData.cxx:547
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
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooPolyVar
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooConstVar.h
RooFit::Conditional
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
Definition: RooGlobalFunc.cxx:231
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TAxis.h
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
kBlue
@ kBlue
Definition: Rtypes.h:66
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
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
TH1.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:347