Loading [MathJax]/extensions/tex2jax.js
ROOT
6.06/09
Reference Guide
ROOT Home Page
Main Page
Related Pages
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
roofit
roofitcore
test
rf602_chi2fit.cxx
Go to the documentation of this file.
1
//////////////////////////////////////////////////////////////////////////
2
//
3
// 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #602
4
//
5
// Setting up a binning chi^2 fit
6
//
7
//
8
//
9
// 07/2008 - Wouter Verkerke
10
//
11
/////////////////////////////////////////////////////////////////////////
12
13
#ifndef __CINT__
14
#include "
RooGlobalFunc.h
"
15
#endif
16
#include "
RooRealVar.h
"
17
#include "
RooDataSet.h
"
18
#include "
RooGaussian.h
"
19
#include "
RooChebychev.h
"
20
#include "
RooAddPdf.h
"
21
#include "
RooChi2Var.h
"
22
#include "
RooMinuit.h
"
23
#include "TCanvas.h"
24
#include "
RooPlot.h
"
25
using namespace
RooFit
;
26
27
28
class
TestBasic602 :
public
RooFitTestUnit
29
{
30
public
:
31
TestBasic602(
TFile
* refFile,
Bool_t
writeRef,
Int_t
verbose
) : RooFitTestUnit(
"Chi2 minimization"
,refFile,writeRef,verbose) {} ;
32
Bool_t
testCode() {
33
34
// S e t u p m o d e l
35
// ---------------------
36
37
// Declare observable x
38
RooRealVar
x
(
"x"
,
"x"
,0,10) ;
39
40
// Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
41
RooRealVar
mean(
"mean"
,
"mean of gaussians"
,5) ;
42
RooRealVar
sigma1(
"sigma1"
,
"width of gaussians"
,0.5) ;
43
RooRealVar
sigma2(
"sigma2"
,
"width of gaussians"
,1) ;
44
45
RooGaussian
sig1(
"sig1"
,
"Signal component 1"
,
x
,mean,sigma1) ;
46
RooGaussian
sig2(
"sig2"
,
"Signal component 2"
,
x
,mean,sigma2) ;
47
48
// Build Chebychev polynomial p.d.f.
49
RooRealVar
a0(
"a0"
,
"a0"
,0.5,0.,1.) ;
50
RooRealVar
a1(
"a1"
,
"a1"
,-0.2,0.,1.) ;
51
RooChebychev
bkg(
"bkg"
,
"Background"
,
x
,
RooArgSet
(a0,a1)) ;
52
53
// Sum the signal components into a composite signal p.d.f.
54
RooRealVar
sig1frac(
"sig1frac"
,
"fraction of component 1 in signal"
,0.8,0.,1.) ;
55
RooAddPdf
sig(
"sig"
,
"Signal"
,
RooArgList
(sig1,sig2),sig1frac) ;
56
57
// Sum the composite signal and background
58
RooRealVar
bkgfrac(
"bkgfrac"
,
"fraction of background"
,0.5,0.,1.) ;
59
RooAddPdf
model(
"model"
,
"g1+g2+a"
,
RooArgList
(bkg,sig),bkgfrac) ;
60
61
62
// C r e a t e b i n n e d d a t a s e t
63
// -----------------------------------------
64
65
RooDataSet
* d = model.generate(
x
,10000) ;
66
RooDataHist
* dh = d->
binnedClone
() ;
67
68
69
// Construct a chi^2 of the data and the model,
70
// which is the input probability density scaled
71
// by the number of events in the dataset
72
RooChi2Var
chi2(
"chi2"
,
"chi2"
,model,*dh) ;
73
74
// Use RooMinuit interface to minimize chi^2
75
RooMinuit
m
(chi2) ;
76
m
.migrad() ;
77
m
.hesse() ;
78
79
RooFitResult
*
r
=
m
.save() ;
80
81
regResult(r,
"rf602_r"
) ;
82
83
delete
d ;
84
delete
dh ;
85
86
return
kTRUE
;
87
}
88
} ;
RooGlobalFunc.h
RooChi2Var.h
RooAddPdf
Definition:
RooAddPdf.h:29
RooArgSet
Definition:
RooArgSet.h:26
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition:
TFile.h:45
RooRealVar.h
RooFitResult
Definition:
RooFitResult.h:41
Int_t
int Int_t
Definition:
RtypesCore.h:41
Bool_t
bool Bool_t
Definition:
RtypesCore.h:59
RooGaussian.h
RooDataHist
Definition:
RooDataHist.h:40
x
Double_t x[n]
Definition:
legend1.C:17
RooFit
Definition:
RooCFunction1Binding.h:26
RooGaussian
Definition:
RooGaussian.h:25
RooChi2Var
Definition:
RooChi2Var.h:25
RooRealVar
Definition:
RooRealVar.h:37
r
ROOT::R::TRInterface & r
Definition:
Object.C:4
m
TMarker * m
Definition:
textangle.C:8
verbose
bool verbose
Definition:
binarySearchTime.cxx:27
RooAddPdf.h
RooPlot.h
RooDataSet
Definition:
RooDataSet.h:29
RooDataSet::binnedClone
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition:
RooDataSet.cxx:980
RooMinuit.h
RooDataSet.h
RooChebychev.h
RooArgList
Definition:
RooArgList.h:21
RooChebychev
Definition:
RooChebychev.h:25
kTRUE
const Bool_t kTRUE
Definition:
Rtypes.h:91
RooMinuit
Definition:
RooMinuit.h:39