{
"cells": [
{
"cell_type": "markdown",
"id": "5cc15b2c",
"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, March 19, 2024 at 07:15 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "09199fd5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:54.923679Z",
"iopub.status.busy": "2024-03-19T19:15:54.923304Z",
"iopub.status.idle": "2024-03-19T19:15:54.950932Z",
"shell.execute_reply": "2024-03-19T19:15:54.949805Z"
}
},
"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": "2451e466",
"metadata": {},
"source": [
"Create B decay pdf with mixing\n",
"----------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "1d665335",
"metadata": {},
"source": [
"Decay time observables"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "12de7d05",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:54.972962Z",
"iopub.status.busy": "2024-03-19T19:15:54.972579Z",
"iopub.status.idle": "2024-03-19T19:15:55.574386Z",
"shell.execute_reply": "2024-03-19T19:15:55.549506Z"
}
},
"outputs": [],
"source": [
"RooRealVar dt(\"dt\", \"dt\", -20, 20);"
]
},
{
"cell_type": "markdown",
"id": "99fc9c7d",
"metadata": {},
"source": [
"Discrete observables mixState (B0tag==B0reco?) and tagFlav (B0tag==B0(bar)?)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "96eeaf86",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:55.590357Z",
"iopub.status.busy": "2024-03-19T19:15:55.589967Z",
"iopub.status.idle": "2024-03-19T19:15:55.813722Z",
"shell.execute_reply": "2024-03-19T19:15:55.812690Z"
}
},
"outputs": [],
"source": [
"RooCategory mixState(\"mixState\", \"B0/B0bar mixing state\");\n",
"RooCategory tagFlav(\"tagFlav\", \"Flavour of the tagged B0\");"
]
},
{
"cell_type": "markdown",
"id": "aebd637b",
"metadata": {},
"source": [
"Define state labels of discrete observables"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bd18d6b8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:55.819310Z",
"iopub.status.busy": "2024-03-19T19:15:55.818956Z",
"iopub.status.idle": "2024-03-19T19:15:56.032861Z",
"shell.execute_reply": "2024-03-19T19:15:56.031550Z"
}
},
"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": "773d284c",
"metadata": {},
"source": [
"Model parameters"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9e3fbc5d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:56.037409Z",
"iopub.status.busy": "2024-03-19T19:15:56.037071Z",
"iopub.status.idle": "2024-03-19T19:15:56.252407Z",
"shell.execute_reply": "2024-03-19T19:15:56.251231Z"
}
},
"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": "b9574a0d",
"metadata": {},
"source": [
"Build a gaussian resolution model"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "37351a51",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:56.257038Z",
"iopub.status.busy": "2024-03-19T19:15:56.256734Z",
"iopub.status.idle": "2024-03-19T19:15:56.473933Z",
"shell.execute_reply": "2024-03-19T19:15:56.472688Z"
}
},
"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": "4269532c",
"metadata": {},
"source": [
"Construct a decay pdf, smeared with single gaussian resolution model"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7dbe2545",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:56.478589Z",
"iopub.status.busy": "2024-03-19T19:15:56.478277Z",
"iopub.status.idle": "2024-03-19T19:15:56.692495Z",
"shell.execute_reply": "2024-03-19T19:15:56.691308Z"
}
},
"outputs": [],
"source": [
"RooBMixDecay bmix_gm1(\"bmix\", \"decay\", dt, mixState, tagFlav, tau, dm, w, dw, gm1, RooBMixDecay::DoubleSided);"
]
},
{
"cell_type": "markdown",
"id": "6b1b6a68",
"metadata": {},
"source": [
"Generate BMixing data with above set of event errors"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "bcc1f703",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:56.714786Z",
"iopub.status.busy": "2024-03-19T19:15:56.714417Z",
"iopub.status.idle": "2024-03-19T19:15:56.934268Z",
"shell.execute_reply": "2024-03-19T19:15:56.933267Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_60: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": "300203d7",
"metadata": {},
"source": [
"Plot full decay distribution\n",
"----------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "56180374",
"metadata": {},
"source": [
"Create frame, plot data and pdf projection (integrated over tagFlav and mixState)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "1550a946",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:56.938612Z",
"iopub.status.busy": "2024-03-19T19:15:56.938239Z",
"iopub.status.idle": "2024-03-19T19:15:57.154343Z",
"shell.execute_reply": "2024-03-19T19:15:57.153101Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_61:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(frame);\n",
"^\n",
"input_line_60: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/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:309: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": "a9ac840b",
"metadata": {},
"source": [
"Plot decay distr. for mixed and unmixed slice of mixState\n",
"------------------------------------------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "a54f0bac",
"metadata": {},
"source": [
"Create frame, plot data (mixed only)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "90e52c79",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:57.166475Z",
"iopub.status.busy": "2024-03-19T19:15:57.166061Z",
"iopub.status.idle": "2024-03-19T19:15:57.376704Z",
"shell.execute_reply": "2024-03-19T19:15:57.375692Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_62:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(frame2, Cut(\"mixState==mixState::mixed\"));\n",
"^\n",
"input_line_60: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/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:309: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": "6664dc4f",
"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": "91b474ef",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:57.397819Z",
"iopub.status.busy": "2024-03-19T19:15:57.397437Z",
"iopub.status.idle": "2024-03-19T19:15:57.630111Z",
"shell.execute_reply": "2024-03-19T19:15:57.628520Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_63: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": "d216b90b",
"metadata": {},
"source": [
"Create frame, plot data (unmixed only)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7a8cac5f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:57.634974Z",
"iopub.status.busy": "2024-03-19T19:15:57.634572Z",
"iopub.status.idle": "2024-03-19T19:15:57.846358Z",
"shell.execute_reply": "2024-03-19T19:15:57.845062Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_64:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(frame3, Cut(\"mixState==mixState::unmixed\"));\n",
"^\n",
"input_line_60: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/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:309: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": "7902e844",
"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": "eb5cb79f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:57.852704Z",
"iopub.status.busy": "2024-03-19T19:15:57.852357Z",
"iopub.status.idle": "2024-03-19T19:15:58.079418Z",
"shell.execute_reply": "2024-03-19T19:15:58.067105Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_65: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": "6cd9be23",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "0bd0ab67",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:58.091972Z",
"iopub.status.busy": "2024-03-19T19:15:58.091587Z",
"iopub.status.idle": "2024-03-19T19:15:58.307776Z",
"shell.execute_reply": "2024-03-19T19:15:58.306314Z"
}
},
"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
}