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