ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf109_chi2residpull.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #109
4 //
5 // Calculating chi^2 from histograms and curves in RooPlots,
6 // making histogram of residual and pull distributions
7 //
8 //
9 //
10 // 07/2008 - Wouter Verkerke
11 //
12 /////////////////////////////////////////////////////////////////////////
13 
14 #ifndef __CINT__
15 #include "RooGlobalFunc.h"
16 #endif
17 #include "RooRealVar.h"
18 #include "RooDataSet.h"
19 #include "RooGaussian.h"
20 #include "TCanvas.h"
21 #include "RooPlot.h"
22 #include "RooHist.h"
23 using namespace RooFit ;
24 
25 class TestBasic109 : public RooFitTestUnit
26 {
27 public:
28  TestBasic109(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Calculation of chi^2 and residuals in plots",refFile,writeRef,verbose) {} ;
29  Bool_t testCode() {
30 
31  // S e t u p m o d e l
32  // ---------------------
33 
34  // Create observables
35  RooRealVar x("x","x",-10,10) ;
36 
37  // Create Gaussian
38  RooRealVar sigma("sigma","sigma",3,0.1,10) ;
39  RooRealVar mean("mean","mean",0,-10,10) ;
40  RooGaussian gauss("gauss","gauss",x,RooConst(0),sigma) ;
41 
42  // Generate a sample of 1000 events with sigma=3
43  RooDataSet* data = gauss.generate(x,10000) ;
44 
45  // Change sigma to 3.15
46  sigma=3.15 ;
47 
48 
49  // P l o t d a t a a n d s l i g h t l y d i s t o r t e d m o d e l
50  // ---------------------------------------------------------------------------
51 
52  // Overlay projection of gauss with sigma=3.15 on data with sigma=3.0
53  RooPlot* frame1 = x.frame(Title("Data with distorted Gaussian pdf"),Bins(40)) ;
54  data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;
55  gauss.plotOn(frame1) ;
56 
57 
58  // C a l c u l a t e c h i ^ 2
59  // ------------------------------
60 
61  // Show the chi^2 of the curve w.r.t. the histogram
62  // If multiple curves or datasets live in the frame you can specify
63  // the name of the relevant curve and/or dataset in chiSquare()
64  regValue(frame1->chiSquare(),"rf109_chi2") ;
65 
66 
67  // S h o w r e s i d u a l a n d p u l l d i s t s
68  // -------------------------------------------------------
69 
70  // Construct a histogram with the residuals of the data w.r.t. the curve
71  RooHist* hresid = frame1->residHist() ;
72 
73  // Construct a histogram with the pulls of the data w.r.t the curve
74  RooHist* hpull = frame1->pullHist() ;
75 
76  // Create a new frame to draw the residual distribution and add the distribution to the frame
77  RooPlot* frame2 = x.frame(Title("Residual Distribution")) ;
78  frame2->addPlotable(hresid,"P") ;
79 
80  // Create a new frame to draw the pull distribution and add the distribution to the frame
81  RooPlot* frame3 = x.frame(Title("Pull Distribution")) ;
82  frame3->addPlotable(hpull,"P") ;
83 
84  regPlot(frame1,"rf109_plot1") ;
85  regPlot(frame2,"rf109_plot2") ;
86  regPlot(frame3,"rf109_plot3") ;
87 
88  delete data ;
89  //delete hresid ;
90  //delete hpull ;
91 
92  return kTRUE ;
93  }
94 } ;
RooHist * pullHist(const char *histname=0, const char *pdfname=0, bool useAverage=false) const
Definition: RooPlot.h:170
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", Bool_t invisible=kFALSE, Bool_t refreshNorm=kFALSE)
Add the specified plotable object to our plot.
Definition: RooPlot.cxx:447
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooCmdArg Title(const char *name)
A RooHist is a graphical representation of binned data based on the TGraphAsymmErrors class...
Definition: RooHist.h:26
Double_t x[n]
Definition: legend1.C:17
RooCmdArg DataError(Int_t)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
const Double_t sigma
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
Plot dataset on specified frame.
Definition: RooAbsData.cxx:626
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooHist * residHist(const char *histname=0, const char *pdfname=0, bool normalize=false, bool useAverage=kFALSE) const
Return a RooHist containing the residuals of histogram 'histname' with respect to curve 'curvename'...
Definition: RooPlot.cxx:998
bool verbose
Double_t chiSquare(int nFitParam=0) const
Definition: RooPlot.h:166
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooConstVar & RooConst(Double_t val)
RooCmdArg Bins(Int_t nbin)
const Bool_t kTRUE
Definition: Rtypes.h:91