ROOT   Reference Guide
Searching...
No Matches
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"
25using namespace RooFit;
26
27void 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)");
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);
77 frame->GetYaxis()->SetTitleOffset(1.4);
78 frame->Draw();
79 c->cd(2);
81 hh->GetZaxis()->SetTitleOffset(2.5);
82 hh->Draw("surf");
83}
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
@ kBlue
Definition Rtypes.h:66
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
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.
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
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
Definition RooAbsPdf.h:121
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:37
PDF for the numerical (FFT) convolution of two PDFs.
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:44
TAxis * GetYaxis() const
Definition RooPlot.cxx:1263
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:249
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:691
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:293
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:58
virtual void SetTitle(const char *title)
Definition TH1.cxx:6678
TAxis * GetZaxis()
Definition TH1.h:322
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg Bins(Int_t nbin)
RooCmdArg ConditionalObservables(const RooArgSet &set)
RooCmdArg Verbose(Bool_t flag=kTRUE)
RooCmdArg Binning(const RooAbsBinning &binning)
const Double_t sigma
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...