ROOT   Reference Guide
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({t}, 10000)
38
39# Generate a (fake) prototype dataset for acceptance limit values
40tmp = ROOT.RooGaussian("gmin", "gmin", tmin, ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(0.5)).generate({tmin}, 5000)
41
42# Generate dataset with t values that observe (t>tmin)
43dacc = model.generate({t}, ProtoData=tmp)
44
45# Fit pdf to data in acceptance region
46# -----------------------------------------------------------------------
47
48r = model.fitTo(dacc, Save=True)
49
50# Plot fitted pdf on full and accepted data
51# ---------------------------------------------------------------------------------
52
53# Make plot frame, datasets and overlay model
54frame = t.frame(Title="Fit to data with per-event acceptance")
55dall.plotOn(frame, MarkerColor="r", LineColor="r")
56model.plotOn(frame)
57dacc.plotOn(frame)
58
59# Print fit results to demonstrate absence of bias
60r.Print("v")
61
62c = ROOT.TCanvas("rf314_paramranges", "rf314_paramranges", 600, 600)