Logo ROOT  
Reference Guide
rf101_basics.C File Reference

Detailed Description

View in nbviewer Open in SWAN Basic functionality: fitting, plotting, toy data generation on one-dimensional PDFs.

pdf = gauss(x,m,s)

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
**********
** 1 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 mean 1.00000e+00 2.00000e+00 -1.00000e+01 1.00000e+01
2 sigma 3.00000e+00 9.90000e-01 1.00000e-01 1.00000e+01
**********
** 3 **SET ERR 0.5
**********
**********
** 4 **SET PRINT 1
**********
**********
** 5 **SET STR 1
**********
NOW USING STRATEGY 1: TRY TO BALANCE SPEED AGAINST RELIABILITY
**********
** 6 **MIGRAD 1000 1
**********
FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION. STRATEGY 1. CONVERGENCE WHEN EDM .LT. 1.00e-03
FCN=25019.2 FROM MIGRAD STATUS=INITIATE 10 CALLS 11 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 mean 1.00000e+00 2.00000e+00 2.02430e-01 -1.99004e+02
2 sigma 3.00000e+00 9.90000e-01 2.22742e-01 1.98823e+02
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=25018.5 FROM MIGRAD STATUS=CONVERGED 32 CALLS 33 TOTAL
EDM=5.80039e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 mean 1.01746e+00 3.00149e-02 3.29345e-04 -8.41130e-02
2 sigma 2.97870e+00 2.19221e-02 5.32112e-04 1.48724e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
9.009e-04 1.839e-05
1.839e-05 4.806e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.02795 1.000 0.028
2 0.02795 0.028 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 1000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=25018.5 FROM HESSE STATUS=OK 10 CALLS 43 TOTAL
EDM=5.80381e-07 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 mean 1.01746e+00 3.00144e-02 6.58691e-05 1.01922e-01
2 sigma 2.97870e+00 2.19217e-02 2.12845e-05 -4.31732e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
9.009e-04 1.792e-05
1.792e-05 4.806e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.02723 1.000 0.027
2 0.02723 0.027 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
RooRealVar::mean = 1.01746 +/- 0.0300144 L(-10 - 10)
RooRealVar::sigma = 2.9787 +/- 0.0219217 L(0.1 - 10)
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "RooPlot.h"
#include "TAxis.h"
using namespace RooFit;
{
// S e t u p m o d e l
// ---------------------
// Declare variables x,mean,sigma with associated name, title, initial value and allowed range
RooRealVar x("x", "x", -10, 10);
RooRealVar mean("mean", "mean of gaussian", 1, -10, 10);
RooRealVar sigma("sigma", "width of gaussian", 1, 0.1, 10);
// Build gaussian p.d.f in terms of x,mean and sigma
RooGaussian gauss("gauss", "gaussian PDF", x, mean, sigma);
// Construct plot frame in 'x'
RooPlot *xframe = x.frame(Title("Gaussian p.d.f."));
// P l o t m o d e l a n d c h a n g e p a r a m e t e r v a l u e s
// ---------------------------------------------------------------------------
// Plot gauss in frame (i.e. in x)
gauss.plotOn(xframe);
// Change the value of sigma to 3
sigma.setVal(3);
// Plot gauss in frame (i.e. in x) and draw frame on canvas
gauss.plotOn(xframe, LineColor(kRed));
// G e n e r a t e e v e n t s
// -----------------------------
// Generate a dataset of 1000 events in x from gauss
RooDataSet *data = gauss.generate(x, 10000);
// Make a second plot frame in x and draw both the
// data and the p.d.f in the frame
RooPlot *xframe2 = x.frame(Title("Gaussian p.d.f. with data"));
data->plotOn(xframe2);
gauss.plotOn(xframe2);
// F i t m o d e l t o d a t a
// -----------------------------
// Fit pdf to data
gauss.fitTo(*data);
// Print values of mean and sigma (that now reflect fitted values and errors)
mean.Print();
sigma.Print();
// Draw all frames on a canvas
TCanvas *c = new TCanvas("rf101_basics", "rf101_basics", 800, 400);
c->Divide(2);
c->cd(1);
gPad->SetLeftMargin(0.15);
xframe->GetYaxis()->SetTitleOffset(1.6);
xframe->Draw();
c->cd(2);
gPad->SetLeftMargin(0.15);
xframe2->GetYaxis()->SetTitleOffset(1.6);
xframe2->Draw();
}
Author
07/2008 - Wouter Verkerke

Definition in file rf101_basics.C.

c
#define c(i)
Definition: RSha256.hxx:119
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
Definition: RooGaussian.h:25
TCanvas.h
RooDataSet.h
TGeant4Unit::gauss
static constexpr double gauss
Definition: TGeant4SystemOfUnits.h:269
RooFit
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:1256
RooPlot
Definition: RooPlot.h:44
RooRealVar.h
kRed
@ kRed
Definition: Rtypes.h:66
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
RooFit::LineColor
RooCmdArg LineColor(Color_t color)
Definition: RooGlobalFunc.cxx:56
TCanvas
Definition: TCanvas.h:23
TAxis.h
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
Definition: RooRealVar.h:35
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173
rf101_basics
Definition: rf101_basics.py:1