rf804_mcstudy_constr.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'VALIDATION AND MC STUDIES' RooFit tutorial macro #804
00004 // 
00005 // Using RooMCStudy on models with constrains
00006 //
00007 // 
00008 // 07/2008 - Wouter Verkerke 
00009 //
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #endif
00015 #include "RooRealVar.h"
00016 #include "RooDataSet.h"
00017 #include "RooGaussian.h"
00018 #include "RooPolynomial.h"
00019 #include "RooAddPdf.h"
00020 #include "RooProdPdf.h"
00021 #include "RooMCStudy.h"
00022 #include "RooPlot.h"
00023 #include "TCanvas.h"
00024 #include "TH1.h"
00025 using namespace RooFit ;
00026 
00027 
00028 class TestBasic804 : public RooFitTestUnit
00029 {
00030 public: 
00031   TestBasic804(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("MC Studies with aux. obs. constraints",refFile,writeRef,verbose) {} ;
00032 
00033   Double_t htol() { return 0.1 ; } // numerically very difficult test
00034 
00035   Bool_t testCode() {
00036 
00037   // C r e a t e   m o d e l   w i t h   p a r a m e t e r   c o n s t r a i n t
00038   // ---------------------------------------------------------------------------
00039 
00040   // Observable
00041   RooRealVar x("x","x",-10,10) ;
00042 
00043   // Signal component
00044   RooRealVar m("m","m",0,-10,10) ;
00045   RooRealVar s("s","s",2,0.1,10) ;
00046   RooGaussian g("g","g",x,m,s) ;
00047 
00048   // Background component
00049   RooPolynomial p("p","p",x) ;
00050 
00051   // Composite model
00052   RooRealVar f("f","f",0.4,0.,1.) ;
00053   RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ;
00054 
00055   // Construct constraint on parameter f
00056   RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.7),RooConst(0.1)) ;
00057 
00058   // Multiply constraint with p.d.f
00059   RooProdPdf sumc("sumc","sum with constraint",RooArgSet(sum,fconstraint)) ;
00060 
00061 
00062 
00063   // S e t u p   t o y   s t u d y   w i t h   m o d e l
00064   // ---------------------------------------------------
00065 
00066   // Perform toy study with internal constraint on f
00067   RooMCStudy mcs(sumc,x,Constrain(f),Silence(),Binned(),FitOptions(PrintLevel(-1))) ;
00068 
00069   // Run 50 toys of 2000 events.  
00070   // Before each toy is generated, a value for the f is sampled from the constraint pdf and 
00071   // that value is used for the generation of that toy.
00072   mcs.generateAndFit(50,2000) ;
00073 
00074   // Make plot of distribution of generated value of f parameter
00075   RooRealVar* f_gen = (RooRealVar*) mcs.fitParDataSet().get()->find("f_gen") ;
00076   TH1* h_f_gen = new TH1F("h_f_gen","",40,0,1) ;
00077   mcs.fitParDataSet().fillHistogram(h_f_gen,*f_gen) ;
00078 
00079   // Make plot of distribution of fitted value of f parameter
00080   RooPlot* frame1  = mcs.plotParam(f,Bins(40),Range(0.4,1)) ;
00081   frame1->SetTitle("Distribution of fitted f values") ;
00082 
00083   // Make plot of pull distribution on f
00084   RooPlot* frame2 = mcs.plotPull(f,Bins(40),Range(-3,3)) ;
00085   frame1->SetTitle("Distribution of f pull values") ;
00086 
00087   regTH(h_f_gen,"rf804_h_f_gen") ;
00088   regPlot(frame1,"rf804_plot1") ;
00089   regPlot(frame2,"rf804_plot2") ;
00090   
00091   return kTRUE ;
00092   }
00093 } ;
00094 

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