Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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")
27b0flav.defineType("B0", -1)
28b0flav.defineType("B0bar", 1)
29b0flav.Print()
30
31# Construct a dummy dataset with random values of tagCat and b0flav
32x = ROOT.RooRealVar("x", "x", 0, 10)
33p = ROOT.RooPolynomial("p", "p", x)
34data = p.generate(ROOT.RooArgSet(x, b0flav, tagCat), 10000)
35
36# Create a cat -> cat mapping category
37# ---------------------------------------------------------------------
38
39# A RooMappedCategory is category.category mapping function based on string expression
40# The constructor takes an input category an a default state name to which unassigned
41# states are mapped
42tcatType = ROOT.RooMappedCategory(
43 "tcatType", "tagCat type", tagCat, "Cut based")
44
45# Enter fully specified state mappings
46tcatType.map("Lepton", "Cut based")
47tcatType.map("Kaon", "Cut based")
48
49# Enter a wilcard expression mapping
50tcatType.map("NetTagger*", "Neural Network")
51
52# Make a table of the mapped category state multiplicit in data
53mtable = data.table(tcatType)
54mtable.Print("v")
55
56# Create a cat X cat product category
57# ----------------------------------------------------------------------
58
59# A SUPER-category is 'product' of _lvalue_ categories. The state names of a super
60# category is a composite of the state labels of the input categories
61b0Xtcat = ROOT.RooSuperCategory(
62 "b0Xtcat", "b0flav X tagCat", ROOT.RooArgSet(b0flav, tagCat))
63
64# Make a table of the product category state multiplicity in data
65stable = data.table(b0Xtcat)
66stable.Print("v")
67
68# Since the super category is an lvalue, is explicitly possible
69b0Xtcat.setLabel("{B0bar;Lepton}")
70
71# A MULTI-category is a 'product' of any category (function). The state names of a super
72# category is a composite of the state labels of the input categories
73b0Xttype = ROOT.RooMultiCategory(
74 "b0Xttype", "b0flav X tagType", ROOT.RooArgSet(b0flav, tcatType))
75
76# Make a table of the product category state multiplicity in data
77xtable = data.table(b0Xttype)
78xtable.Print("v")