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