Logo ROOT   6.16/01
Reference Guide
rf406_cattocatfuncs.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook -nodraw
4##
5## 'DATA AND CATEGORIES' RooFit tutorial macro #406
6##
7## Demonstration of discrete-.discrete (invertable) functions
8##
9## \macro_code
10##
11## \date February 2018
12## \author Clemens Lange
13## \author Wouter Verkerke (C version)
14
15
16import ROOT
17
18
19# Construct two categories
20# ----------------------------------------------
21
22# Define a category with labels only
23tagCat = ROOT.RooCategory("tagCat", "Tagging category")
24tagCat.defineType("Lepton")
25tagCat.defineType("Kaon")
26tagCat.defineType("NetTagger-1")
27tagCat.defineType("NetTagger-2")
28tagCat.Print()
29
30# Define a category with explicitly numbered states
31b0flav = ROOT.RooCategory("b0flav", "B0 flavour eigenstate")
32b0flav.defineType("B0", -1)
33b0flav.defineType("B0bar", 1)
34b0flav.Print()
35
36# Construct a dummy dataset with random values of tagCat and b0flav
37x = ROOT.RooRealVar("x", "x", 0, 10)
38p = ROOT.RooPolynomial("p", "p", x)
39data = p.generate(ROOT.RooArgSet(x, b0flav, tagCat), 10000)
40
41# Create a cat -> cat mapping category
42# ---------------------------------------------------------------------
43
44# A RooMappedCategory is category.category mapping function based on string expression
45# The constructor takes an input category an a default state name to which unassigned
46# states are mapped
47tcatType = ROOT.RooMappedCategory(
48 "tcatType", "tagCat type", tagCat, "Cut based")
49
50# Enter fully specified state mappings
51tcatType.map("Lepton", "Cut based")
52tcatType.map("Kaon", "Cut based")
53
54# Enter a wilcard expression mapping
55tcatType.map("NetTagger*", "Neural Network")
56
57# Make a table of the mapped category state multiplicit in data
58mtable = data.table(tcatType)
59mtable.Print("v")
60
61# Create a cat X cat product category
62# ----------------------------------------------------------------------
63
64# A SUPER-category is 'product' of _lvalue_ categories. The state names of a super
65# category is a composite of the state labels of the input categories
66b0Xtcat = ROOT.RooSuperCategory(
67 "b0Xtcat", "b0flav X tagCat", ROOT.RooArgSet(b0flav, tagCat))
68
69# Make a table of the product category state multiplicity in data
70stable = data.table(b0Xtcat)
71stable.Print("v")
72
73# Since the super category is an lvalue, is explicitly possible
74b0Xtcat.setLabel("{B0bar;Lepton}")
75
76# A MULTI-category is a 'product' of any category (function). The state names of a super
77# category is a composite of the state labels of the input categories
78b0Xttype = ROOT.RooMultiCategory(
79 "b0Xttype", "b0flav X tagType", ROOT.RooArgSet(b0flav, tcatType))
80
81# Make a table of the product category state multiplicity in data
82xtable = data.table(b0Xttype)
83xtable.Print("v")