Logo ROOT  
Reference Guide
rf803_mcstudy_addons2.py
Go to the documentation of this file.
1## \ingroup tutorial_roofit
2## \notebook
3##
4## 'VALIDATION AND MC STUDIES' RooFit tutorial macro #803
5##
6## RooMCStudy: Using the randomizer and profile likelihood add-on models
7##
8## \macro_code
9##
10## \date February 2018
11## \author Clemens Lange
12
13
14import ROOT
15
16
17# Create model
18# -----------------------
19
20# Simulation of signal and background of top quark decaying into
21# 3 jets with background
22
23# Observable
24mjjj = ROOT.RooRealVar("mjjj", "m(3jet) (GeV)", 100, 85.0, 350.0)
25
26# Signal component (Gaussian)
27mtop = ROOT.RooRealVar("mtop", "m(top)", 162)
28wtop = ROOT.RooRealVar("wtop", "m(top) resolution", 15.2)
29sig = ROOT.RooGaussian("sig", "top signal", mjjj, mtop, wtop)
30
31# Background component (Chebychev)
32c0 = ROOT.RooRealVar("c0", "Chebychev coefficient 0", -0.846, -1.0, 1.0)
33c1 = ROOT.RooRealVar("c1", "Chebychev coefficient 1", 0.112, -1.0, 1.0)
34c2 = ROOT.RooRealVar("c2", "Chebychev coefficient 2", 0.076, -1.0, 1.0)
35bkg = ROOT.RooChebychev("bkg", "combinatorial background", mjjj, [c0, c1, c2])
36
37# Composite model
38nsig = ROOT.RooRealVar("nsig", "number of signal events", 53, 0, 1e3)
39nbkg = ROOT.RooRealVar("nbkg", "number of background events", 103, 0, 5e3)
40model = ROOT.RooAddPdf("model", "model", [sig, bkg], [nsig, nbkg])
41
42# Create manager
43# ---------------------------
44
45# Configure manager to perform binned extended likelihood fits (Binned(), ROOT.RooFit.Extended()) on data generated
46# with a Poisson fluctuation on Nobs (Extended())
47mcs = ROOT.RooMCStudy(
48 model,
49 {mjjj},
50 ROOT.RooFit.Binned(),
51 ROOT.RooFit.Silence(),
52 ROOT.RooFit.Extended(ROOT.kTRUE),
53 ROOT.RooFit.FitOptions(ROOT.RooFit.Extended(ROOT.kTRUE), ROOT.RooFit.PrintEvalErrors(-1)),
54)
55
56# Customize manager
57# ---------------------------------
58
59# Add module that randomizes the summed value of nsig+nbkg
60# sampling from a uniform distribution between 0 and 1000
61#
62# In general one can randomize a single parameter, a
63# sum of N parameters, either a uniform or a Gaussian
64# distribution. Multiple randomization can be executed
65# by a single randomizer module
66
67randModule = ROOT.RooRandomizeParamMCSModule()
68randModule.sampleSumUniform({nsig, nbkg}, 50, 500)
69mcs.addModule(randModule)
70
71# Add profile likelihood calculation of significance. Redo each
72# fit while keeping parameter nsig fixed to zero. For each toy,
73# the difference in -log(L) of both fits is stored, well
74# a simple significance interpretation of the delta(-logL)
75# Dnll = 0.5 sigma^2
76
77sigModule = ROOT.RooDLLSignificanceMCSModule(nsig, 0)
78mcs.addModule(sigModule)
79
80# Run manager, make plots
81# ---------------------------------------------
82
83# Run 1000 experiments. ROOT.This configuration will generate a fair number
84# of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit
85# at low statistics.
86mcs.generateAndFit(500)
87
88# Make some plots
89dll_vs_ngen = ROOT.RooAbsData.createHistogram(mcs.fitParDataSet(), "ngen,dll_nullhypo_nsig", -40, -40)
90z_vs_ngen = ROOT.RooAbsData.createHistogram(mcs.fitParDataSet(), "ngen,significance_nullhypo_nsig", -40, -40)
91errnsig_vs_ngen = ROOT.RooAbsData.createHistogram(mcs.fitParDataSet(), "ngen,nsigerr", -40, -40)
92errnsig_vs_nsig = ROOT.RooAbsData.createHistogram(mcs.fitParDataSet(), "nsig,nsigerr", -40, -40)
93
94# Draw plots on canvas
95c = ROOT.TCanvas("rf803_mcstudy_addons2", "rf802_mcstudy_addons2", 800, 800)
96c.Divide(2, 2)
97c.cd(1)
98ROOT.gPad.SetLeftMargin(0.15)
99dll_vs_ngen.GetYaxis().SetTitleOffset(1.6)
100dll_vs_ngen.Draw("box")
101c.cd(2)
102ROOT.gPad.SetLeftMargin(0.15)
103z_vs_ngen.GetYaxis().SetTitleOffset(1.6)
104z_vs_ngen.Draw("box")
105c.cd(3)
106ROOT.gPad.SetLeftMargin(0.15)
107errnsig_vs_ngen.GetYaxis().SetTitleOffset(1.6)
108errnsig_vs_ngen.Draw("box")
109c.cd(4)
110ROOT.gPad.SetLeftMargin(0.15)
111errnsig_vs_nsig.GetYaxis().SetTitleOffset(1.6)
112errnsig_vs_nsig.Draw("box")
113
114c.SaveAs("rf803_mcstudy_addons2.png")
115
116# Make ROOT.RooMCStudy object available on command line after
117# macro finishes
118ROOT.gDirectory.Add(mcs)