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