{ "cells": [ { "cell_type": "markdown", "id": "ce4e2f55", "metadata": {}, "source": [ "# rf406_cattocatfuncs\n", "Data and categories: demonstration of discrete-->discrete (invertible) functions\n", "\n", "\n", "\n", "\n", "**Author:** Wouter Verkerke \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:31 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "b62742c8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:50.089619Z", "iopub.status.busy": "2026-05-19T20:31:50.089494Z", "iopub.status.idle": "2026-05-19T20:31:50.103816Z", "shell.execute_reply": "2026-05-19T20:31:50.103433Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooPolynomial.h\"\n", "#include \"RooCategory.h\"\n", "#include \"RooMappedCategory.h\"\n", "#include \"RooMultiCategory.h\"\n", "#include \"RooSuperCategory.h\"\n", "#include \"Roo1DTable.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "b3d57c5e", "metadata": {}, "source": [ "Construct two categories\n", "----------------------------------------------" ] }, { "cell_type": "markdown", "id": "63fc8e49", "metadata": {}, "source": [ "Define a category with labels only" ] }, { "cell_type": "code", "execution_count": 2, "id": "8f75fdae", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:50.106236Z", "iopub.status.busy": "2026-05-19T20:31:50.106122Z", "iopub.status.idle": "2026-05-19T20:31:50.451815Z", "shell.execute_reply": "2026-05-19T20:31:50.451263Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RooCategory::tagCat = Lepton(idx = 0)\n", "\n" ] } ], "source": [ "RooCategory tagCat(\"tagCat\", \"Tagging category\");\n", "tagCat.defineType(\"Lepton\");\n", "tagCat.defineType(\"Kaon\");\n", "tagCat.defineType(\"NetTagger-1\");\n", "tagCat.defineType(\"NetTagger-2\");\n", "tagCat.Print();" ] }, { "cell_type": "markdown", "id": "a5db8316", "metadata": {}, "source": [ "Define a category with explicitly numbered states" ] }, { "cell_type": "code", "execution_count": 3, "id": "5594a7b8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:50.453186Z", "iopub.status.busy": "2026-05-19T20:31:50.453069Z", "iopub.status.idle": "2026-05-19T20:31:50.661560Z", "shell.execute_reply": "2026-05-19T20:31:50.660956Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RooCategory::b0flav = B0(idx = -1)\n", "\n" ] } ], "source": [ "RooCategory b0flav(\"b0flav\", \"B0 flavour eigenstate\");\n", "b0flav.defineType(\"B0\", -1);\n", "b0flav.defineType(\"B0bar\", 1);\n", "b0flav.Print();" ] }, { "cell_type": "markdown", "id": "7e5e5aa4", "metadata": {}, "source": [ "Construct a dummy dataset with random values of tagCat and b0flav" ] }, { "cell_type": "code", "execution_count": 4, "id": "d9bb95a9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:50.662993Z", "iopub.status.busy": "2026-05-19T20:31:50.662861Z", "iopub.status.idle": "2026-05-19T20:31:50.871510Z", "shell.execute_reply": "2026-05-19T20:31:50.870921Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_51:4:1: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n", "std::unique_ptr data{p.generate({x, b0flav, tagCat}, 10000)};\n", "^\n" ] } ], "source": [ "RooRealVar x(\"x\", \"x\", 0, 10);\n", "RooPolynomial p(\"p\", \"p\", x);\n", "std::unique_ptr data{p.generate({x, b0flav, tagCat}, 10000)};" ] }, { "cell_type": "markdown", "id": "32abebc4", "metadata": {}, "source": [ "Create a cat->cat m apping category\n", "---------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "c500101a", "metadata": {}, "source": [ "A RooMappedCategory is category->category mapping function based on string expression\n", "The constructor takes an input category an a default state name to which unassigned\n", "states are mapped" ] }, { "cell_type": "code", "execution_count": 5, "id": "44438f61", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:50.872985Z", "iopub.status.busy": "2026-05-19T20:31:50.872867Z", "iopub.status.idle": "2026-05-19T20:31:51.078310Z", "shell.execute_reply": "2026-05-19T20:31:51.077675Z" } }, "outputs": [], "source": [ "RooMappedCategory tcatType(\"tcatType\", \"tagCat type\", tagCat, \"Cut based\");" ] }, { "cell_type": "markdown", "id": "918f695a", "metadata": {}, "source": [ "Enter fully specified state mappings" ] }, { "cell_type": "code", "execution_count": 6, "id": "3cd15556", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:51.079987Z", "iopub.status.busy": "2026-05-19T20:31:51.079872Z", "iopub.status.idle": "2026-05-19T20:31:51.285680Z", "shell.execute_reply": "2026-05-19T20:31:51.284985Z" } }, "outputs": [], "source": [ "tcatType.map(\"Lepton\", \"Cut based\");\n", "tcatType.map(\"Kaon\", \"Cut based\");" ] }, { "cell_type": "markdown", "id": "2c5a9f5a", "metadata": {}, "source": [ "Enter a wildcard expression mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "1ef6d05d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:51.287199Z", "iopub.status.busy": "2026-05-19T20:31:51.287086Z", "iopub.status.idle": "2026-05-19T20:31:51.492961Z", "shell.execute_reply": "2026-05-19T20:31:51.492042Z" } }, "outputs": [], "source": [ "tcatType.map(\"NetTagger*\", \"Neural Network\");" ] }, { "cell_type": "markdown", "id": "a6609604", "metadata": {}, "source": [ "Make a table of the mapped category state multiplicity in data" ] }, { "cell_type": "code", "execution_count": 8, "id": "babf50fc", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:51.494451Z", "iopub.status.busy": "2026-05-19T20:31:51.494336Z", "iopub.status.idle": "2026-05-19T20:31:51.700572Z", "shell.execute_reply": "2026-05-19T20:31:51.700067Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_55:2:23: error: reference to 'data' is ambiguous\n", " Roo1DTable *mtable = data->table(tcatType);\n", " ^\n", "input_line_51:4:29: note: candidate found by name lookup is 'data'\n", "std::unique_ptr data{p.generate({x, b0flav, tagCat}, 10000)};\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "Roo1DTable *mtable = data->table(tcatType);\n", "mtable->Print(\"v\");" ] }, { "cell_type": "markdown", "id": "450a75f4", "metadata": {}, "source": [ "Create a cat X cat product category\n", "----------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "2496ee3d", "metadata": {}, "source": [ "A SUPER-category is 'product' of _lvalue_ categories. The state names of a super\n", "category is a composite of the state labels of the input categories" ] }, { "cell_type": "code", "execution_count": 9, "id": "8d9d83ff", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:51.701959Z", "iopub.status.busy": "2026-05-19T20:31:51.701845Z", "iopub.status.idle": "2026-05-19T20:31:51.910083Z", "shell.execute_reply": "2026-05-19T20:31:51.909490Z" } }, "outputs": [], "source": [ "RooSuperCategory b0Xtcat(\"b0Xtcat\", \"b0flav X tagCat\", RooArgSet(b0flav, tagCat));" ] }, { "cell_type": "markdown", "id": "1f3b1812", "metadata": {}, "source": [ "Make a table of the product category state multiplicity in data" ] }, { "cell_type": "code", "execution_count": 10, "id": "32ffc5a3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:51.911780Z", "iopub.status.busy": "2026-05-19T20:31:51.911666Z", "iopub.status.idle": "2026-05-19T20:31:52.139527Z", "shell.execute_reply": "2026-05-19T20:31:52.139069Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_57:2:23: error: reference to 'data' is ambiguous\n", " Roo1DTable *stable = data->table(b0Xtcat);\n", " ^\n", "input_line_51:4:29: note: candidate found by name lookup is 'data'\n", "std::unique_ptr data{p.generate({x, b0flav, tagCat}, 10000)};\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "Roo1DTable *stable = data->table(b0Xtcat);\n", "stable->Print(\"v\");" ] }, { "cell_type": "markdown", "id": "fb7d42c7", "metadata": {}, "source": [ "Since the super category is an lvalue, assignment is explicitly possible" ] }, { "cell_type": "code", "execution_count": 11, "id": "885684a5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:52.141173Z", "iopub.status.busy": "2026-05-19T20:31:52.141054Z", "iopub.status.idle": "2026-05-19T20:31:52.349236Z", "shell.execute_reply": "2026-05-19T20:31:52.348649Z" } }, "outputs": [], "source": [ "b0Xtcat.setLabel(\"{B0bar;Lepton}\");" ] }, { "cell_type": "markdown", "id": "61bdbbcb", "metadata": {}, "source": [ "A MULTI-category is a 'product' of any category (function). The state names of a super\n", "category is a composite of the state labels of the input categories" ] }, { "cell_type": "code", "execution_count": 12, "id": "5728d4d6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:52.351029Z", "iopub.status.busy": "2026-05-19T20:31:52.350896Z", "iopub.status.idle": "2026-05-19T20:31:52.580818Z", "shell.execute_reply": "2026-05-19T20:31:52.563095Z" } }, "outputs": [], "source": [ "RooMultiCategory b0Xttype(\"b0Xttype\", \"b0flav X tagType\", RooArgSet(b0flav, tcatType));" ] }, { "cell_type": "markdown", "id": "7e73227d", "metadata": {}, "source": [ "Make a table of the product category state multiplicity in data" ] }, { "cell_type": "code", "execution_count": 13, "id": "e7c908ff", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:52.582364Z", "iopub.status.busy": "2026-05-19T20:31:52.582240Z", "iopub.status.idle": "2026-05-19T20:31:52.801986Z", "shell.execute_reply": "2026-05-19T20:31:52.801441Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_60:2:23: error: reference to 'data' is ambiguous\n", " Roo1DTable *xtable = data->table(b0Xttype);\n", " ^\n", "input_line_51:4:29: note: candidate found by name lookup is 'data'\n", "std::unique_ptr data{p.generate({x, b0flav, tagCat}, 10000)};\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "Roo1DTable *xtable = data->table(b0Xttype);\n", "xtable->Print(\"v\");" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }