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