Logo ROOT  
Reference Guide
rf314_paramfitrange.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4##
5## Multidimensional models: working with parameterized ranges in a fit.
6## This an example of a fit with an acceptance that changes per-event
7##
8## `pdf = exp(-t/tau)` with `t[tmin,5]`
9##
10## where `t` and `tmin` are both observables in the dataset
11##
12## \macro_code
13##
14## \date February 2018
15## \authors Clemens Lange, Wouter Verkerke (C++ version)
16
17import ROOT
18
19
20# Define observables and decay pdf
21# ---------------------------------------------------------------
22
23# Declare observables
24t = ROOT.RooRealVar("t", "t", 0, 5)
25tmin = ROOT.RooRealVar("tmin", "tmin", 0, 0, 5)
26
27# Make parameterized range in t : [tmin,5]
28t.setRange(tmin, ROOT.RooFit.RooConst(t.getMax()))
29
30# Make pdf
31tau = ROOT.RooRealVar("tau", "tau", -1.54, -10, -0.1)
32model = ROOT.RooExponential("model", "model", t, tau)
33
34# Create input data
35# ------------------------------------
36
37# Generate complete dataset without acceptance cuts (for reference)
38dall = model.generate(ROOT.RooArgSet(t), 10000)
39
40# Generate a (fake) prototype dataset for acceptance limit values
41tmp = ROOT.RooGaussian("gmin", "gmin", tmin, ROOT.RooFit.RooConst(
42 0), ROOT.RooFit.RooConst(0.5)).generate(ROOT.RooArgSet(tmin), 5000)
43
44# Generate dataset with t values that observe (t>tmin)
45dacc = model.generate(ROOT.RooArgSet(t), ROOT.RooFit.ProtoData(tmp))
46
47# Fit pdf to data in acceptance region
48# -----------------------------------------------------------------------
49
50r = model.fitTo(dacc, ROOT.RooFit.Save())
51
52# Plot fitted pdf on full and accepted data
53# ---------------------------------------------------------------------------------
54
55# Make plot frame, datasets and overlay model
56frame = t.frame(ROOT.RooFit.Title("Fit to data with per-event acceptance"))
57dall.plotOn(frame, ROOT.RooFit.MarkerColor(ROOT.kRed),
58 ROOT.RooFit.LineColor(ROOT.kRed))
59model.plotOn(frame)
60dacc.plotOn(frame)
61
62# Print fit results to demonstrate absence of bias
63r.Print("v")
64
65c = ROOT.TCanvas("rf314_paramranges", "rf314_paramranges", 600, 600)
66ROOT.gPad.SetLeftMargin(0.15)
67frame.GetYaxis().SetTitleOffset(1.6)
68frame.Draw()
69
70c.SaveAs("rf314_paramranges.png")