{ "cells": [ { "cell_type": "markdown", "id": "6910d1a6", "metadata": {}, "source": [ "# rf513_wsfactory_tools\n", "Organization and simultaneous fits: RooCustomizer and RooSimWSTool interface in factory\n", "workspace tool in a complex standalone B physics example\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:32 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "b439185f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:41.538711Z", "iopub.status.busy": "2026-05-19T20:32:41.538557Z", "iopub.status.idle": "2026-05-19T20:32:41.553184Z", "shell.execute_reply": "2026-05-19T20:32:41.552620Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"RooChebychev.h\"\n", "#include \"RooAddPdf.h\"\n", "#include \"RooWorkspace.h\"\n", "#include \"RooPlot.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "using namespace RooFit;" ] }, { "cell_type": "code", "execution_count": 2, "id": "36bccad1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:41.555267Z", "iopub.status.busy": "2026-05-19T20:32:41.555148Z", "iopub.status.idle": "2026-05-19T20:32:41.760498Z", "shell.execute_reply": "2026-05-19T20:32:41.759790Z" } }, "outputs": [], "source": [ "RooWorkspace *w = new RooWorkspace(\"w\");" ] }, { "cell_type": "markdown", "id": "778ee388", "metadata": {}, "source": [ "Build a complex example p.d.f.\n", "-----------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "1351287b", "metadata": {}, "source": [ "Make signal model for CPV: A bmixing decay function in t (convoluted with a triple Gaussian resolution model)\n", "times a Gaussian function the reconstructed mass" ] }, { "cell_type": "code", "execution_count": 3, "id": "c89da2b5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:41.762883Z", "iopub.status.busy": "2026-05-19T20:32:41.762756Z", "iopub.status.idle": "2026-05-19T20:32:41.965159Z", "shell.execute_reply": "2026-05-19T20:32:41.964471Z" } }, "outputs": [], "source": [ "w->factory(\"PROD::sig( BMixDecay::sig_t( dt[-20,20], mixState[mixed=1,unmix=-1], tagFlav[B0=1,B0bar=-1], \"\n", " \"tau[1.54], dm[0.472], w[0.05], dw[0],\"\n", " \"AddModel::gm({GaussModel(dt,biasC[-10,10],sigmaC[0.1,3],dterr[0.01,0.2]),\"\n", " \"GaussModel(dt,0,sigmaT[3,10]),\"\n", " \"GaussModel(dt,0,20)},{fracC[0,1],fracT[0,1]}),\"\n", " \"DoubleSided ),\"\n", " \"Gaussian::sig_m( mes[5.20,5.30], mB0[5.20,5.30], sigmB0[0.01,0.05] ))\");" ] }, { "cell_type": "markdown", "id": "7b5e6162", "metadata": {}, "source": [ "Make background component: A plain decay function in t times an Argus function in the reconstructed mass" ] }, { "cell_type": "code", "execution_count": 4, "id": "f2587f3e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:41.967224Z", "iopub.status.busy": "2026-05-19T20:32:41.967102Z", "iopub.status.idle": "2026-05-19T20:32:42.172935Z", "shell.execute_reply": "2026-05-19T20:32:42.172188Z" } }, "outputs": [], "source": [ "w->factory(\"PROD::bkg( Decay::bkg_t( dt, tau, gm, DoubleSided),\"\n", " \"ArgusBG::bkg_m( mes, 5.291, k[-100,-10]))\");" ] }, { "cell_type": "markdown", "id": "3c24e72c", "metadata": {}, "source": [ "Make composite model from the signal and background component" ] }, { "cell_type": "code", "execution_count": 5, "id": "0e7d850d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:42.174582Z", "iopub.status.busy": "2026-05-19T20:32:42.174455Z", "iopub.status.idle": "2026-05-19T20:32:42.404780Z", "shell.execute_reply": "2026-05-19T20:32:42.388494Z" } }, "outputs": [], "source": [ "w->factory(\"SUM::model( Nsig[5000,0,10000]*sig, NBkg[500,0,10000]*bkg )\");" ] }, { "cell_type": "markdown", "id": "a2d94e21", "metadata": {}, "source": [ "Example of RooSimWSTool interface\n", "------------------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "088bac47", "metadata": {}, "source": [ "Introduce a flavour tagging category tagCat as observable with 4 states corresponding\n", "to 4 flavour tagging techniques with different performance that require different\n", "parameterizations of the fit model\n", "\n", "RooSimWSTool operation:\n", "- Make 4 clones of model (for each tagCat) state, that will gain an individual\n", "copy of parameters w,dw and biasC. The other parameters remain common\n", "- Make a simultaneous pdf of the 4 clones assigning each to the appropriate\n", "state of the tagCat index category" ] }, { "cell_type": "markdown", "id": "30745d86", "metadata": {}, "source": [ "RooSimWSTool is interfaced as meta-type SIMCLONE in the factory. The $SplitParam()\n", "argument maps to the SplitParam() named argument in the RooSimWSTool constructor" ] }, { "cell_type": "code", "execution_count": 6, "id": "09092e95", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:42.406526Z", "iopub.status.busy": "2026-05-19T20:32:42.406392Z", "iopub.status.idle": "2026-05-19T20:32:42.611836Z", "shell.execute_reply": "2026-05-19T20:32:42.611194Z" } }, "outputs": [], "source": [ "w->factory(\"SIMCLONE::model_sim( model, $SplitParam({w,dw,biasC},tagCat[Lep,Kao,NT1,NT2]))\");" ] }, { "cell_type": "markdown", "id": "21282842", "metadata": {}, "source": [ "Example of RooCustomizer interface\n", "-------------------------------------------------------------------\n", "\n", "Class RooCustomizer makes clones of existing pdfs with certain prescribed\n", "modifications (branch of leaf node replacements)\n", "\n", "Here we take our model (the original before RooSimWSTool modifications)\n", "and request that the parameter w (the mistag rate) is replaced with\n", "an expression-based function that calculates w in terms of the Dilution\n", "parameter D that is defined as D = 1-2*w" ] }, { "cell_type": "markdown", "id": "0ed09a7a", "metadata": {}, "source": [ "Make a clone model_D of original 'model' replacing 'w' with 'expr('0.5-D/2',D[0,1])'" ] }, { "cell_type": "code", "execution_count": 7, "id": "be4f0ed0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:42.613921Z", "iopub.status.busy": "2026-05-19T20:32:42.613796Z", "iopub.status.idle": "2026-05-19T20:32:42.815927Z", "shell.execute_reply": "2026-05-19T20:32:42.815257Z" } }, "outputs": [], "source": [ "w->factory(\"EDIT::model_D(model, w=expr('0.5-D/2',D[0,1]) )\");" ] }, { "cell_type": "markdown", "id": "eefe0c8f", "metadata": {}, "source": [ "Print workspace contents" ] }, { "cell_type": "code", "execution_count": 8, "id": "94954b69", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:42.819420Z", "iopub.status.busy": "2026-05-19T20:32:42.819287Z", "iopub.status.idle": "2026-05-19T20:32:43.031146Z", "shell.execute_reply": "2026-05-19T20:32:43.030521Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RooWorkspace(w) w contents\n", "\n", "variables\n", "---------\n", "(D,NBkg,Nsig,biasC,biasC_Kao,biasC_Lep,biasC_NT1,biasC_NT2,dm,dt,dterr,dw,dw_Kao,dw_Lep,dw_NT1,dw_NT2,fracC,fracT,k,mB0,mes,mixState,sigmB0,sigmaC,sigmaT,tagCat,tagFlav,tau,w,w_Kao,w_Lep,w_NT1,w_NT2)\n", "\n", "p.d.f.s\n", "-------\n", "RooProdPdf::bkg[ bkg_t * bkg_m ] = 0.307193\n", "RooProdPdf::bkg_Kao[ bkg_t_Kao * bkg_m ] = 0.307193\n", "RooProdPdf::bkg_Lep[ bkg_t_Lep * bkg_m ] = 0.307193\n", "RooProdPdf::bkg_NT1[ bkg_t_NT1 * bkg_m ] = 0.307193\n", "RooProdPdf::bkg_NT2[ bkg_t_NT2 * bkg_m ] = 0.307193\n", "RooArgusBG::bkg_m[ m=mes m0=5.291 c=k p=0.5 ] = 0.279062\n", "RooDecay::bkg_t[ t=dt tau=tau ] = 1.10081\n", "RooDecay::bkg_t_Kao[ t=dt tau=tau ] = 1.10081\n", "RooDecay::bkg_t_Lep[ t=dt tau=tau ] = 1.10081\n", "RooDecay::bkg_t_NT1[ t=dt tau=tau ] = 1.10081\n", "RooDecay::bkg_t_NT2[ t=dt tau=tau ] = 1.10081\n", "RooAddPdf::model[ Nsig * sig + NBkg * bkg ] = 1.88229/1\n", "RooAddPdf::model_D[ Nsig * sig_model_D + NBkg * bkg ] = 1.5029/1\n", "RooAddPdf::model_Kao[ Nsig * sig_Kao + NBkg * bkg_Kao ] = 1.88229/1\n", "RooAddPdf::model_Lep[ Nsig * sig_Lep + NBkg * bkg_Lep ] = 1.88229/1\n", "RooAddPdf::model_NT1[ Nsig * sig_NT1 + NBkg * bkg_NT1 ] = 1.88229/1\n", "RooAddPdf::model_NT2[ Nsig * sig_NT2 + NBkg * bkg_NT2 ] = 1.88229/1\n", "RooSimultaneous::model_sim[ indexCat=tagCat Kao=model_Kao Lep=model_Lep NT1=model_NT1 NT2=model_NT2 ] = 0.470573\n", "RooProdPdf::sig[ sig_t * sig_m ] = 2.0398\n", "RooProdPdf::sig_Kao[ sig_t_Kao * sig_m ] = 2.0398\n", "RooProdPdf::sig_Lep[ sig_t_Lep * sig_m ] = 2.0398\n", "RooProdPdf::sig_NT1[ sig_t_NT1 * sig_m ] = 2.0398\n", "RooProdPdf::sig_NT2[ sig_t_NT2 * sig_m ] = 2.0398\n", "RooGaussian::sig_m[ x=mes mean=mB0 sigma=sigmB0 ] = 1\n", "RooProdPdf::sig_model_D[ sig_t_model_D * sig_m ] = 1.62247\n", "RooBMixDecay::sig_t[ mistag=w delMistag=dw mixState=mixState tagFlav=tagFlav tau=tau dm=dm t=dt ] = 2.0398\n", "RooBMixDecay::sig_t_Kao[ mistag=w_Kao delMistag=dw_Kao mixState=mixState tagFlav=tagFlav tau=tau dm=dm t=dt ] = 2.0398\n", "RooBMixDecay::sig_t_Lep[ mistag=w_Lep delMistag=dw_Lep mixState=mixState tagFlav=tagFlav tau=tau dm=dm t=dt ] = 2.0398\n", "RooBMixDecay::sig_t_NT1[ mistag=w_NT1 delMistag=dw_NT1 mixState=mixState tagFlav=tagFlav tau=tau dm=dm t=dt ] = 2.0398\n", "RooBMixDecay::sig_t_NT2[ mistag=w_NT2 delMistag=dw_NT2 mixState=mixState tagFlav=tagFlav tau=tau dm=dm t=dt ] = 2.0398\n", "RooBMixDecay::sig_t_model_D[ mistag=model_D_2 delMistag=dw mixState=mixState tagFlav=tagFlav tau=tau dm=dm t=dt ] = 1.62247\n", "\n", "analytical resolution models\n", "----------------------------\n", "RooAddModel::gm[ x=dt (fracC * gm_11 + fracT * gm_12 + [%] * gm_13) ] = 1.25632\n", "RooGaussModel::gm_11[ x=dt mean=biasC sigma=sigmaC msf=dterr ssf=dterr ] = 2.45126\n", "RooGaussModel::gm_11_Kao[ x=dt mean=biasC_Kao sigma=sigmaC msf=dterr ssf=dterr ] = 2.45126\n", "RooGaussModel::gm_11_Lep[ x=dt mean=biasC_Lep sigma=sigmaC msf=dterr ssf=dterr ] = 2.45126\n", "RooGaussModel::gm_11_NT1[ x=dt mean=biasC_NT1 sigma=sigmaC msf=dterr ssf=dterr ] = 2.45126\n", "RooGaussModel::gm_11_NT2[ x=dt mean=biasC_NT2 sigma=sigmaC msf=dterr ssf=dterr ] = 2.45126\n", "RooGaussModel::gm_12[ x=dt mean=0 sigma=sigmaT msf=1 ssf=1 ] = 0.0613757\n", "RooGaussModel::gm_13[ x=dt mean=0 sigma=20 msf=1 ssf=1 ] = 0.0199471\n", "RooAddModel::gm_Kao[ x=dt (fracC * gm_11_Kao + fracT * gm_12 + [%] * gm_13) ] = 1.25632\n", "RooAddModel::gm_Lep[ x=dt (fracC * gm_11_Lep + fracT * gm_12 + [%] * gm_13) ] = 1.25632\n", "RooAddModel::gm_NT1[ x=dt (fracC * gm_11_NT1 + fracT * gm_12 + [%] * gm_13) ] = 1.25632\n", "RooAddModel::gm_NT2[ x=dt (fracC * gm_11_NT2 + fracT * gm_12 + [%] * gm_13) ] = 1.25632\n", "\n", "functions\n", "--------\n", "RooFormulaVar::model_D_2[ actualVars=(D) formula=\"0.5-D/2\" ] = 0.25\n", "\n" ] } ], "source": [ "w->Print();" ] }, { "cell_type": "markdown", "id": "56a13f9b", "metadata": {}, "source": [ "Make workspace visible on command line" ] }, { "cell_type": "code", "execution_count": 9, "id": "dc157529", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:32:43.033030Z", "iopub.status.busy": "2026-05-19T20:32:43.032900Z", "iopub.status.idle": "2026-05-19T20:32:43.241293Z", "shell.execute_reply": "2026-05-19T20:32:43.240633Z" } }, "outputs": [], "source": [ "gDirectory->Add(w);" ] } ], "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 }