Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf304_uncorrprod.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Multidimensional models: simple uncorrelated multi-dimensional pdfs
5///
6/// `pdf = gauss(x,mx,sx) * gauss(y,my,sy)`
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 "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 c o m p o n e n t p d f s i n x a n d y
28 // ----------------------------------------------------------------
29
30 // Create two pdfs gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables
31 RooRealVar x("x", "x", -5, 5);
32 RooRealVar y("y", "y", -5, 5);
33
34 RooRealVar meanx("mean1", "mean of gaussian x", 2);
35 RooRealVar meany("mean2", "mean of gaussian y", -2);
36 RooRealVar sigmax("sigmax", "width of gaussian x", 1);
37 RooRealVar sigmay("sigmay", "width of gaussian y", 5);
38
39 RooGaussian gaussx("gaussx", "gaussian PDF", x, meanx, sigmax);
40 RooGaussian gaussy("gaussy", "gaussian PDF", y, meany, sigmay);
41
42 // C o n s t r u c t u n c o r r e l a t e d p r o d u c t p d f
43 // -------------------------------------------------------------------
44
45 // Multiply gaussx and gaussy into a two-dimensional pdf gaussxy
46 RooProdPdf gaussxy("gaussxy", "gaussx*gaussy", RooArgList(gaussx, gaussy));
47
48 // S a m p l e p d f , p l o t p r o j e c t i o n o n x a n d y
49 // ---------------------------------------------------------------------------
50
51 // Generate 10000 events in x and y from gaussxy
52 std::unique_ptr<RooDataSet> data{gaussxy.generate({x, y}, 10000)};
53
54 // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)
55 RooPlot *xframe = x.frame(Title("X projection of gauss(x)*gauss(y)"));
56 data->plotOn(xframe);
57 gaussxy.plotOn(xframe);
58
59 // Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y)
60 RooPlot *yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)"));
61 data->plotOn(yframe);
62 gaussxy.plotOn(yframe);
63
64 // Make canvas and draw RooPlots
65 TCanvas *c = new TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400);
66 c->Divide(2);
67 c->cd(1);
68 gPad->SetLeftMargin(0.15);
69 xframe->GetYaxis()->SetTitleOffset(1.4);
70 xframe->Draw();
71 c->cd(2);
72 gPad->SetLeftMargin(0.15);
73 yframe->GetYaxis()->SetTitleOffset(1.4);
74 yframe->Draw();
75}
#define c(i)
Definition RSha256.hxx:101
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
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
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
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