{ "cells": [ { "cell_type": "markdown", "id": "9a7cd180", "metadata": {}, "source": [ "# rf310_sliceplot\n", "Multidimensional models: projecting pdf and data slices in discrete observables\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:30 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "9a6b3674", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:02.497479Z", "iopub.status.busy": "2026-05-19T20:31:02.497355Z", "iopub.status.idle": "2026-05-19T20:31:02.511302Z", "shell.execute_reply": "2026-05-19T20:31:02.510711Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussModel.h\"\n", "#include \"RooDecay.h\"\n", "#include \"RooBMixDecay.h\"\n", "#include \"RooCategory.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"RooPlot.h\"\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "9b42027c", "metadata": {}, "source": [ "Create B decay pdf with mixing\n", "----------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "5a3e9151", "metadata": {}, "source": [ "Decay time observables" ] }, { "cell_type": "code", "execution_count": 2, "id": "f19fede1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:02.512758Z", "iopub.status.busy": "2026-05-19T20:31:02.512642Z", "iopub.status.idle": "2026-05-19T20:31:02.722206Z", "shell.execute_reply": "2026-05-19T20:31:02.721507Z" } }, "outputs": [], "source": [ "RooRealVar dt(\"dt\", \"dt\", -20, 20);" ] }, { "cell_type": "markdown", "id": "6dfd8fc4", "metadata": {}, "source": [ "Discrete observables mixState (B0tag==B0reco?) and tagFlav (B0tag==B0(bar)?)" ] }, { "cell_type": "code", "execution_count": 3, "id": "d9e9e31d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:02.724146Z", "iopub.status.busy": "2026-05-19T20:31:02.724020Z", "iopub.status.idle": "2026-05-19T20:31:02.929700Z", "shell.execute_reply": "2026-05-19T20:31:02.929039Z" } }, "outputs": [], "source": [ "RooCategory mixState(\"mixState\", \"B0/B0bar mixing state\");\n", "RooCategory tagFlav(\"tagFlav\", \"Flavour of the tagged B0\");" ] }, { "cell_type": "markdown", "id": "73242ee9", "metadata": {}, "source": [ "Define state labels of discrete observables" ] }, { "cell_type": "code", "execution_count": 4, "id": "09621849", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:02.931838Z", "iopub.status.busy": "2026-05-19T20:31:02.931717Z", "iopub.status.idle": "2026-05-19T20:31:03.137024Z", "shell.execute_reply": "2026-05-19T20:31:03.136531Z" } }, "outputs": [], "source": [ "mixState.defineType(\"mixed\", -1);\n", "mixState.defineType(\"unmixed\", 1);\n", "tagFlav.defineType(\"B0\", 1);\n", "tagFlav.defineType(\"B0bar\", -1);" ] }, { "cell_type": "markdown", "id": "05e4c4b3", "metadata": {}, "source": [ "Model parameters" ] }, { "cell_type": "code", "execution_count": 5, "id": "a7034678", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:03.139641Z", "iopub.status.busy": "2026-05-19T20:31:03.139500Z", "iopub.status.idle": "2026-05-19T20:31:03.347663Z", "shell.execute_reply": "2026-05-19T20:31:03.346967Z" } }, "outputs": [], "source": [ "RooRealVar dm(\"dm\", \"delta m(B)\", 0.472, 0., 1.0);\n", "RooRealVar tau(\"tau\", \"B0 decay time\", 1.547, 1.0, 2.0);\n", "RooRealVar w(\"w\", \"Flavor Mistag rate\", 0.03, 0.0, 1.0);\n", "RooRealVar dw(\"dw\", \"Flavor Mistag rate difference between B0 and B0bar\", 0.01);" ] }, { "cell_type": "markdown", "id": "1fd5cec9", "metadata": {}, "source": [ "Build a gaussian resolution model" ] }, { "cell_type": "code", "execution_count": 6, "id": "c3f090c2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:03.349492Z", "iopub.status.busy": "2026-05-19T20:31:03.349369Z", "iopub.status.idle": "2026-05-19T20:31:03.557572Z", "shell.execute_reply": "2026-05-19T20:31:03.556862Z" } }, "outputs": [], "source": [ "RooRealVar bias1(\"bias1\", \"bias1\", 0);\n", "RooRealVar sigma1(\"sigma1\", \"sigma1\", 0.01);\n", "RooGaussModel gm1(\"gm1\", \"gauss model 1\", dt, bias1, sigma1);" ] }, { "cell_type": "markdown", "id": "ee4ff07d", "metadata": {}, "source": [ "Construct a decay pdf, smeared with single gaussian resolution model" ] }, { "cell_type": "code", "execution_count": 7, "id": "bba64d47", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:03.559587Z", "iopub.status.busy": "2026-05-19T20:31:03.559464Z", "iopub.status.idle": "2026-05-19T20:31:03.767230Z", "shell.execute_reply": "2026-05-19T20:31:03.766805Z" } }, "outputs": [], "source": [ "RooBMixDecay bmix_gm1(\"bmix\", \"decay\", dt, mixState, tagFlav, tau, dm, w, dw, gm1, RooBMixDecay::DoubleSided);" ] }, { "cell_type": "markdown", "id": "c1a3ca9d", "metadata": {}, "source": [ "Generate BMixing data with above set of event errors" ] }, { "cell_type": "code", "execution_count": 8, "id": "3c37876e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:03.769366Z", "iopub.status.busy": "2026-05-19T20:31:03.769251Z", "iopub.status.idle": "2026-05-19T20:31:03.978414Z", "shell.execute_reply": "2026-05-19T20:31:03.977857Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_67:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n", " std::unique_ptr data{bmix_gm1.generate({dt, tagFlav, mixState}, 20000)};\n", " ^\n" ] } ], "source": [ "std::unique_ptr data{bmix_gm1.generate({dt, tagFlav, mixState}, 20000)};" ] }, { "cell_type": "markdown", "id": "5e3db1b0", "metadata": {}, "source": [ "Plot full decay distribution\n", "----------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "310573f2", "metadata": {}, "source": [ "Create frame, plot data and pdf projection (integrated over tagFlav and mixState)" ] }, { "cell_type": "code", "execution_count": 9, "id": "8eb1ba03", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:03.979907Z", "iopub.status.busy": "2026-05-19T20:31:03.979790Z", "iopub.status.idle": "2026-05-19T20:31:04.188443Z", "shell.execute_reply": "2026-05-19T20:31:04.187851Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_68:3:1: error: reference to 'data' is ambiguous\n", "data->plotOn(frame);\n", "^\n", "input_line_67:2:30: note: candidate found by name lookup is 'data'\n", " std::unique_ptr data{bmix_gm1.generate({dt, tagFlav, mixState}, 20000)};\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": [ "RooPlot *frame = dt.frame(Title(\"Inclusive decay distribution\"));\n", "data->plotOn(frame);\n", "bmix_gm1.plotOn(frame);" ] }, { "cell_type": "markdown", "id": "ecdca24c", "metadata": {}, "source": [ "Plot decay distr. for mixed and unmixed slice of mixState\n", "------------------------------------------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "87d86f72", "metadata": {}, "source": [ "Create frame, plot data (mixed only)" ] }, { "cell_type": "code", "execution_count": 10, "id": "7faab9c7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:04.189959Z", "iopub.status.busy": "2026-05-19T20:31:04.189843Z", "iopub.status.idle": "2026-05-19T20:31:04.395955Z", "shell.execute_reply": "2026-05-19T20:31:04.395488Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_69:3:1: error: reference to 'data' is ambiguous\n", "data->plotOn(frame2, Cut(\"mixState==mixState::mixed\"));\n", "^\n", "input_line_67:2:30: note: candidate found by name lookup is 'data'\n", " std::unique_ptr data{bmix_gm1.generate({dt, tagFlav, mixState}, 20000)};\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": [ "RooPlot *frame2 = dt.frame(Title(\"Decay distribution of mixed events\"));\n", "data->plotOn(frame2, Cut(\"mixState==mixState::mixed\"));" ] }, { "cell_type": "markdown", "id": "0c61d328", "metadata": {}, "source": [ "Position slice in mixState at \"mixed\" and plot slice of pdf in mixstate over data (integrated over tagFlav)" ] }, { "cell_type": "code", "execution_count": 11, "id": "92b1cd1f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:04.397702Z", "iopub.status.busy": "2026-05-19T20:31:04.397564Z", "iopub.status.idle": "2026-05-19T20:31:04.603250Z", "shell.execute_reply": "2026-05-19T20:31:04.602726Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_70:2:26: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(RooCategory &, const char *)'\n", " bmix_gm1.plotOn(frame2, Slice(mixState, \"mixed\"));\n", " ^~~~~\n" ] } ], "source": [ "bmix_gm1.plotOn(frame2, Slice(mixState, \"mixed\"));" ] }, { "cell_type": "markdown", "id": "c2ccc78c", "metadata": {}, "source": [ "Create frame, plot data (unmixed only)" ] }, { "cell_type": "code", "execution_count": 12, "id": "fad7bdff", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:04.604706Z", "iopub.status.busy": "2026-05-19T20:31:04.604566Z", "iopub.status.idle": "2026-05-19T20:31:04.810688Z", "shell.execute_reply": "2026-05-19T20:31:04.810282Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_71:3:1: error: reference to 'data' is ambiguous\n", "data->plotOn(frame3, Cut(\"mixState==mixState::unmixed\"));\n", "^\n", "input_line_67:2:30: note: candidate found by name lookup is 'data'\n", " std::unique_ptr data{bmix_gm1.generate({dt, tagFlav, mixState}, 20000)};\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": [ "RooPlot *frame3 = dt.frame(Title(\"Decay distribution of unmixed events\"));\n", "data->plotOn(frame3, Cut(\"mixState==mixState::unmixed\"));" ] }, { "cell_type": "markdown", "id": "82c3c552", "metadata": {}, "source": [ "Position slice in mixState at \"unmixed\" and plot slice of pdf in mixstate over data (integrated over tagFlav)" ] }, { "cell_type": "code", "execution_count": 13, "id": "0c09a031", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:04.818256Z", "iopub.status.busy": "2026-05-19T20:31:04.818119Z", "iopub.status.idle": "2026-05-19T20:31:05.026949Z", "shell.execute_reply": "2026-05-19T20:31:05.026342Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_72:2:26: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(RooCategory &, const char *)'\n", " bmix_gm1.plotOn(frame3, Slice(mixState, \"unmixed\"));\n", " ^~~~~\n" ] } ], "source": [ "bmix_gm1.plotOn(frame3, Slice(mixState, \"unmixed\"));\n", "\n", "TCanvas *c = new TCanvas(\"rf310_sliceplot\", \"rf310_sliceplot\", 1200, 400);\n", "c->Divide(3);\n", "c->cd(1);\n", "gPad->SetLeftMargin(0.15);\n", "frame->GetYaxis()->SetTitleOffset(1.4);\n", "gPad->SetLogy();\n", "frame->Draw();\n", "c->cd(2);\n", "gPad->SetLeftMargin(0.15);\n", "frame2->GetYaxis()->SetTitleOffset(1.4);\n", "gPad->SetLogy();\n", "frame2->Draw();\n", "c->cd(3);\n", "gPad->SetLeftMargin(0.15);\n", "frame3->GetYaxis()->SetTitleOffset(1.4);\n", "gPad->SetLogy();\n", "frame3->Draw();" ] }, { "cell_type": "markdown", "id": "e1cfd0d3", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 14, "id": "04b23cde", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:31:05.030566Z", "iopub.status.busy": "2026-05-19T20:31:05.030447Z", "iopub.status.idle": "2026-05-19T20:31:05.238391Z", "shell.execute_reply": "2026-05-19T20:31:05.237772Z" } }, "outputs": [], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "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 }