Logo ROOT  
Reference Guide
No Matches
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Basic functionality: binding ROOT math functions as RooFit functions and pdfs
6/// \macro_image
7/// \macro_output
8/// \macro_code
10/// \date July 2008
11/// \author Wouter Verkerke
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "TCanvas.h"
17#include "TAxis.h"
18#include "RooPlot.h"
19#include "TMath.h"
20#include "TF1.h"
21#include "Math/DistFunc.h"
22#include "RooTFnBinding.h"
24using namespace RooFit;
26void rf105_funcbinding()
29 // B i n d T M a t h : : E r f C f u n c t i o n
30 // ---------------------------------------------------
32 // Bind one-dimensional TMath::Erf function as RooAbsReal function
33 RooRealVar x("x", "x", -3, 3);
34 RooAbsReal *errorFunc = bindFunction("erf", TMath::Erf, x);
36 // Print erf definition
37 errorFunc->Print();
39 // Plot erf on frame
40 RooPlot *frame1 = x.frame(Title("TMath::Erf bound as RooFit function"));
41 errorFunc->plotOn(frame1);
43 // B i n d R O O T : : M a t h : : b e t a _ p d f C f u n c t i o n
44 // -----------------------------------------------------------------------
46 // Bind pdf ROOT::Math::Beta with three variables as RooAbsPdf function
47 RooRealVar x2("x2", "x2", 0, 0.999);
48 RooRealVar a("a", "a", 5, 0, 10);
49 RooRealVar b("b", "b", 2, 0, 10);
52 // Perf beta definition
53 beta->Print();
55 // Generate some events and fit
56 RooDataSet *data = beta->generate(x2, 10000);
57 beta->fitTo(*data);
59 // Plot data and pdf on frame
60 RooPlot *frame2 = x2.frame(Title("ROOT::Math::Beta bound as RooFit pdf"));
61 data->plotOn(frame2);
62 beta->plotOn(frame2);
64 // B i n d R O O T T F 1 a s R o o F i t f u n c t i o n
65 // ---------------------------------------------------------------
67 // Create a ROOT TF1 function
68 TF1 *fa1 = new TF1("fa1", "sin(x)/x", 0, 10);
70 // Create an observable
71 RooRealVar x3("x3", "x3", 0.01, 20);
73 // Create binding of TF1 object to above observable
74 RooAbsReal *rfa1 = bindFunction(fa1, x3);
76 // Print rfa1 definition
77 rfa1->Print();
79 // Make plot frame in observable, plot TF1 binding function
80 RooPlot *frame3 = x3.frame(Title("TF1 bound as RooFit function"));
81 rfa1->plotOn(frame3);
83 TCanvas *c = new TCanvas("rf105_funcbinding", "rf105_funcbinding", 1200, 400);
84 c->Divide(3);
85 c->cd(1);
86 gPad->SetLeftMargin(0.15);
87 frame1->GetYaxis()->SetTitleOffset(1.6);
88 frame1->Draw();
89 c->cd(2);
90 gPad->SetLeftMargin(0.15);
91 frame2->GetYaxis()->SetTitleOffset(1.6);
92 frame2->Draw();
93 c->cd(3);
94 gPad->SetLeftMargin(0.15);
95 frame3->GetYaxis()->SetTitleOffset(1.6);
96 frame3->Draw();
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
static const double x2[5]
static const double x3[11]
#define gPad
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:340
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
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:33
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
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:213
double beta_pdf(double x, double a, double b)
Probability density function of the beta distribution.
double beta(double x, double y)
Calculates the beta function.
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
RooAbsPdf * bindPdf(const char *name, CFUNCD1D func, RooAbsReal &x)
RooAbsReal * bindFunction(const char *name, CFUNCD1D func, RooAbsReal &x)
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Definition TMath.cxx:184
const char * Title
Definition TXMLSetup.cxx:68