# Rf 4 0 6_Cattocatfuncs¶

Data and categories: demonstration of discrete-->discrete (invertible) functions

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, January 17, 2022 at 10:03 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooPolynomial.h"
#include "RooCategory.h"
#include "RooMappedCategory.h"
#include "RooMultiCategory.h"
#include "RooSuperCategory.h"
#include "Roo1DTable.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"

In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;


## Construct two categories¶

Define a category with labels only

In [3]:
RooCategory tagCat("tagCat", "Tagging category");
tagCat.defineType("Lepton");
tagCat.defineType("Kaon");
tagCat.defineType("NetTagger-1");
tagCat.defineType("NetTagger-2");
tagCat.Print();

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University

RooCategory::tagCat = Lepton(idx = 0)



Define a category with explicitly numbered states

In [4]:
RooCategory b0flav("b0flav", "B0 flavour eigenstate");
b0flav.defineType("B0", -1);
b0flav.defineType("B0bar", 1);
b0flav.Print();

RooCategory::b0flav = B0(idx = -1)



Construct a dummy dataset with random values of tagcat and b0flav

In [5]:
RooRealVar x("x", "x", 0, 10);
RooPolynomial p("p", "p", x);
RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);


## Create a cat->cat m apping category¶

A roomappedcategory is category->category mapping function based on string expression The constructor takes an input category an a default state name to which unassigned states are mapped

In [6]:
RooMappedCategory tcatType("tcatType", "tagCat type", tagCat, "Cut based");


Enter fully specified state mappings

In [7]:
tcatType.map("Lepton", "Cut based");
tcatType.map("Kaon", "Cut based");


Enter a wilcard expression mapping

In [8]:
tcatType.map("NetTagger*", "Neural Network");


Make a table of the mapped category state multiplicity in data

In [9]:
Roo1DTable *mtable = data->table(tcatType);
mtable->Print("v");

input_line_59:2:23: error: reference to 'data' is ambiguous
Roo1DTable *mtable = data->table(tcatType);
^
input_line_55:4:13: note: candidate found by name lookup is '__cling_N523::data'
RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


## Create a cat x cat product category¶

A super-category is 'product' of lvalue categories. the state names of a super category is a composite of the state labels of the input categories

In [10]:
RooSuperCategory b0Xtcat("b0Xtcat", "b0flav X tagCat", RooArgSet(b0flav, tagCat));


Make a table of the product category state multiplicity in data

In [11]:
Roo1DTable *stable = data->table(b0Xtcat);
stable->Print("v");

input_line_61:2:23: error: reference to 'data' is ambiguous
Roo1DTable *stable = data->table(b0Xtcat);
^
input_line_55:4:13: note: candidate found by name lookup is '__cling_N523::data'
RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


Since the super category is an lvalue, assignment is explicitly possible

In [12]:
b0Xtcat.setLabel("{B0bar;Lepton}");


A multi-category is a 'product' of any category (function). the state names of a super category is a composite of the state labels of the input categories

In [13]:
RooMultiCategory b0Xttype("b0Xttype", "b0flav X tagType", RooArgSet(b0flav, tcatType));


Make a table of the product category state multiplicity in data

In [14]:
Roo1DTable *xtable = data->table(b0Xttype);
xtable->Print("v");

input_line_64:2:23: error: reference to 'data' is ambiguous
Roo1DTable *xtable = data->table(b0Xttype);
^
input_line_55:4:13: note: candidate found by name lookup is '__cling_N523::data'
RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^