rf804_mcstudy_constr.C

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 "RooConstVar.h"
00019 #include "RooPolynomial.h"
00020 #include "RooAddPdf.h"
00021 #include "RooProdPdf.h"
00022 #include "RooMCStudy.h"
00023 #include "RooPlot.h"
00024 #include "TCanvas.h"
00025 #include "TAxis.h"
00026 #include "TH1.h"
00027 using namespace RooFit ;
00028 
00029 
00030 void rf804_mcstudy_constr()
00031 {
00032   // 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
00033   // ---------------------------------------------------------------------------
00034 
00035   // Observable
00036   RooRealVar x("x","x",-10,10) ;
00037 
00038   // Signal component
00039   RooRealVar m("m","m",0,-10,10) ;
00040   RooRealVar s("s","s",2,0.1,10) ;
00041   RooGaussian g("g","g",x,m,s) ;
00042 
00043   // Background component
00044   RooPolynomial p("p","p",x) ;
00045 
00046   // Composite model
00047   RooRealVar f("f","f",0.4,0.,1.) ;
00048   RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ;
00049 
00050   // Construct constraint on parameter f
00051   RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.7),RooConst(0.1)) ;
00052 
00053   // Multiply constraint with p.d.f
00054   RooProdPdf sumc("sumc","sum with constraint",RooArgSet(sum,fconstraint)) ;
00055 
00056 
00057 
00058   // S e t u p   t o y   s t u d y   w i t h   m o d e l
00059   // ---------------------------------------------------
00060 
00061   // Perform toy study with internal constraint on f
00062   RooMCStudy mcs(sumc,x,Constrain(f),Silence(),Binned(),FitOptions(PrintLevel(-1))) ;
00063 
00064   // Run 500 toys of 2000 events.  
00065   // Before each toy is generated, a value for the f is sampled from the constraint pdf and 
00066   // that value is used for the generation of that toy.
00067   mcs.generateAndFit(500,2000) ;
00068 
00069   // Make plot of distribution of generated value of f parameter
00070   TH1* h_f_gen = mcs.fitParDataSet().createHistogram("f_gen",-40) ;
00071 
00072   // Make plot of distribution of fitted value of f parameter
00073   RooPlot* frame1  = mcs.plotParam(f,Bins(40)) ;
00074   frame1->SetTitle("Distribution of fitted f values") ;
00075 
00076   // Make plot of pull distribution on f
00077   RooPlot* frame2 = mcs.plotPull(f,Bins(40),FitGauss()) ;
00078   frame1->SetTitle("Distribution of f pull values") ;
00079 
00080 
00081 
00082   TCanvas* c = new TCanvas("rf804_mcstudy_constr","rf804_mcstudy_constr",1200,400) ;
00083   c->Divide(3) ;
00084   c->cd(1) ; gPad->SetLeftMargin(0.15) ; h_f_gen->GetYaxis()->SetTitleOffset(1.4) ; h_f_gen->Draw() ;
00085   c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
00086   c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
00087 
00088 }
00089 

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