Logo ROOT  
Reference Guide
rf211_paramconv.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// Addition and convolution: working with a pdf with a convolution operator in terms of a parameter
5 ///
6 /// This tutorial requires FFT3 to be enabled.
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 ///
12 /// \date April 2009
13 /// \author Wouter Verkerke
14 
15 #include "RooRealVar.h"
16 #include "RooDataHist.h"
17 #include "RooGaussian.h"
18 #include "RooGenericPdf.h"
19 #include "RooFormulaVar.h"
20 #include "RooFFTConvPdf.h"
21 #include "RooPlot.h"
22 #include "TCanvas.h"
23 #include "TAxis.h"
24 #include "TH2.h"
25 using namespace RooFit;
26 
27 void rf211_paramconv()
28 {
29  // S e t u p c o m p o n e n t p d f s
30  // ---------------------------------------
31 
32  // Gaussian g(x ; mean,sigma)
33  RooRealVar x("x", "x", -10, 10);
34  RooRealVar mean("mean", "mean", -3, 3);
35  RooRealVar sigma("sigma", "sigma", 0.5, 0.1, 10);
36  RooGaussian modelx("gx", "gx", x, mean, sigma);
37 
38  // Block function in mean
39  RooRealVar a("a", "a", 2, 1, 10);
40  RooGenericPdf model_mean("model_mean", "abs(mean)<a", RooArgList(mean, a));
41 
42  // Convolution in mean parameter model = g(x,mean,sigma) (x) block(mean)
43  x.setBins(1000, "cache");
44  mean.setBins(50, "cache");
45  RooFFTConvPdf model("model", "model", mean, modelx, model_mean);
46 
47  // Configure convolution to construct a 2-D cache in (x,mean)
48  // rather than a 1-d cache in mean that needs to be recalculated
49  // for each value of x
50  model.setCacheObservables(x);
51  model.setBufferFraction(1.0);
52 
53  // Integrate model over mean projModel = Int model dmean
54  RooAbsPdf *projModel = model.createProjection(mean);
55 
56  // Generate 1000 toy events
57  RooDataHist *d = projModel->generateBinned(x, 1000);
58 
59  // Fit pdf to toy data
60  projModel->fitTo(*d, Verbose());
61 
62  // Plot data and fitted pdf
63  RooPlot *frame = x.frame(Bins(25));
64  d->plotOn(frame);
65  projModel->plotOn(frame);
66 
67  // Make 2d histogram of model(x;mean)
68  TH1 *hh = model.createHistogram("hh", x, Binning(50), YVar(mean, Binning(50)), ConditionalObservables(mean));
69  hh->SetTitle("histogram of model(x|mean)");
70  hh->SetLineColor(kBlue);
71 
72  // Draw frame on canvas
73  TCanvas *c = new TCanvas("rf211_paramconv", "rf211_paramconv", 800, 400);
74  c->Divide(2);
75  c->cd(1);
76  gPad->SetLeftMargin(0.15);
77  frame->GetYaxis()->SetTitleOffset(1.4);
78  frame->Draw();
79  c->cd(2);
80  gPad->SetLeftMargin(0.20);
81  hh->GetZaxis()->SetTitleOffset(2.5);
82  hh->Draw("surf");
83 }
RooFormulaVar.h
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
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition: RooGlobalFunc.cxx:177
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
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
RooGenericPdf.h
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:322
RooAbsPdf::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 RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition: RooAbsPdf.h:121
TH1::SetTitle
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6655
RooDataHist
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:39
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
a
auto * a
Definition: textangle.C:12
RooFit::Verbose
RooCmdArg Verbose(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:189
RooDataHist.h
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
RooRealVar.h
RooFit::ConditionalObservables
RooCmdArg ConditionalObservables(const RooArgSet &set)
Definition: RooGlobalFunc.cxx:199
TH2.h
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
RooFFTConvPdf
PDF for the numerical (FFT) convolution of two PDFs.
Definition: RooFFTConvPdf.h:25
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
RooGenericPdf
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
Definition: RooGenericPdf.h:25
kBlue
@ kBlue
Definition: Rtypes.h:66
RooFFTConvPdf.h
d
#define d(i)
Definition: RSha256.hxx:102
gPad
#define gPad
Definition: TVirtualPad.h:287
RooAbsPdf::generateBinned
virtual RooDataHist * generateBinned(const RooArgSet &whatVars, Double_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none()) const
As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,...
Definition: RooAbsPdf.h:107
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsPdf
Definition: RooAbsPdf.h:43
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
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050
RooAbsPdf::fitTo
virtual RooFitResult * fitTo(RooAbsData &data, 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())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1264