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 Tuesday, March 19, 2024 at 07:16 PM.
%%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;
Define a category with labels only
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
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
RooRealVar x("x", "x", 0, 10);
RooPolynomial p("p", "p", x);
std::unique_ptr<RooDataSet> data{p.generate({x, b0flav, tagCat}, 10000)};
input_line_50:4:1: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration std::unique_ptr<RooDataSet> data{p.generate({x, b0flav, tagCat}, 10000)}; ^
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
RooMappedCategory tcatType("tcatType", "tagCat type", tagCat, "Cut based");
Enter fully specified state mappings
tcatType.map("Lepton", "Cut based");
tcatType.map("Kaon", "Cut based");
Enter a wildcard expression mapping
tcatType.map("NetTagger*", "Neural Network");
Make a table of the mapped category state multiplicity in data
Roo1DTable *mtable = data->table(tcatType);
mtable->Print("v");
input_line_54:2:23: error: reference to 'data' is ambiguous Roo1DTable *mtable = data->table(tcatType); ^ input_line_50:4:29: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{p.generate({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 ^
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
RooSuperCategory b0Xtcat("b0Xtcat", "b0flav X tagCat", RooArgSet(b0flav, tagCat));
Make a table of the product category state multiplicity in data
Roo1DTable *stable = data->table(b0Xtcat);
stable->Print("v");
input_line_56:2:23: error: reference to 'data' is ambiguous Roo1DTable *stable = data->table(b0Xtcat); ^ input_line_50:4:29: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{p.generate({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
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
RooMultiCategory b0Xttype("b0Xttype", "b0flav X tagType", RooArgSet(b0flav, tcatType));
Make a table of the product category state multiplicity in data
Roo1DTable *xtable = data->table(b0Xttype);
xtable->Print("v");
input_line_59:2:23: error: reference to 'data' is ambiguous Roo1DTable *xtable = data->table(b0Xttype); ^ input_line_50:4:29: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{p.generate({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 ^