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