Logo ROOT   6.10/09
Reference Guide
rf803_mcstudy_addons2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'VALIDATION AND MC STUDIES' RooFit tutorial macro #803
5 ///
6 /// RooMCStudy: Using the randomizer and profile likelihood add-on models
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooChebychev.h"
19 #include "RooAddPdf.h"
20 #include "RooMCStudy.h"
23 #include "RooPlot.h"
24 #include "TCanvas.h"
25 #include "TAxis.h"
26 #include "TH1.h"
27 #include "TDirectory.h"
28 
29 using namespace RooFit ;
30 
31 
32 void rf803_mcstudy_addons2()
33 {
34  // C r e a t e m o d e l
35  // -----------------------
36 
37  // Simulation of signal and background of top quark decaying into
38  // 3 jets with background
39 
40  // Observable
41  RooRealVar mjjj("mjjj","m(3jet) (GeV)",100,85.,350.) ;
42 
43  // Signal component (Gaussian)
44  RooRealVar mtop("mtop","m(top)",162) ;
45  RooRealVar wtop("wtop","m(top) resolution",15.2) ;
46  RooGaussian sig("sig","top signal",mjjj,mtop,wtop) ;
47 
48  // Background component (Chebychev)
49  RooRealVar c0("c0","Chebychev coefficient 0",-0.846,-1.,1.) ;
50  RooRealVar c1("c1","Chebychev coefficient 1", 0.112,-1.,1.) ;
51  RooRealVar c2("c2","Chebychev coefficient 2", 0.076,-1.,1.) ;
52  RooChebychev bkg("bkg","combinatorial background",mjjj,RooArgList(c0,c1,c2)) ;
53 
54  // Composite model
55  RooRealVar nsig("nsig","number of signal events",53,0,1e3) ;
56  RooRealVar nbkg("nbkg","number of background events",103,0,5e3) ;
57  RooAddPdf model("model","model",RooArgList(sig,bkg),RooArgList(nsig,nbkg)) ;
58 
59 
60 
61  // C r e a t e m a n a g e r
62  // ---------------------------
63 
64  // Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated
65  // with a Poisson fluctuation on Nobs (Extended())
66  RooMCStudy* mcs = new RooMCStudy(model,mjjj,Binned(),Silence(),Extended(kTRUE),
68 
69 
70 
71  // C u s t o m i z e m a n a g e r
72  // ---------------------------------
73 
74  // Add module that randomizes the summed value of nsig+nbkg
75  // sampling from a uniform distribution between 0 and 1000
76  //
77  // In general one can randomize a single parameter, or a
78  // sum of N parameters, using either a uniform or a Gaussian
79  // distribution. Multiple randomization can be executed
80  // by a single randomizer module
81 
82  RooRandomizeParamMCSModule randModule ;
83  randModule.sampleSumUniform(RooArgSet(nsig,nbkg),50,500) ;
84  mcs->addModule(randModule) ;
85 
86 
87  // Add profile likelihood calculation of significance. Redo each
88  // fit while keeping parameter nsig fixed to zero. For each toy,
89  // the difference in -log(L) of both fits is stored, as well
90  // a simple significance interpretation of the delta(-logL)
91  // using Dnll = 0.5 sigma^2
92 
93  RooDLLSignificanceMCSModule sigModule(nsig,0) ;
94  mcs->addModule(sigModule) ;
95 
96 
97 
98  // R u n m a n a g e r , m a k e p l o t s
99  // ---------------------------------------------
100 
101  // Run 1000 experiments. This configuration will generate a fair number
102  // of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit
103  // at low statistics.
104  mcs->generateAndFit(500) ;
105 
106  // Make some plots
107  TH1* dll_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,dll_nullhypo_nsig",-40,-40) ;
108  TH1* z_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,significance_nullhypo_nsig",-40,-40) ;
109  TH1* errnsig_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,nsigerr",-40,-40) ;
110  TH1* errnsig_vs_nsig = mcs->fitParDataSet().createHistogram("nsig,nsigerr",-40,-40) ;
111 
112 
113  // Draw plots on canvas
114  TCanvas* c = new TCanvas("rf803_mcstudy_addons2","rf802_mcstudy_addons2",800,800) ;
115  c->Divide(2,2) ;
116  c->cd(1) ; gPad->SetLeftMargin(0.15) ; dll_vs_ngen->GetYaxis()->SetTitleOffset(1.6) ; dll_vs_ngen->Draw("box") ;
117  c->cd(2) ; gPad->SetLeftMargin(0.15) ; z_vs_ngen->GetYaxis()->SetTitleOffset(1.6) ; z_vs_ngen->Draw("box") ;
118  c->cd(3) ; gPad->SetLeftMargin(0.15) ; errnsig_vs_ngen->GetYaxis()->SetTitleOffset(1.6) ; errnsig_vs_ngen->Draw("box") ;
119  c->cd(4) ; gPad->SetLeftMargin(0.15) ; errnsig_vs_nsig->GetYaxis()->SetTitleOffset(1.6) ; errnsig_vs_nsig->Draw("box") ;
120 
121 
122  // Make RooMCStudy object available on command line after
123  // macro finishes
124  gDirectory->Add(mcs) ;
125 
126 }
127 
128 
129 
130 
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:262
void sampleSumUniform(const RooArgSet &paramSet, Double_t lo, Double_t hi)
Request uniform smearing of sum of parameters in paramSet uniform smearing in range [lo...
RooMCStudy is a help class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies...
Definition: RooMCStudy.h:32
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooCmdArg Binned(Bool_t flag=kTRUE)
return c1
Definition: legend1.C:41
const RooDataSet & fitParDataSet()
Return a RooDataSet the resulting fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:956
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg Extended(Bool_t flag=kTRUE)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:438
Bool_t generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char *asciiFilePat=0)
Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
Definition: RooMCStudy.cxx:653
RooCmdArg Silence(Bool_t flag=kTRUE)
RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that calculates the significance of a ...
RooCmdArg FitOptions(const char *opts)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
RooRandomizeParamMCSModule is an add-on modules to RooMCStudy that allows you to randomize input gene...
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
TAxis * GetYaxis()
Definition: TH1.h:301
The Canvas class.
Definition: TCanvas.h:31
return c2
Definition: legend2.C:14
The TH1 histogram class.
Definition: TH1.h:56
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1135
#define gPad
Definition: TVirtualPad.h:284
#define gDirectory
Definition: TDirectory.h:211
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
const Bool_t kTRUE
Definition: RtypesCore.h:91