Logo ROOT  
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: RooMCStudy - Using the randomizer and profile likelihood add-on models
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooConstVar.h"
17#include "RooChebychev.h"
18#include "RooAddPdf.h"
19#include "RooMCStudy.h"
22#include "RooPlot.h"
23#include "TCanvas.h"
24#include "TAxis.h"
25#include "TH1.h"
26#include "TDirectory.h"
27
28using namespace RooFit;
29
30void rf803_mcstudy_addons2()
31{
32 // C r e a t e m o d e l
33 // -----------------------
34
35 // Simulation of signal and background of top quark decaying into
36 // 3 jets with background
37
38 // Observable
39 RooRealVar mjjj("mjjj", "m(3jet) (GeV)", 100, 85., 350.);
40
41 // Signal component (Gaussian)
42 RooRealVar mtop("mtop", "m(top)", 162);
43 RooRealVar wtop("wtop", "m(top) resolution", 15.2);
44 RooGaussian sig("sig", "top signal", mjjj, mtop, wtop);
45
46 // Background component (Chebychev)
47 RooRealVar c0("c0", "Chebychev coefficient 0", -0.846, -1., 1.);
48 RooRealVar c1("c1", "Chebychev coefficient 1", 0.112, -1., 1.);
49 RooRealVar c2("c2", "Chebychev coefficient 2", 0.076, -1., 1.);
50 RooChebychev bkg("bkg", "combinatorial background", mjjj, RooArgList(c0, c1, c2));
51
52 // Composite model
53 RooRealVar nsig("nsig", "number of signal events", 53, 0, 1e3);
54 RooRealVar nbkg("nbkg", "number of background events", 103, 0, 5e3);
55 RooAddPdf model("model", "model", RooArgList(sig, bkg), RooArgList(nsig, nbkg));
56
57 // C r e a t e m a n a g e r
58 // ---------------------------
59
60 // Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated
61 // with a Poisson fluctuation on Nobs (Extended())
62 RooMCStudy *mcs = new RooMCStudy(model, mjjj, Binned(), Silence(), Extended(kTRUE),
64
65 // C u s t o m i z e m a n a g e r
66 // ---------------------------------
67
68 // Add module that randomizes the summed value of nsig+nbkg
69 // sampling from a uniform distribution between 0 and 1000
70 //
71 // In general one can randomize a single parameter, or a
72 // sum of N parameters, using either a uniform or a Gaussian
73 // distribution. Multiple randomization can be executed
74 // by a single randomizer module
75
77 randModule.sampleSumUniform(RooArgSet(nsig, nbkg), 50, 500);
78 mcs->addModule(randModule);
79
80 // Add profile likelihood calculation of significance. Redo each
81 // fit while keeping parameter nsig fixed to zero. For each toy,
82 // the difference in -log(L) of both fits is stored, as well
83 // a simple significance interpretation of the delta(-logL)
84 // using Dnll = 0.5 sigma^2
85
86 RooDLLSignificanceMCSModule sigModule(nsig, 0);
87 mcs->addModule(sigModule);
88
89 // R u n m a n a g e r , m a k e p l o t s
90 // ---------------------------------------------
91
92 // Run 1000 experiments. This configuration will generate a fair number
93 // of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit
94 // at low statistics.
95 mcs->generateAndFit(500);
96
97 // Make some plots
98 TH1 *dll_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,dll_nullhypo_nsig", -40, -40);
99 TH1 *z_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,significance_nullhypo_nsig", -40, -40);
100 TH1 *errnsig_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,nsigerr", -40, -40);
101 TH1 *errnsig_vs_nsig = mcs->fitParDataSet().createHistogram("nsig,nsigerr", -40, -40);
102
103 // Draw plots on canvas
104 TCanvas *c = new TCanvas("rf803_mcstudy_addons2", "rf802_mcstudy_addons2", 800, 800);
105 c->Divide(2, 2);
106 c->cd(1);
107 gPad->SetLeftMargin(0.15);
108 dll_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
109 dll_vs_ngen->Draw("box");
110 c->cd(2);
111 gPad->SetLeftMargin(0.15);
112 z_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
113 z_vs_ngen->Draw("box");
114 c->cd(3);
115 gPad->SetLeftMargin(0.15);
116 errnsig_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
117 errnsig_vs_ngen->Draw("box");
118 c->cd(4);
119 gPad->SetLeftMargin(0.15);
120 errnsig_vs_nsig->GetYaxis()->SetTitleOffset(1.6);
121 errnsig_vs_nsig->Draw("box");
122
123 // Make RooMCStudy object available on command line after
124 // macro finishes
125 gDirectory->Add(mcs);
126}
#define c(i)
Definition: RSha256.hxx:101
const Bool_t kTRUE
Definition: RtypesCore.h:91
#define gDirectory
Definition: TDirectory.h:290
#define gPad
Definition: TVirtualPad.h:287
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:32
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that calculates the significance of a ...
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.
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
RooMCStudy is a helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies,...
Definition: RooMCStudy.h:32
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:981
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:660
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:445
RooRandomizeParamMCSModule is an add-on modules to RooMCStudy that allows you to randomize input gene...
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,...
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
The Canvas class.
Definition: TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
TAxis * GetYaxis()
Definition: TH1.h:321
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3073
RooCmdArg Binned(Bool_t flag=kTRUE)
RooCmdArg Silence(Bool_t flag=kTRUE)
RooCmdArg Extended(Bool_t flag=kTRUE)
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg FitOptions(const char *opts)
return c1
Definition: legend1.C:41
return c2
Definition: legend2.C:14
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...