rf801_mcstudy.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'VALIDATION AND MC STUDIES' RooFit tutorial macro #801
00004 // 
00005 // A Toy Monte Carlo study that perform cycles of
00006 // event generation and fittting
00007 //
00008 // 
00009 /////////////////////////////////////////////////////////////////////////
00010 
00011 #ifndef __CINT__
00012 #include "RooGlobalFunc.h"
00013 #endif
00014 #include "RooRealVar.h"
00015 #include "RooDataSet.h"
00016 #include "RooGaussian.h"
00017 #include "RooChebychev.h"
00018 #include "RooAddPdf.h"
00019 #include "RooMCStudy.h"
00020 #include "RooPlot.h"
00021 #include "TCanvas.h"
00022 #include "TH2.h"
00023 #include "RooFitResult.h"
00024 #include "TStyle.h"
00025 #include "TDirectory.h"
00026 
00027 using namespace RooFit ;
00028 
00029 
00030 // Elementary operations on a gaussian PDF
00031 class TestBasic801 : public RooFitTestUnit
00032 {
00033 public: 
00034   TestBasic801(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Automated MC studies",refFile,writeRef,verbose) {} ;
00035   Bool_t testCode() {
00036 
00037   // C r e a t e   m o d e l
00038   // -----------------------
00039 
00040   // Declare observable x
00041   RooRealVar x("x","x",0,10) ;
00042   x.setBins(40) ;
00043 
00044   // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their paramaters
00045   RooRealVar mean("mean","mean of gaussians",5,0,10) ;
00046   RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
00047   RooRealVar sigma2("sigma2","width of gaussians",1) ;
00048 
00049   RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;  
00050   RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;  
00051   
00052   // Build Chebychev polynomial p.d.f.  
00053   RooRealVar a0("a0","a0",0.5,0.,1.) ;
00054   RooRealVar a1("a1","a1",-0.2,-1,1.) ;
00055   RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
00056 
00057   // Sum the signal components into a composite signal p.d.f.
00058   RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00059   RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00060 
00061   // Sum the composite signal and background 
00062   RooRealVar nbkg("nbkg","number of background events,",150,0,1000) ;
00063   RooRealVar nsig("nsig","number of signal events",150,0,1000) ;
00064   RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),RooArgList(nbkg,nsig)) ;
00065 
00066 
00067 
00068   // C r e a t e   m a n a g e r
00069   // ---------------------------
00070 
00071   // Instantiate RooMCStudy manager on model with x as observable and given choice of fit options
00072   //
00073   // The Silence() option kills all messages below the PROGRESS level, leaving only a single message
00074   // per sample executed, and any error message that occur during fitting
00075   //
00076   // The Extended() option has two effects: 
00077   //    1) The extended ML term is included in the likelihood and 
00078   //    2) A poisson fluctuation is introduced on the number of generated events 
00079   //
00080   // The FitOptions() given here are passed to the fitting stage of each toy experiment.
00081   // If Save() is specified, the fit result of each experiment is saved by the manager  
00082   //
00083   // A Binned() option is added in this example to bin the data between generation and fitting
00084   // to speed up the study at the expemse of some precision
00085 
00086   RooMCStudy* mcstudy = new RooMCStudy(model,x,Binned(kTRUE),Silence(),Extended(),
00087                                        FitOptions(Save(kTRUE),PrintEvalErrors(0))) ;
00088   
00089 
00090   // G e n e r a t e   a n d   f i t   e v e n t s
00091   // ---------------------------------------------
00092 
00093   // Generate and fit 100 samples of Poisson(nExpected) events
00094   mcstudy->generateAndFit(100) ;
00095 
00096 
00097 
00098   // E x p l o r e   r e s u l t s   o f   s t u d y 
00099   // ------------------------------------------------
00100 
00101   // Make plots of the distributions of mean, the error on mean and the pull of mean
00102   RooPlot* frame1 = mcstudy->plotParam(mean,Bins(40)) ;
00103   RooPlot* frame2 = mcstudy->plotError(mean,Bins(40)) ;
00104   RooPlot* frame3 = mcstudy->plotPull(mean,Bins(40),FitGauss(kTRUE)) ;
00105 
00106   // Plot distribution of minimized likelihood
00107   RooPlot* frame4 = mcstudy->plotNLL(Bins(40)) ;
00108 
00109   regPlot(frame1,"rf801_plot1") ;
00110   regPlot(frame2,"rf801_plot2") ;
00111   regPlot(frame3,"rf801_plot3") ;
00112   regPlot(frame4,"rf801_plot4") ;
00113 
00114   delete mcstudy ;
00115 
00116   return kTRUE ;
00117   }
00118 } ;

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