Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 ## \author Clemens Lange, Wouter Verkerke (C++ version)
11 
12 import ROOT
13 
14 
15 # Construct two categories
16 # ----------------------------------------------
17 
18 # Define a category with labels only
19 tagCat = ROOT.RooCategory("tagCat", "Tagging category")
20 tagCat.defineType("Lepton")
21 tagCat.defineType("Kaon")
22 tagCat.defineType("NetTagger-1")
23 tagCat.defineType("NetTagger-2")
24 tagCat.Print()
25 
26 # Define a category with explicitly numbered states
27 b0flav = ROOT.RooCategory("b0flav", "B0 flavour eigenstate")
28 b0flav.defineType("B0", -1)
29 b0flav.defineType("B0bar", 1)
30 b0flav.Print()
31 
32 # Construct a dummy dataset with random values of tagCat and b0flav
33 x = ROOT.RooRealVar("x", "x", 0, 10)
34 p = ROOT.RooPolynomial("p", "p", x)
35 data = 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
43 tcatType = ROOT.RooMappedCategory(
44  "tcatType", "tagCat type", tagCat, "Cut based")
45 
46 # Enter fully specified state mappings
47 tcatType.map("Lepton", "Cut based")
48 tcatType.map("Kaon", "Cut based")
49 
50 # Enter a wilcard expression mapping
51 tcatType.map("NetTagger*", "Neural Network")
52 
53 # Make a table of the mapped category state multiplicit in data
54 mtable = data.table(tcatType)
55 mtable.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
62 b0Xtcat = ROOT.RooSuperCategory(
63  "b0Xtcat", "b0flav X tagCat", ROOT.RooArgSet(b0flav, tagCat))
64 
65 # Make a table of the product category state multiplicity in data
66 stable = data.table(b0Xtcat)
67 stable.Print("v")
68 
69 # Since the super category is an lvalue, is explicitly possible
70 b0Xtcat.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
74 b0Xttype = ROOT.RooMultiCategory(
75  "b0Xttype", "b0flav X tagType", ROOT.RooArgSet(b0flav, tcatType))
76 
77 # Make a table of the product category state multiplicity in data
78 xtable = data.table(b0Xttype)
79 xtable.Print("v")