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