{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "15291f5e",
   "metadata": {},
   "source": [
    "# rf512_wsfactory_oper\n",
    "'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #512\n",
    "\n",
    "Illustration of operator expressions and expression-based\n",
    "basic p.d.f.s in the workspace factory syntax\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "**Author:**  Clemens Lange, Wouter Verkerke (C version)  \n",
    "<i><small>This notebook tutorial was automatically generated with <a href= \"https://github.com/root-project/root/blob/master/documentation/doxygen/converttonotebook.py\">ROOTBOOK-izer</a> from the macro found in the ROOT repository  on Tuesday, May 19, 2026 at 08:32 PM.</small></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4879856f",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:40.085866Z",
     "iopub.status.busy": "2026-05-19T20:32:40.085722Z",
     "iopub.status.idle": "2026-05-19T20:32:41.059457Z",
     "shell.execute_reply": "2026-05-19T20:32:41.058636Z"
    }
   },
   "outputs": [],
   "source": [
    "import ROOT\n",
    "\n",
    "\n",
    "w = ROOT.RooWorkspace(\"w\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "414c18e7",
   "metadata": {},
   "source": [
    "You can define typedefs for even shorter construction semantics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c944cb83",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.061817Z",
     "iopub.status.busy": "2026-05-19T20:32:41.061687Z",
     "iopub.status.idle": "2026-05-19T20:32:41.224566Z",
     "shell.execute_reply": "2026-05-19T20:32:41.223811Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooAbsArg object at 0x(nil)>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"$Typedef(Gaussian,Gaus)\")\n",
    "w.factory(\"$Typedef(Chebychev,Cheby)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ad22734",
   "metadata": {},
   "source": [
    "Operator pdf examples\n",
    "------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebeb7625",
   "metadata": {},
   "source": [
    "PDF addition is done with SUM (coef1*pdf1,pdf2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "40c3d3fe",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.226658Z",
     "iopub.status.busy": "2026-05-19T20:32:41.226511Z",
     "iopub.status.idle": "2026-05-19T20:32:41.362800Z",
     "shell.execute_reply": "2026-05-19T20:32:41.362185Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooAddPdf object at 0x555f70a34bf0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"SUM::summodel( f[0,1]*Gaussian::gx(x[-10,10],m[0],1.0), Chebychev::ch(x,{0.1,0.2,-0.3}) )\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a473b232",
   "metadata": {},
   "source": [
    "Extended PDF addition is done with SUM (yield1*pdf1,yield2*pdf2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6671e78f",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.364791Z",
     "iopub.status.busy": "2026-05-19T20:32:41.364663Z",
     "iopub.status.idle": "2026-05-19T20:32:41.469021Z",
     "shell.execute_reply": "2026-05-19T20:32:41.468450Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooAddPdf object at 0x555f70b91f50>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"SUM::extsummodel( Nsig[0,1000]*gx, Nbkg[0,1000]*ch )\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be1636eb",
   "metadata": {},
   "source": [
    "PDF multiplication is done with PROD ( pdf1, pdf2 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2cd51d32",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.470949Z",
     "iopub.status.busy": "2026-05-19T20:32:41.470826Z",
     "iopub.status.idle": "2026-05-19T20:32:41.583286Z",
     "shell.execute_reply": "2026-05-19T20:32:41.582701Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooProdPdf object at 0x555f70b87c80>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"PROD::gxz( gx, Gaussian::gz(z[-10,10],0,1) )\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7c3290e",
   "metadata": {},
   "source": [
    "Conditional p.d.f multiplication is done with PROD ( pdf1|obs, pdf2 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a0d26178",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.585348Z",
     "iopub.status.busy": "2026-05-19T20:32:41.585223Z",
     "iopub.status.idle": "2026-05-19T20:32:41.694982Z",
     "shell.execute_reply": "2026-05-19T20:32:41.694378Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooProdPdf object at 0x555f70c35c70>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"Gaussian::gy( y[-10,10], x, 1.0 )\")\n",
    "w.factory(\"PROD::gxycond( gy|x, gx )\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f869ec2",
   "metadata": {},
   "source": [
    "Convolution (numeric/ fft) is done with NCONV/FCONV (obs,pdf1,pdf2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2b30cccb",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.696968Z",
     "iopub.status.busy": "2026-05-19T20:32:41.696847Z",
     "iopub.status.idle": "2026-05-19T20:32:41.823817Z",
     "shell.execute_reply": "2026-05-19T20:32:41.823203Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#1] INFO:Caching -- Changing internal binning of variable 'x' in FFT 'lxg' from 100 to 930 to improve the precision of the numerical FFT. This can be done manually by setting an additional binning named 'cache'.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooFFTConvPdf object at 0x555f70d38640>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"FCONV::lxg( x, Gaussian::g(x,mg[0],1), Landau::lc(x,0,1) )\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a4a0ce48",
   "metadata": {},
   "source": [
    "Simultaneous p.d.f.s are constructed with SIMUL( index, state1=pdf1,\n",
    "state2=pdf2,...)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4269de77",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.825839Z",
     "iopub.status.busy": "2026-05-19T20:32:41.825714Z",
     "iopub.status.idle": "2026-05-19T20:32:41.941052Z",
     "shell.execute_reply": "2026-05-19T20:32:41.940415Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooSimultaneous object at 0x555f70d75790>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"SIMUL::smodel( c[A=0,B=1], A=Gaussian::gs(x,m,s[1.0, 0.01, 10.0]), B=Landau::ls(x,0,1) )\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1af59bf0",
   "metadata": {},
   "source": [
    "Operator function examples\n",
    "---------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73e05baa",
   "metadata": {},
   "source": [
    "Function multiplication is done with prod (func1, func2,...)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ba767a79",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:41.943013Z",
     "iopub.status.busy": "2026-05-19T20:32:41.942892Z",
     "iopub.status.idle": "2026-05-19T20:32:42.054619Z",
     "shell.execute_reply": "2026-05-19T20:32:42.053925Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooProduct object at 0x555f70e017a0>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"prod::uv(u[10],v[10])\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10201229",
   "metadata": {},
   "source": [
    "Function addition is done with sum(func1,func2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "409e0d08",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:42.056592Z",
     "iopub.status.busy": "2026-05-19T20:32:42.056471Z",
     "iopub.status.idle": "2026-05-19T20:32:42.163331Z",
     "shell.execute_reply": "2026-05-19T20:32:42.162743Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooAddition object at 0x555f70db6410>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"sum::uv2(u,v)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "218e858b",
   "metadata": {},
   "source": [
    "Lagrangian morphing function for the example shown in rf711_lagrangianmorph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "dc05156b",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:42.165622Z",
     "iopub.status.busy": "2026-05-19T20:32:42.165483Z",
     "iopub.status.idle": "2026-05-19T20:32:42.315072Z",
     "shell.execute_reply": "2026-05-19T20:32:42.314704Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0] PROGRESS:InputArguments -- initializing physics inputs from file /github/home/ROOT-CI/build/tutorials/roofit/roofit/input_histos_rf_lagrangianmorph.root with object name(s) 'pTV'\n",
      "[#1] INFO:ObjectHandling -- RooWorkspace::import(w) importing dataset dh_SM_NPsq0_morph\n",
      "[#1] INFO:ObjectHandling -- RooWorkspace::import(w) importing dataset dh_cHq3_NPsq1_morph\n",
      "[#1] INFO:ObjectHandling -- RooWorkspace::import(w) importing dataset dh_cHq3_NPsq2_morph\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooLagrangianMorphFunc object at 0x555f71074360>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "infilename = ROOT.gROOT.GetTutorialDir().Data() + \"/roofit/roofit/input_histos_rf_lagrangianmorph.root\"\n",
    "w.factory(\n",
    "    \"lagrangianmorph::morph($observableName('pTV'),$fileName('\"\n",
    "    + infilename\n",
    "    + \"'),$couplings({cHq3[0,1],SM[1]}),$NewPhysics(cHq3=1,SM=0),$folders({'SM_NPsq0','cHq3_NPsq1','cHq3_NPsq2'}))\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2400d8be",
   "metadata": {},
   "source": [
    "Taylor expansion is done with taylorexpand(func,{var1,var2,...},val,order)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6c98d807",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:42.322868Z",
     "iopub.status.busy": "2026-05-19T20:32:42.322735Z",
     "iopub.status.idle": "2026-05-19T20:32:42.444822Z",
     "shell.execute_reply": "2026-05-19T20:32:42.444286Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooPolyFunc object at 0x555f711067c0>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"taylorexpand::te(expr::poly('x^4+5*x^3+2*x^2+x+1',x),{x},0.0,2)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "479ad0d7",
   "metadata": {},
   "source": [
    "Interpreted and compiled expression based pdfs\n",
    "---------------------------------------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd7a02c0",
   "metadata": {},
   "source": [
    "Create a ROOT.RooGenericPdf interpreted p.d.f. You can use single quotes\n",
    "to pass the expression string argument"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f01ce349",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:42.453357Z",
     "iopub.status.busy": "2026-05-19T20:32:42.453226Z",
     "iopub.status.idle": "2026-05-19T20:32:42.571279Z",
     "shell.execute_reply": "2026-05-19T20:32:42.570692Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooGenericPdf object at 0x555f6f6cc910>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.factory(\"EXPR::G('x*x+1',x)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d88ed15d",
   "metadata": {},
   "source": [
    "Create a custom compiled p.d.f similar to the above interpreted p.d.f.\n",
    "The code required to make self p.d.f. is automatically embedded in\n",
    "the workspace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b4c4c43a",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:42.573167Z",
     "iopub.status.busy": "2026-05-19T20:32:42.573039Z",
     "iopub.status.idle": "2026-05-19T20:32:52.513005Z",
     "shell.execute_reply": "2026-05-19T20:32:52.512485Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Info in <TUnixSystem::ACLiC>: creating shared library /github/home/master/notebooks/RooCFAuto000Pdf_cxx.so\n",
      "/usr/bin/ld: cannot find /github/home/master/notebooks/RooCFAuto000Pdf_cxx_ACLiC_dict.o: No such file or directory\n",
      "collect2: error: ld returned 1 exit status\n",
      "Error in <ACLiC>: Executing 'cd \"/github/home/master/notebooks\" ; c++ -fPIC -c -O3 -DNDEBUG -Wno-implicit-fallthrough -Wno-noexcept-type -pipe -W -Woverloaded-virtual -fsigned-char -fsized-deallocation -pthread -std=c++17  -I/github/home/ROOT-CI/build/include -I\"/github/home/ROOT-CI/build/etc/\" -I\"/github/home/ROOT-CI/build/etc//cling\" -I\"/github/home/ROOT-CI/build/etc//cling/plugins/include\" -I\"/github/home/ROOT-CI/build/include\" -I\"/usr/include/python3.12\" -I\"/usr/include/freetype2\"   -D__ACLIC__ \"/github/home/master/notebooks/RooCFAuto000Pdf_cxx_ACLiC_dict.cxx\" ; c++ -O3 -DNDEBUG \"/github/home/master/notebooks/RooCFAuto000Pdf_cxx_ACLiC_dict.o\" -shared  -rdynamic -Wl,-rpath,/github/home/ROOT-CI/build/lib -Wl,-rpath,/github/home/master/notebooks  \"/lib64/libm.so\" \"/lib64/libc.so\" \"/lib64/libpython3.12.so.1.0\" \"/usr/lib64/python3.12/lib-dynload/math.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_json.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/fcntl.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_posixsubprocess.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/select.cpython-312-x86_64-linux-gnu.so\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/zmq/backend/cython/_zmq.abi3.so\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/zmq/backend/cython/../../../pyzmq.libs/libzmq-7b073b3d.so.5.2.5\" \"/lib64/libpthread.so.0\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/zmq/backend/cython/../../../pyzmq.libs/libsodium-19479d6d.so.26.2.0\" \"/lib64/librt.so.1\" \"/usr/lib64/python3.12/lib-dynload/_opcode.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_struct.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_pickle.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_bisect.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_random.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_hashlib.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libcrypto.so.3\" \"/lib64/libz.so.1\" \"/usr/lib64/python3.12/lib-dynload/_blake2.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_heapq.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_socket.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/array.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_ssl.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libssl.so.3\" \"/usr/lib64/python3.12/lib-dynload/binascii.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_contextvars.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_asyncio.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_queue.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_datetime.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/zlib.cpython-312-x86_64-linux-gnu.so\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/tornado/speedups.abi3.so\" \"/usr/lib64/python3.12/lib-dynload/_curses.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libncursesw.so.6\" \"/lib64/libtinfo.so.6\" \"/usr/lib64/python3.12/lib-dynload/_decimal.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libmpdec.so.3\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/msgpack/_cmsgpack.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/termios.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_bz2.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libbz2.so.1\" \"/usr/lib64/python3.12/lib-dynload/_lzma.cpython-312-x86_64-linux-gnu.so\" \"/lib64/liblzma.so.5\" \"/usr/lib64/python3.12/lib-dynload/_uuid.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libuuid.so.1\" \"/usr/lib64/python3.12/lib-dynload/_csv.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_sqlite3.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libsqlite3.so.0\" \"/usr/lib64/python3.12/lib-dynload/pyexpat.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libexpat.so.1\" \"/usr/lib64/python3.12/lib-dynload/unicodedata.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/_lsprof.cpython-312-x86_64-linux-gnu.so\" \"/usr/lib64/python3.12/lib-dynload/resource.cpython-312-x86_64-linux-gnu.so\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/psutil/_psutil_linux.abi3.so\" \"/usr/lib64/python3.12/lib-dynload/_ctypes.cpython-312-x86_64-linux-gnu.so\" \"/lib64/libffi.so.8\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cpython-312-x86_64-linux-gnu.so\" \"/py-venv/ROOT-CI/lib64/python3.12/site-packages/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.cpython-312-x86_64-linux-gnu.so\" \"/github/home/ROOT-CI/build/lib/cppyy/libcppyy.so\" \"/github/home/ROOT-CI/build/lib/libCPyCppyy.so\" \"/github/home/ROOT-CI/build/lib/libCore.so\" \"/lib64/libpcre2-8.so.0\" \"/lib64/libxxhash.so.0\" \"/lib64/liblz4.so.1\" \"/lib64/libzstd.so.1\" \"/github/home/ROOT-CI/build/lib/libRIO.so\" \"/github/home/ROOT-CI/build/lib/libThread.so\" \"/lib64/libtbb.so.12\" \"/github/home/ROOT-CI/build/lib/libCling.so\" \"/github/home/ROOT-CI/build/lib/ROOT/libROOTPythonizations.so\" \"/github/home/ROOT-CI/build/lib/libTree.so\" \"/github/home/ROOT-CI/build/lib/libMathCore.so\" \"/github/home/ROOT-CI/build/lib/libImt.so\" \"/github/home/ROOT-CI/build/lib/libMultiProc.so\" \"/github/home/ROOT-CI/build/lib/libNet.so\" \"/github/home/ROOT-CI/build/lib/libRint.so\" \"/github/home/ROOT-CI/build/lib/libRooFitCore.so\" \"/github/home/ROOT-CI/build/lib/libGraf.so\" \"/github/home/ROOT-CI/build/lib/libFoam.so\" \"/github/home/ROOT-CI/build/lib/libRooBatchCompute.so\" \"/github/home/ROOT-CI/build/lib/libHist.so\" \"/github/home/ROOT-CI/build/lib/libMatrix.so\" \"/lib64/libfreetype.so.6\" \"/lib64/libpng16.so.16\" \"/lib64/libharfbuzz.so.0\" \"/lib64/libbrotlidec.so.1\" \"/lib64/libglib-2.0.so.0\" \"/lib64/libgraphite2.so.3\" \"/lib64/libbrotlicommon.so.1\" \"/github/home/ROOT-CI/build/lib/liblistDict.so\" \"/github/home/ROOT-CI/build/lib/libROOTMLDataLoader.so\" \"/github/home/ROOT-CI/build/lib/libROOTDataFrame.so\" \"/github/home/ROOT-CI/build/lib/libTreePlayer.so\" \"/github/home/ROOT-CI/build/lib/libGraf3d.so\" \"/github/home/ROOT-CI/build/lib/libGpad.so\" \"/github/home/ROOT-CI/build/lib/libROOTNTuple.so\" \"/github/home/ROOT-CI/build/lib/libROOTVecOps.so\" \"/github/home/ROOT-CI/build/lib/libvdt.so\" \"/github/home/ROOT-CI/build/lib/libROOTHist.so\" \"/github/home/ROOT-CI/build/lib/libROOTGpadv7.so\" \"/github/home/ROOT-CI/build/lib/libGeom.so\" \"/github/home/ROOT-CI/build/lib/libGenVector.so\" \"/github/home/ROOT-CI/build/lib/libRooFit.so\" \"/lib64/libnss_systemd.so.2\" \"/lib64/libcap.so.2\" -o \"/github/home/master/notebooks/RooCFAuto000Pdf_cxx.so\" ' failed!\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooCFAuto001Pdf object at 0x555f7142a020>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0] ERROR:ObjectHandling -- RooWorkspace::CodeRepo(w) ERROR: cannot retrieve code file names for class RooCFAuto001Pdf through ROOT TClass interface, unable to import code\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Info in <TUnixSystem::ACLiC>: creating shared library /github/home/master/notebooks/RooCFAuto001Pdf_cxx.so\n"
     ]
    }
   ],
   "source": [
    "w.factory(\"CEXPR::GC('x*x+a',{x,a[1]})\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e97bbfe9",
   "metadata": {},
   "source": [
    "Compiled and interpreted functions (rather than p.d.f.s) can be made with the lower case\n",
    "'expr' and 'cexpr' types"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92ca3211",
   "metadata": {},
   "source": [
    "Print workspace contents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b565dd5e",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:52.528396Z",
     "iopub.status.busy": "2026-05-19T20:32:52.528254Z",
     "iopub.status.idle": "2026-05-19T20:32:52.673078Z",
     "shell.execute_reply": "2026-05-19T20:32:52.672638Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "RooWorkspace(w) w contents\n",
      "\n",
      "variables\n",
      "---------\n",
      "(Nbkg,Nsig,SM,a,binWidth_pTV,c,cHq3,f,m,mg,nNP0,nNP1,nNP2,nNP3,nNP4,pTV,s,te_c0,te_c1,te_c2,te_x^0,te_x^1,te_x^2,u,v,x,y,z)\n",
      "\n",
      "p.d.f.s\n",
      "-------\n",
      "RooGenericPdf::G[ actualVars=(x) formula=\"x[0]*x[0]+1\" ] = 1\n",
      "RooCFAuto001Pdf::GC[ x=x a=a ] = 1\n",
      "RooChebychev::ch[ x=x coefList=(0.1,0.2,-0.3) ] = 0.8\n",
      "RooAddPdf::extsummodel[ Nsig * gx + Nbkg * ch ] = 0.9/1\n",
      "RooGaussian::g[ x=x mean=mg sigma=1 ] = 1\n",
      "RooGaussian::gs[ x=x mean=m sigma=s ] = 1\n",
      "RooGaussian::gx[ x=x mean=m sigma=1 ] = 1\n",
      "RooProdPdf::gxycond[ gx * gy|x ] = 1\n",
      "RooProdPdf::gxz[ gx * gz ] = 1\n",
      "RooGaussian::gy[ x=y mean=x sigma=1 ] = 1\n",
      "RooGaussian::gz[ x=z mean=0 sigma=1 ] = 1\n",
      "RooLandau::lc[ x=x mean=0 sigma=1 ] = 0.178854\n",
      "RooLandau::ls[ x=x mean=0 sigma=1 ] = 0.178854\n",
      "RooFFTConvPdf::lxg[ g(x) (*) lc(x) ] = 380336\n",
      "RooSimultaneous::smodel[ indexCat=c A=gs B=ls ] = 1\n",
      "RooAddPdf::summodel[ f * gx + [%] * ch ] = 0.9/1\n",
      "\n",
      "functions\n",
      "--------\n",
      "RooLagrangianMorphFunc::morph[ physics=(phys_SM_NPsq0_morph,phys_cHq3_NPsq1_morph,phys_cHq3_NPsq2_morph) operators=(cHq3,SM) observables=(pTV) binWidths=(binWidth_pTV) flags=(nNP0,nNP1,nNP2,nNP3,nNP4) binWidth_pTV * SM_NPsq0_morph + binWidth_pTV * cHq3_NPsq1_morph + binWidth_pTV * cHq3_NPsq2_morph ] = 35.9835\n",
      "RooHistFunc::phys_SM_NPsq0_morph[ depList=(pTV) ] = 65.1309\n",
      "RooHistFunc::phys_cHq3_NPsq1_morph[ depList=(pTV) ] = 544.966\n",
      "RooHistFunc::phys_cHq3_NPsq2_morph[ depList=(pTV) ] = 1528.22\n",
      "RooFormulaVar::poly[ actualVars=(x) formula=\"x^4+5*x^3+2*x^2+x+1\" ] = 1\n",
      "RooPolyFunc::te[ vars=(x) te_t0=(te_x^0,te_c0) te_t1=(te_x^1,te_c1) te_t2=(te_x^2,te_c2) ] = 1\n",
      "RooProduct::uv[ u * v ] = 100\n",
      "RooAddition::uv2[ u + v ] = 20\n",
      "\n",
      "embedded datasets (in pdfs and functions)\n",
      "-----------------------------------------\n",
      "RooDataHist::dh_SM_NPsq0_morph(pTV)\n",
      "RooDataHist::dh_cHq3_NPsq1_morph(pTV)\n",
      "RooDataHist::dh_cHq3_NPsq2_morph(pTV)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "w.Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a21336ce",
   "metadata": {},
   "source": [
    "Make workspace visible on command line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a13a2ac8",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:52.674435Z",
     "iopub.status.busy": "2026-05-19T20:32:52.674308Z",
     "iopub.status.idle": "2026-05-19T20:32:52.791825Z",
     "shell.execute_reply": "2026-05-19T20:32:52.791272Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.gDirectory.Add(w)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ded6a3a2",
   "metadata": {},
   "source": [
    "Draw all canvases "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a092dde5",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:52.793359Z",
     "iopub.status.busy": "2026-05-19T20:32:52.793237Z",
     "iopub.status.idle": "2026-05-19T20:32:52.900975Z",
     "shell.execute_reply": "2026-05-19T20:32:52.900446Z"
    }
   },
   "outputs": [],
   "source": [
    "from ROOT import gROOT \n",
    "gROOT.GetListOfCanvases().Draw()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
