rf406_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, November 28, 2022 at 11:30 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"
using namespace RooFit;

Construct two categories

Define a category with labels only

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

Define a category with explicitly numbered states

In [3]:
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 [4]:
RooRealVar x("x", "x", 0, 10);
RooPolynomial p("p", "p", x);
RooDataSet *data = p.generate(RooArgSet(x, b0flav, tagCat), 10000);
input_line_52:4:1: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration
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 [5]:
RooMappedCategory tcatType("tcatType", "tagCat type", tagCat, "Cut based");

Enter fully specified state mappings

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

Enter a wilcard expression mapping

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

Make a table of the mapped category state multiplicity in data

In [8]:
Roo1DTable *mtable = data->table(tcatType);
mtable->Print("v");
input_line_56:2:23: error: reference to 'data' is ambiguous
 Roo1DTable *mtable = data->table(tcatType);
                      ^
input_line_52: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 [9]:
RooSuperCategory b0Xtcat("b0Xtcat", "b0flav X tagCat", RooArgSet(b0flav, tagCat));

Make a table of the product category state multiplicity in data

In [10]:
Roo1DTable *stable = data->table(b0Xtcat);
stable->Print("v");
input_line_58:2:23: error: reference to 'data' is ambiguous
 Roo1DTable *stable = data->table(b0Xtcat);
                      ^
input_line_52: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 [11]:
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 [12]:
RooMultiCategory b0Xttype("b0Xttype", "b0flav X tagType", RooArgSet(b0flav, tcatType));

Make a table of the product category state multiplicity in data

In [13]:
Roo1DTable *xtable = data->table(b0Xttype);
xtable->Print("v");
input_line_61:2:23: error: reference to 'data' is ambiguous
 Roo1DTable *xtable = data->table(b0Xttype);
                      ^
input_line_52: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
    ^