Loading [MathJax]/extensions/tex2jax.js
ROOT  6.06/09
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 } ;
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t x[n]
Definition: legend1.C:17
ROOT::R::TRInterface & r
Definition: Object.C:4
TMarker * m
Definition: textangle.C:8
bool verbose
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:980
const Bool_t kTRUE
Definition: Rtypes.h:91