rf109_chi2residpull.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #109
00004 // 
00005 // Calculating chi^2 from histograms and curves in RooPlots, 
00006 // making histogram of residual and pull distributions
00007 //
00008 //
00009 //
00010 // 07/2008 - Wouter Verkerke 
00011 // 
00012 /////////////////////////////////////////////////////////////////////////
00013 
00014 #ifndef __CINT__
00015 #include "RooGlobalFunc.h"
00016 #endif
00017 #include "RooRealVar.h"
00018 #include "RooDataSet.h"
00019 #include "RooGaussian.h"
00020 #include "TCanvas.h"
00021 #include "RooPlot.h"
00022 #include "RooHist.h"
00023 using namespace RooFit ;
00024 
00025 class TestBasic109 : public RooFitTestUnit
00026 {
00027 public: 
00028   TestBasic109(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Calculation of chi^2 and residuals in plots",refFile,writeRef,verbose) {} ;
00029   Bool_t testCode() {
00030     
00031     // S e t u p   m o d e l 
00032     // ---------------------
00033     
00034     // Create observables
00035     RooRealVar x("x","x",-10,10) ;
00036     
00037     // Create Gaussian
00038     RooRealVar sigma("sigma","sigma",3,0.1,10) ;
00039     RooRealVar mean("mean","mean",0,-10,10) ;
00040     RooGaussian gauss("gauss","gauss",x,RooConst(0),sigma) ;
00041     
00042     // Generate a sample of 1000 events with sigma=3
00043     RooDataSet* data = gauss.generate(x,10000) ;
00044     
00045     // Change sigma to 3.15
00046     sigma=3.15 ;
00047     
00048     
00049     // 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
00050     // ---------------------------------------------------------------------------
00051     
00052     // Overlay projection of gauss with sigma=3.15 on data with sigma=3.0
00053     RooPlot* frame1 = x.frame(Title("Data with distorted Gaussian pdf"),Bins(40)) ;
00054     data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;
00055     gauss.plotOn(frame1) ;
00056     
00057     
00058     // C a l c u l a t e   c h i ^ 2 
00059     // ------------------------------
00060     
00061     // Show the chi^2 of the curve w.r.t. the histogram
00062     // If multiple curves or datasets live in the frame you can specify
00063     // the name of the relevant curve and/or dataset in chiSquare()
00064     regValue(frame1->chiSquare(),"rf109_chi2") ;
00065     
00066     
00067     // S h o w   r e s i d u a l   a n d   p u l l   d i s t s
00068     // -------------------------------------------------------
00069     
00070     // Construct a histogram with the residuals of the data w.r.t. the curve
00071     RooHist* hresid = frame1->residHist() ;
00072     
00073     // Construct a histogram with the pulls of the data w.r.t the curve
00074     RooHist* hpull = frame1->pullHist() ;
00075     
00076     // Create a new frame to draw the residual distribution and add the distribution to the frame
00077     RooPlot* frame2 = x.frame(Title("Residual Distribution")) ;
00078     frame2->addPlotable(hresid,"P") ;
00079     
00080     // Create a new frame to draw the pull distribution and add the distribution to the frame
00081     RooPlot* frame3 = x.frame(Title("Pull Distribution")) ;
00082     frame3->addPlotable(hpull,"P") ;
00083     
00084     regPlot(frame1,"rf109_plot1") ;
00085     regPlot(frame2,"rf109_plot2") ;
00086     regPlot(frame3,"rf109_plot3") ;
00087 
00088     delete data ;
00089     //delete hresid ;
00090     //delete hpull ;
00091     
00092     return kTRUE ;    
00093   }
00094 } ;

Generated on Tue Jul 5 15:07:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1