{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "48623884",
   "metadata": {},
   "source": [
    "# rf506_msgservice\n",
    "Organization and simultaneous fits: tuning and customizing the ROOT.RooFit message logging facility\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": "3f7e3c1d",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:24.456152Z",
     "iopub.status.busy": "2026-05-19T20:32:24.456035Z",
     "iopub.status.idle": "2026-05-19T20:32:25.448758Z",
     "shell.execute_reply": "2026-05-19T20:32:25.448082Z"
    }
   },
   "outputs": [],
   "source": [
    "import ROOT"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4bd10a39",
   "metadata": {},
   "source": [
    "Create pdf\n",
    "--------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "639345dd",
   "metadata": {},
   "source": [
    "Construct gauss(x,m,s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "67ccf697",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:25.450918Z",
     "iopub.status.busy": "2026-05-19T20:32:25.450784Z",
     "iopub.status.idle": "2026-05-19T20:32:25.630010Z",
     "shell.execute_reply": "2026-05-19T20:32:25.629448Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0] WARNING:InputArguments -- The parameter 's' with range [-10, 10] of the RooGaussian 'g' exceeds the safe range of (0, inf). Advise to limit its range.\n"
     ]
    }
   ],
   "source": [
    "x = ROOT.RooRealVar(\"x\", \"x\", -10, 10)\n",
    "m = ROOT.RooRealVar(\"m\", \"m\", 0, -10, 10)\n",
    "s = ROOT.RooRealVar(\"s\", \"s\", 1, -10, 10)\n",
    "gauss = ROOT.RooGaussian(\"g\", \"g\", x, m, s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3914cb8f",
   "metadata": {},
   "source": [
    "Construct poly(x,p0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bebb7a5c",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:25.631874Z",
     "iopub.status.busy": "2026-05-19T20:32:25.631747Z",
     "iopub.status.idle": "2026-05-19T20:32:25.809202Z",
     "shell.execute_reply": "2026-05-19T20:32:25.808411Z"
    }
   },
   "outputs": [],
   "source": [
    "p0 = ROOT.RooRealVar(\"p0\", \"p0\", 0.01, 0.0, 1.0)\n",
    "poly = ROOT.RooPolynomial(\"p\", \"p\", x, [p0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2b504c5",
   "metadata": {},
   "source": [
    "model = f*gauss(x) + (1-f)*poly(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bb8f4cb1",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:25.810995Z",
     "iopub.status.busy": "2026-05-19T20:32:25.810869Z",
     "iopub.status.idle": "2026-05-19T20:32:25.961480Z",
     "shell.execute_reply": "2026-05-19T20:32:25.960840Z"
    }
   },
   "outputs": [],
   "source": [
    "f = ROOT.RooRealVar(\"f\", \"f\", 0.5, 0.0, 1.0)\n",
    "model = ROOT.RooAddPdf(\"model\", \"model\", [gauss, poly], [f])\n",
    "\n",
    "data = model.generate({x}, 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4f55419",
   "metadata": {},
   "source": [
    "Print configuration of message service\n",
    "------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "473e608c",
   "metadata": {},
   "source": [
    "Print streams configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "eb0169ea",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:25.963494Z",
     "iopub.status.busy": "2026-05-19T20:32:25.963364Z",
     "iopub.status.idle": "2026-05-19T20:32:26.082456Z",
     "shell.execute_reply": "2026-05-19T20:32:26.081693Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Active Message streams\n",
      "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n",
      "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n",
      "[2] MinLevel = INFO Topic = HistFactory \n"
     ]
    }
   ],
   "source": [
    "ROOT.RooMsgService.instance().Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a01f61ac",
   "metadata": {},
   "source": [
    "Adding integration topic to existing INFO stream\n",
    "---------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96f1ba66",
   "metadata": {},
   "source": [
    "Print streams configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f6668c6b",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.084465Z",
     "iopub.status.busy": "2026-05-19T20:32:26.084335Z",
     "iopub.status.idle": "2026-05-19T20:32:26.189047Z",
     "shell.execute_reply": "2026-05-19T20:32:26.188352Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Active Message streams\n",
      "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n",
      "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n",
      "[2] MinLevel = INFO Topic = HistFactory \n"
     ]
    }
   ],
   "source": [
    "ROOT.RooMsgService.instance().Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09935e44",
   "metadata": {},
   "source": [
    "Add Integration topic to existing INFO stream"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e4abbdac",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.190903Z",
     "iopub.status.busy": "2026-05-19T20:32:26.190778Z",
     "iopub.status.idle": "2026-05-19T20:32:26.315707Z",
     "shell.execute_reply": "2026-05-19T20:32:26.314977Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.RooMsgService.instance().getStream(1).addTopic(ROOT.RooFit.Integration)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c839478",
   "metadata": {},
   "source": [
    "Construct integral over gauss to demonstrate message stream"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "294b56c4",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.317621Z",
     "iopub.status.busy": "2026-05-19T20:32:26.317474Z",
     "iopub.status.idle": "2026-05-19T20:32:26.434358Z",
     "shell.execute_reply": "2026-05-19T20:32:26.433721Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#1] INFO:Integration -- RooRealIntegral::ctor(g_Int[x]) Constructing integral of function g over observables(x) with normalization () with range identifier <none>\n",
      "[#1] INFO:Integration -- g: Observable x is suitable for analytical integration (if supported by p.d.f)\n",
      "[#1] INFO:Integration -- g: Function integrated observables (x) internally with code 1\n",
      "[#1] INFO:Integration -- g: Observables (x) are analytically integrated with code 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RooRealIntegral::g_Int[x][ Int gd[Ana](x) ] = 2.50663\n"
     ]
    }
   ],
   "source": [
    "igauss = gauss.createIntegral({x})\n",
    "igauss.Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8d0535a",
   "metadata": {},
   "source": [
    "Print streams configuration in verbose, also shows inactive streams"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b76db076",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.436121Z",
     "iopub.status.busy": "2026-05-19T20:32:26.435995Z",
     "iopub.status.idle": "2026-05-19T20:32:26.540744Z",
     "shell.execute_reply": "2026-05-19T20:32:26.540022Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Active Message streams\n",
      "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n",
      "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Integration Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n",
      "[2] MinLevel = INFO Topic = HistFactory \n"
     ]
    }
   ],
   "source": [
    "ROOT.RooMsgService.instance().Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ec79319",
   "metadata": {},
   "source": [
    "Remove stream"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "39e90e73",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.542306Z",
     "iopub.status.busy": "2026-05-19T20:32:26.542183Z",
     "iopub.status.idle": "2026-05-19T20:32:26.649488Z",
     "shell.execute_reply": "2026-05-19T20:32:26.648855Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.RooMsgService.instance().getStream(1).removeTopic(ROOT.RooFit.Integration)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f29ae6c",
   "metadata": {},
   "source": [
    "Examples of pdf value tracing\n",
    "-----------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2383d93e",
   "metadata": {},
   "source": [
    "Show DEBUG level message on function tracing, ROOT.RooGaussian only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c55cffbd",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.651474Z",
     "iopub.status.busy": "2026-05-19T20:32:26.651347Z",
     "iopub.status.idle": "2026-05-19T20:32:26.778314Z",
     "shell.execute_reply": "2026-05-19T20:32:26.777593Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic=ROOT.RooFit.Tracing, ClassName=\"RooGaussian\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14252b16",
   "metadata": {},
   "source": [
    "Perform a fit to generate some tracing messages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5f731668",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.780345Z",
     "iopub.status.busy": "2026-05-19T20:32:26.780213Z",
     "iopub.status.idle": "2026-05-19T20:32:26.979397Z",
     "shell.execute_reply": "2026-05-19T20:32:26.978732Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#1] INFO:Fitting -- RooAbsPdf::fitTo(model) fixing normalization set for coefficient determination to observables in data\n",
      "[#1] INFO:Fitting -- using generic CPU library compiled with no vectorizations\n",
      "[#1] INFO:Fitting -- Creation of NLL object took 831.193 μs\n",
      "[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData) Summation contains a RooNLLVar, using its error level\n",
      "[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for f: using 0.1\n",
      "[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for m: using 2\n",
      "[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for p0: using 0.005\n",
      "[#0] WARNING:Minimization -- RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for s: using 2\n",
      "[#1] INFO:Minimization -- [fitFCN] No discrete parameters, performing continuous minimization only\n",
      "Minuit2Minimizer: Minimize with max-calls 2000 convergence for edm < 1 strategy 1\n",
      "p0=0.01, \n",
      "prevFCN = 31.75882326  f=0.501, \n",
      "prevFCN = 31.76758673  f=0.499, \n",
      "prevFCN = 31.75008506  f=0.5, m=0.02014, \n",
      "prevFCN = 31.72980141  m=-0.02014, \n",
      "prevFCN = 31.78749743  m=0.004235, \n",
      "prevFCN = 31.75274724  m=-0.004235, \n",
      "prevFCN = 31.76488389  m=0, p0=0.01005, \n",
      "prevFCN = 31.75954549  p0=0.009948, \n",
      "prevFCN = 31.75810351  p0=0.01013, \n",
      "prevFCN = 31.76062402  p0=0.009872, \n",
      "prevFCN = 31.75703788  p0=0.01, s=1.02, \n",
      "prevFCN = 31.67915486  s=0.9799, \n",
      "prevFCN = 31.84068856  s=1.002, \n",
      "prevFCN = 31.75075447  s=0.998, \n",
      "prevFCN = 31.76691405  m=0.004235, s=1, \n",
      "prevFCN = 31.75274724  m=0.02118, \n",
      "prevFCN = 31.72829189  m=0.06353, \n",
      "prevFCN = 31.66614321  m=0.1906, \n",
      "prevFCN = 31.47244051  m=0.5715, \n",
      "prevFCN = 30.87227361  m=1.707, \n",
      "prevFCN = 29.88047134  m=2.064, \n",
      "prevFCN = 29.97604268  f=0.5008, m=1.707, \n",
      "prevFCN = 29.88564172  f=0.4992, \n",
      "prevFCN = 29.87531802  f=0.5, m=1.711, \n",
      "prevFCN = 29.8803659  m=1.703, \n",
      "prevFCN = 29.88060433  m=1.71, \n",
      "prevFCN = 29.88039214  m=1.704, \n",
      "prevFCN = 29.88056503  m=1.707, p0=0.01013, \n",
      "prevFCN = 29.88274199  p0=0.009875, \n",
      "prevFCN = 29.87821833  p0=0.01, s=1.002, \n",
      "prevFCN = 29.87987611  s=0.9984, \n",
      "prevFCN = 29.88107011  s=1.003, \n",
      "prevFCN = 29.87926952  s=0.9967, \n",
      "prevFCN = 29.88168765  f=0.2774, m=1.724, p0=0.000388, s=1.276, \n",
      "prevFCN = 28.97288883  f=0.2912, m=1.723, p0=0.0006269, s=1.257, \n",
      "prevFCN = 28.97893369  f=0.278, m=1.724, p0=0.000388, s=1.276, \n",
      "prevFCN = 28.97325909  f=0.2768, \n",
      "prevFCN = 28.97252778  f=0.2774, m=1.727, \n",
      "prevFCN = 28.97321652  m=1.722, \n",
      "prevFCN = 28.97256819  m=1.724, p0=0.0004103, \n",
      "prevFCN = 28.97321664  p0=0.0003662, \n",
      "prevFCN = 28.97257031  p0=0.000388, s=1.279, \n",
      "prevFCN = 28.97432524  s=1.273, \n",
      "prevFCN = 28.97145596  s=1.282, \n",
      "prevFCN = 28.97575564  s=1.269, \n",
      "prevFCN = 28.97003607  f=0.2452, m=1.663, p0=5.498e-07, s=0.9876, \n",
      "prevFCN = 28.8608997  f=0.2274, m=1.628, p0=0.0001029, s=0.8218, \n",
      "prevFCN = 28.87647974  f=0.241, m=1.655, p0=3.204e-06, s=0.9491, \n",
      "prevFCN = 28.85685477  f=0.2418, \n",
      "prevFCN = 28.85692699  f=0.2403, \n",
      "prevFCN = 28.85679737  f=0.241, m=1.659, \n",
      "prevFCN = 28.85436009  m=1.651, \n",
      "prevFCN = 28.8593705  m=1.655, p0=1.215e-06, \n",
      "prevFCN = 28.85682558  p0=6.138e-06, \n",
      "prevFCN = 28.85689784  p0=3.204e-06, s=0.9556, \n",
      "prevFCN = 28.85804684  s=0.9426, \n",
      "prevFCN = 28.85571545  s=0.9524, \n",
      "prevFCN = 28.85746237  s=0.9458, \n",
      "prevFCN = 28.85626117  f=0.2171, m=1.753, p0=0.0002379, s=0.6877, \n",
      "prevFCN = 28.6750677  f=0.1311, m=2.143, p0=0.004887, s=-0.3611, RooAbsMinimizerFcn: Minimized function has error status.\n",
      "Returning maximum FCN so far (31.8407) to force MIGRAD to back out of this region. Error log follows.\n",
      "Parameter values: \tf=0.131146\tm=2.14309\tp0=0.00488743\ts=-0.361096\n",
      "RooFit::Detail::RooNormalizedPdf::g_over_g_Int[x][ numerator=g denominator=g_Int[x] ]\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=2.2451e-08, denominator=g_Int[x]=-0.905133\n",
      "RooAddPdf::model[ f * g_over_g_Int[x] + [%] * p_over_p_Int[x] ]\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.131146)\n",
      "\n",
      "\n",
      "prevFCN = 122.3539561  f=0.2285, m=1.706, p0=7.868e-05, s=0.8134, \n",
      "prevFCN = 28.78647388  f=0.1125, m=2.24, p0=0.006973, s=-0.6231, RooAbsMinimizerFcn: Minimized function has error status.\n",
      "Returning maximum FCN so far (31.8407) to force MIGRAD to back out of this region. Error log follows.\n",
      "Parameter values: \tf=0.112499\tm=2.24008\tp0=0.00697315\ts=-0.623113\n",
      "RooFit::Detail::RooNormalizedPdf::g_over_g_Int[x][ numerator=g denominator=g_Int[x] ]\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "     p.d.f normalization integral is zero or negative @ numerator=g=0.00156176, denominator=g_Int[x]=-1.56191\n",
      "RooAddPdf::model[ f * g_over_g_Int[x] + [%] * p_over_p_Int[x] ]\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "     getLogVal() top-level p.d.f evaluates to NaN @ !refCoefNorm=(x = 0), !pdfs=(g_over_g_Int[x] = nan,p_over_p_Int[x] = 0.05), !coefficients=(f = 0.112499)\n",
      "\n",
      "\n",
      "prevFCN = 188.0319232  f=0.1613, m=1.997, p0=0.00245, s=0.03234, \n",
      "prevFCN = 28.83468497  f=0.1957, m=1.844, p0=0.0007883, s=0.4446, \n",
      "prevFCN = 28.29265399  f=0.1624, m=1.992, p0=0.002383, s=0.04546, \n",
      "prevFCN = 28.59402561  f=0.1875, m=1.879, p0=0.001091, s=0.3493, \n",
      "prevFCN = 28.21262286  f=0.1848, m=1.891, p0=0.001205, s=0.317, \n",
      "prevFCN = 28.2291378  f=0.1881, m=1.879, p0=0.001091, s=0.3493, \n",
      "prevFCN = 28.2116799  f=0.1869, \n",
      "prevFCN = 28.21358342  f=0.1875, m=1.883, \n",
      "prevFCN = 28.19355103  m=1.876, \n",
      "prevFCN = 28.23178919  m=1.881, \n",
      "prevFCN = 28.20535193  m=1.878, \n",
      "prevFCN = 28.21990748  m=1.879, p0=0.001046, \n",
      "prevFCN = 28.21195078  p0=0.001136, \n",
      "prevFCN = 28.21330942  p0=0.001091, s=0.3526, \n",
      "prevFCN = 28.20611526  s=0.346, \n",
      "prevFCN = 28.21961937  s=0.3499, \n",
      "prevFCN = 28.21150023  s=0.3488, \n",
      "prevFCN = 28.21375918  f=0.1722, m=1.965, p0=0.001851, s=0.1732, \n",
      "prevFCN = 28.74341302  f=0.1862, m=1.887, p0=0.001148, s=0.3343, \n",
      "prevFCN = 28.20584218  f=0.1867, \n",
      "prevFCN = 28.2049983  f=0.1856, \n",
      "prevFCN = 28.20669972  f=0.1862, m=1.888, \n",
      "prevFCN = 28.1981678  m=1.885, \n",
      "prevFCN = 28.21353035  m=1.887, p0=0.001103, \n",
      "prevFCN = 28.205172  p0=0.001193, \n",
      "prevFCN = 28.20652605  p0=0.001148, s=0.3349, \n",
      "prevFCN = 28.20444386  s=0.3338, \n",
      "prevFCN = 28.207256  f=0.1818, m=1.915, p0=0.001339, s=0.308, \n",
      "prevFCN = 28.10982092  f=0.1645, m=2.028, p0=0.002253, s=0.2025, \n",
      "prevFCN = 27.87419674  f=0.1563, m=2.083, p0=0.00279, s=0.1506, \n",
      "prevFCN = 28.120134  f=0.1689, m=1.998, p0=0.001992, s=0.23, \n",
      "prevFCN = 27.88982194  f=0.165, m=2.028, p0=0.002253, s=0.2025, \n",
      "prevFCN = 27.87267254  f=0.164, \n",
      "prevFCN = 27.87573501  f=0.1645, m=2.029, \n",
      "prevFCN = 27.86358331  m=2.027, \n",
      "prevFCN = 27.8848256  m=2.028, p0=0.002191, \n",
      "prevFCN = 27.8732548  p0=0.002317, \n",
      "prevFCN = 27.87515272  p0=0.002253, s=0.203, \n",
      "prevFCN = 27.86944003  s=0.202, \n",
      "prevFCN = 27.87899564  s=0.2028, \n",
      "prevFCN = 27.87149737  s=0.2022, \n",
      "prevFCN = 27.87690965  f=0.1678, m=2.025, p0=0.002114, s=0.2145, \n",
      "prevFCN = 27.78335096  f=0.1813, m=2.015, p0=0.001599, s=0.2625, \n",
      "prevFCN = 27.57269415  f=0.1863, m=2.011, p0=0.00143, s=0.2798, \n",
      "prevFCN = 27.54157239  f=0.1904, m=2.008, p0=0.001303, s=0.2937, \n",
      "prevFCN = 27.52903783  f=0.193, m=2.006, p0=0.001223, s=0.3027, \n",
      "prevFCN = 27.52579739  f=0.1935, \n",
      "prevFCN = 27.52443883  f=0.1924, \n",
      "prevFCN = 27.52717062  f=0.193, m=2.008, \n",
      "prevFCN = 27.51931944  m=2.005, \n",
      "prevFCN = 27.53229881  m=2.007, \n",
      "prevFCN = 27.52090749  m=2.006, \n",
      "prevFCN = 27.53070065  m=2.006, p0=0.001178, \n",
      "prevFCN = 27.52510167  p0=0.001268, \n",
      "prevFCN = 27.52650648  p0=0.001223, s=0.303, \n",
      "prevFCN = 27.52565028  s=0.3024, \n",
      "prevFCN = 27.52594887  s=0.3032, \n",
      "prevFCN = 27.52554316  s=0.3022, \n",
      "prevFCN = 27.52606498  f=0.1972, m=2.021, p0=0.001181, s=0.2995, \n",
      "prevFCN = 27.43559462  f=0.2143, m=2.078, p0=0.001023, s=0.2869, \n",
      "prevFCN = 27.09103887  f=0.2593, m=2.222, p0=0.0006776, s=0.2553, \n",
      "prevFCN = 26.4930668  f=0.3114, m=2.377, p0=0.0003819, s=0.2208, \n",
      "prevFCN = 26.77366262  f=0.2701, m=2.254, p0=0.0006081, s=0.248, \n",
      "prevFCN = 26.44761776  f=0.2707, \n",
      "prevFCN = 26.4477329  f=0.2695, \n",
      "prevFCN = 26.44751719  f=0.2701, m=2.255, \n",
      "prevFCN = 26.44758877  m=2.254, \n",
      "prevFCN = 26.44767461  m=2.255, \n",
      "prevFCN = 26.44759504  m=2.254, \n",
      "prevFCN = 26.44765333  m=2.254, p0=0.0005774, \n",
      "prevFCN = 26.44711639  p0=0.0006397, \n",
      "prevFCN = 26.44813234  p0=0.0006081, s=0.2485, \n",
      "prevFCN = 26.44908167  s=0.2475, \n",
      "prevFCN = 26.44616632  f=0.259, m=2.32, p0=9.98e-05, s=0.1948, \n",
      "prevFCN = 26.48282841  f=0.2655, m=2.282, p0=0.0003449, s=0.2259, \n",
      "prevFCN = 26.40615815  f=0.266, \n",
      "prevFCN = 26.40618966  f=0.2649, \n",
      "prevFCN = 26.40613942  f=0.2655, m=2.282, \n",
      "prevFCN = 26.40679026  m=2.281, \n",
      "prevFCN = 26.40554061  m=2.282, p0=0.0003222, \n",
      "prevFCN = 26.4057895  p0=0.0003684, \n",
      "prevFCN = 26.40653948  p0=0.0003449, s=0.2264, \n",
      "prevFCN = 26.4069314  s=0.2254, \n",
      "prevFCN = 26.40540512  f=0.2619, m=2.269, p0=1.166e-05, s=0.2128, \n",
      "prevFCN = 26.37812649  f=0.2604, m=2.263, p0=9.718e-06, s=0.2071, \n",
      "prevFCN = 26.37647825  f=0.2607, m=2.265, p0=2.448e-06, s=0.2085, \n",
      "prevFCN = 26.37623563  f=0.2613, \n",
      "prevFCN = 26.37614616  f=0.2602, \n",
      "prevFCN = 26.37633795  f=0.2607, m=2.265, \n",
      "prevFCN = 26.37638096  m=2.264, \n",
      "prevFCN = 26.37610505  m=2.265, p0=4.799e-06, \n",
      "prevFCN = 26.37627356  p0=8.816e-07, \n",
      "prevFCN = 26.37621035  p0=2.448e-06, s=0.2089, \n",
      "prevFCN = 26.37617463  s=0.208, \n",
      "prevFCN = 26.37631583  f=0.266, m=2.258, p0=2.888e-06, s=0.2111, \n",
      "prevFCN = 26.375028  f=0.2652, m=2.259, p0=2.82e-06, s=0.2107, \n",
      "prevFCN = 26.37498908  f=0.2657, \n",
      "prevFCN = 26.37499406  f=0.2646, \n",
      "prevFCN = 26.37499693  f=0.2652, m=2.26, \n",
      "prevFCN = 26.3750055  m=2.259, \n",
      "prevFCN = 26.37498542  m=2.259, p0=5.333e-06, \n",
      "prevFCN = 26.37502968  p0=1.1e-06, \n",
      "prevFCN = 26.3749613  p0=2.82e-06, s=0.211, \n",
      "prevFCN = 26.37501086  s=0.2104, \n",
      "prevFCN = 26.37497968  s=0.2107, \n",
      "prevFCN = 26.37498908  f=0.2657, \n",
      "prevFCN = 26.37499406  f=0.2646, \n",
      "prevFCN = 26.37499693  f=0.2652, m=2.26, \n",
      "prevFCN = 26.3750055  m=2.259, \n",
      "prevFCN = 26.37498542  m=2.259, p0=5.333e-06, \n",
      "prevFCN = 26.37502968  p0=1.1e-06, \n",
      "prevFCN = 26.3749613  p0=2.82e-06, s=0.211, \n",
      "prevFCN = 26.37501086  s=0.2104, \n",
      "prevFCN = 26.37497968  f=0.2653, s=0.2107, \n",
      "prevFCN = 26.37498905  f=0.2651, \n",
      "prevFCN = 26.37498962  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37499134  m=2.259, \n",
      "prevFCN = 26.37498732  m=2.259, p0=3.259e-06, \n",
      "prevFCN = 26.37499617  p0=2.412e-06, \n",
      "prevFCN = 26.3749825  p0=2.82e-06, s=0.2108, \n",
      "prevFCN = 26.37499245  s=0.2107, \n",
      "prevFCN = 26.37498621  f=0.2657, m=2.26, s=0.2107, \n",
      "prevFCN = 26.37501118  m=2.259, p0=5.333e-06, \n",
      "prevFCN = 26.37503467  p0=2.82e-06, s=0.211, \n",
      "prevFCN = 26.37501545  f=0.2652, m=2.26, p0=5.333e-06, s=0.2107, \n",
      "prevFCN = 26.37504611  p0=2.82e-06, s=0.211, \n",
      "prevFCN = 26.37502828  m=2.259, p0=5.333e-06, \n",
      "prevFCN = 26.37505147  Minuit2Minimizer : Valid minimum - status = 0\n",
      "FVAL  = 26.3749890776351137\n",
      "Edm   = 5.84995089530609806e-05\n",
      "Nfcn  = 190\n",
      "f\t  = 0.2652\t +/-  0.1492\t(limited)\n",
      "m\t  = 2.259\t +/-  0.1408\t(limited)\n",
      "p0\t  = 2.82e-06\t +/-  0.03063\t(limited)\n",
      "s\t  = 0.2107\t +/-  0.09423\t(limited)\n",
      "p0=2.82e-06, s=0.2107, \n",
      "prevFCN = 26.37498908  f=0.2653, \n",
      "prevFCN = 26.37498905  f=0.2651, \n",
      "prevFCN = 26.37498962  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37499134  m=2.259, \n",
      "prevFCN = 26.37498732  m=2.259, p0=3.259e-06, \n",
      "prevFCN = 26.37499617  p0=2.412e-06, \n",
      "prevFCN = 26.3749825  p0=2.82e-06, s=0.2108, \n",
      "prevFCN = 26.37499245  s=0.2107, \n",
      "prevFCN = 26.37498621  f=0.2652, s=0.2107, \n",
      "prevFCN = 26.37498903  f=0.2652, \n",
      "prevFCN = 26.37498915  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37498949  m=2.259, \n",
      "prevFCN = 26.37498869  m=2.259, p0=2.905e-06, \n",
      "prevFCN = 26.37499046  p0=2.736e-06, \n",
      "prevFCN = 26.37498772  p0=2.82e-06, s=0.2107, \n",
      "prevFCN = 26.37498971  s=0.2107, \n",
      "prevFCN = 26.37498846  f=0.2653, m=2.259, s=0.2107, \n",
      "prevFCN = 26.37499134  m=2.259, p0=3.259e-06, \n",
      "prevFCN = 26.37499614  p0=2.82e-06, s=0.2108, \n",
      "prevFCN = 26.3749924  f=0.2652, m=2.259, p0=3.259e-06, s=0.2107, \n",
      "prevFCN = 26.37499844  p0=2.82e-06, s=0.2108, \n",
      "prevFCN = 26.37499475  m=2.259, p0=3.259e-06, \n",
      "prevFCN = 26.37499954  p0=2.82e-06, s=0.2107, "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator\n",
      "Info in <Minuit2>: MnSeedGenerator Evaluated function and gradient in 291.651 μs\n",
      "Info in <Minuit2>: MnSeedGenerator Initial state: FCN =       31.75882326 Edm =       105.7453285 NCalls =     15\n",
      "Info in <Minuit2>: NegativeG2LineSearch Doing a NegativeG2LineSearch since one of the G2 component is negative\n",
      "Info in <Minuit2>: NegativeG2LineSearch Done after 242.061 μs\n",
      "Info in <Minuit2>: MnSeedGenerator Negative G2 found - new state: \n",
      "  Minimum value : 29.88047134\n",
      "  Edm           : 0.9770510488\n",
      "  Internal parameters:\t[                0      0.171531608     -1.370461484     0.1001674212]\t\n",
      "  Internal gradient  :\t[      3.386411878    -0.2900861807      1.801816673     -3.635226112]\t\n",
      "  Internal covariance matrix:\n",
      "[[     0.27253744              0              0              0]\n",
      " [              0    0.012260718              0              0]\n",
      " [              0              0     0.17864007              0]\n",
      " [              0              0              0    0.015271346]]]\n",
      "Info in <Minuit2>: MnSeedGenerator Initial state  \n",
      "  Minimum value : 29.88047134\n",
      "  Edm           : 0.9770510488\n",
      "  Internal parameters:\t[                0      0.171531608     -1.370461484     0.1001674212]\t\n",
      "  Internal gradient  :\t[      3.386411878    -0.2900861807      1.801816673     -3.635226112]\t\n",
      "  Internal covariance matrix:\n",
      "[[     0.27253744              0              0              0]\n",
      " [              0    0.012260718              0              0]\n",
      " [              0              0     0.17864007              0]\n",
      " [              0              0              0    0.015271346]]]\n",
      "Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 2000\n",
      "Info in <Minuit2>: VariableMetricBuilder    0 - FCN =       29.88047134 Edm =      0.9770510488 NCalls =     34\n",
      "Info in <Minuit2>: VariableMetricBuilder    1 - FCN =       28.97288883 Edm =     0.08543708166 NCalls =     46\n",
      "Info in <Minuit2>: VariableMetricBuilder    2 - FCN =       28.85685477 Edm =      0.1244371212 NCalls =     59\n",
      "Info in <Minuit2>: VariableMetricBuilder    3 - FCN =       28.21262286 Edm =       4.183704166 NCalls =     80\n",
      "Info in <Minuit2>: VariableMetricBuilder    4 - FCN =       28.20584218 Edm =      0.1212466033 NCalls =     90\n",
      "Info in <Minuit2>: VariableMetricBuilder    5 - FCN =       27.87419674 Edm =      0.6700901467 NCalls =    104\n",
      "Info in <Minuit2>: VariableMetricBuilder    6 - FCN =       27.52579739 Edm =      0.4526109095 NCalls =    121\n",
      "Info in <Minuit2>: VariableMetricBuilder    7 - FCN =       26.44761776 Edm =     0.06161593762 NCalls =    136\n",
      "Info in <Minuit2>: VariableMetricBuilder    8 - FCN =       26.40615815 Edm =     0.02342269747 NCalls =    146\n",
      "Info in <Minuit2>: VariableMetricBuilder    9 - FCN =       26.37623563 Edm =    0.001494167444 NCalls =    157\n",
      "Info in <Minuit2>: VariableMetricBuilder   10 - FCN =       26.37498908 Edm =   4.659572515e-05 NCalls =    167\n",
      "Info in <Minuit2>: MnHesse Done after 296.841 μs\n",
      "Info in <Minuit2>: VariableMetricBuilder After Hessian\n",
      "Info in <Minuit2>: VariableMetricBuilder   11 - FCN =       26.37498908 Edm =   5.849950895e-05 NCalls =    190\n",
      "Info in <Minuit2>: VariableMetricBuilder Stop iterating after 2.46312 ms\n",
      "Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 2000\n",
      "Info in <Minuit2>: MnHesse Done after 262.501 μs\n",
      "Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooFitResult object at 0x(nil)>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fitTo(data, Verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ea09d13",
   "metadata": {},
   "source": [
    "Reset message service to default stream configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cd6c7e70",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:26.981362Z",
     "iopub.status.busy": "2026-05-19T20:32:26.981236Z",
     "iopub.status.idle": "2026-05-19T20:32:27.088461Z",
     "shell.execute_reply": "2026-05-19T20:32:27.087637Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.RooMsgService.instance().reset()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fe665ad",
   "metadata": {},
   "source": [
    "Show DEBUG level message on function tracing on all objects, output to\n",
    "file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ea797cd7",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:27.090433Z",
     "iopub.status.busy": "2026-05-19T20:32:27.090294Z",
     "iopub.status.idle": "2026-05-19T20:32:27.200163Z",
     "shell.execute_reply": "2026-05-19T20:32:27.199497Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic=ROOT.RooFit.Tracing, OutputFile=\"rf506_debug.log\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "619ea16f",
   "metadata": {},
   "source": [
    "Perform a fit to generate some tracing messages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "80a6757c",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:27.202205Z",
     "iopub.status.busy": "2026-05-19T20:32:27.202077Z",
     "iopub.status.idle": "2026-05-19T20:32:27.312756Z",
     "shell.execute_reply": "2026-05-19T20:32:27.312181Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#1] INFO:Fitting -- RooAbsPdf::fitTo(model) fixing normalization set for coefficient determination to observables in data\n",
      "[#1] INFO:Fitting -- Creation of NLL object took 208.311 μs\n",
      "[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData) Summation contains a RooNLLVar, using its error level\n",
      "[#1] INFO:Minimization -- [fitFCN] No discrete parameters, performing continuous minimization only\n",
      "Minuit2Minimizer: Minimize with max-calls 2000 convergence for edm < 1 strategy 1\n",
      "\n",
      "prevFCN = 26.37498908  f=0.2667, \n",
      "prevFCN = 26.37503727  f=0.2636, \n",
      "prevFCN = 26.37504545  f=0.2657, \n",
      "prevFCN = 26.37499405  f=0.2646, \n",
      "prevFCN = 26.37499692  f=0.2652, m=2.261, \n",
      "prevFCN = 26.37506777  m=2.258, \n",
      "prevFCN = 26.37501136  m=2.26, \n",
      "prevFCN = 26.37500554  m=2.259, \n",
      "prevFCN = 26.37498543  m=2.259, p0=6.522e-06, \n",
      "prevFCN = 26.3750489  p0=6.471e-07, \n",
      "prevFCN = 26.37495398  p0=5.331e-06, \n",
      "prevFCN = 26.37502965  p0=1.101e-06, \n",
      "prevFCN = 26.37496132  p0=2.82e-06, s=0.2117, \n",
      "prevFCN = 26.37508362  s=0.2098, \n",
      "prevFCN = 26.37499532  s=0.2111, \n",
      "prevFCN = 26.37501134  s=0.2104, \n",
      "prevFCN = 26.37497963  f=0.2652, m=2.259, p0=1.367e-14, s=0.2103, \n",
      "prevFCN = 26.37493072  f=0.2658, \n",
      "prevFCN = 26.37493708  f=0.2647, \n",
      "prevFCN = 26.37493718  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37493591  m=2.258, \n",
      "prevFCN = 26.3749384  m=2.259, p0=3.967e-07, \n",
      "prevFCN = 26.37493713  p0=3.964e-07, \n",
      "prevFCN = 26.37493713  p0=1.367e-14, s=0.2106, \n",
      "prevFCN = 26.37493624  s=0.21, \n",
      "prevFCN = 26.37493815  s=0.2103, \n",
      "prevFCN = 26.37493072  f=0.2658, \n",
      "prevFCN = 26.37493708  f=0.2647, \n",
      "prevFCN = 26.37493718  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37493591  m=2.258, \n",
      "prevFCN = 26.3749384  m=2.259, p0=3.967e-07, \n",
      "prevFCN = 26.37493713  p0=3.964e-07, \n",
      "prevFCN = 26.37493713  p0=1.367e-14, s=0.2106, \n",
      "prevFCN = 26.37493624  s=0.21, \n",
      "prevFCN = 26.37493815  f=0.2654, s=0.2103, \n",
      "prevFCN = 26.37493097  f=0.2651, \n",
      "prevFCN = 26.37493099  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37493073  m=2.259, \n",
      "prevFCN = 26.37493123  m=2.259, p0=1.589e-08, \n",
      "prevFCN = 26.37493098  p0=1.583e-08, \n",
      "prevFCN = 26.37493098  p0=1.367e-14, s=0.2104, \n",
      "prevFCN = 26.3749308  s=0.2102, \n",
      "prevFCN = 26.37493117  f=0.2658, m=2.259, s=0.2103, \n",
      "prevFCN = 26.37494296  m=2.259, p0=3.967e-07, \n",
      "prevFCN = 26.37494349  p0=1.367e-14, s=0.2106, \n",
      "prevFCN = 26.3749422  f=0.2652, m=2.259, p0=3.967e-07, s=0.2103, \n",
      "prevFCN = 26.37494232  p0=1.367e-14, s=0.2106, \n",
      "prevFCN = 26.37494248  m=2.259, p0=3.967e-07, \n",
      "prevFCN = 26.37494265  Minuit2Minimizer : Valid minimum - status = 0\n",
      "FVAL  = 26.3749307248998583\n",
      "Edm   = 8.78576670714055406e-08\n",
      "Nfcn  = 49\n",
      "f\t  = 0.2652\t +/-  0.1492\t(limited)\n",
      "m\t  = 2.259\t +/-  0.1406\t(limited)\n",
      "p0\t  = 1.367e-14\t +/-  0.03063\t(limited)\n",
      "s\t  = 0.2103\t +/-  0.09377\t(limited)\n",
      "p0=1.367e-14, s=0.2103, \n",
      "prevFCN = 26.37493072  f=0.2654, \n",
      "prevFCN = 26.37493097  f=0.2651, \n",
      "prevFCN = 26.37493099  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37493073  m=2.259, \n",
      "prevFCN = 26.37493123  m=2.259, p0=1.589e-08, \n",
      "prevFCN = 26.37493098  p0=1.583e-08, \n",
      "prevFCN = 26.37493098  p0=1.367e-14, s=0.2104, \n",
      "prevFCN = 26.3749308  s=0.2102, \n",
      "prevFCN = 26.37493117  f=0.2653, s=0.2103, \n",
      "prevFCN = 26.37493073  f=0.2652, \n",
      "prevFCN = 26.37493074  f=0.2652, m=2.259, \n",
      "prevFCN = 26.37493069  m=2.259, \n",
      "prevFCN = 26.37493079  m=2.259, p0=6.404e-10, \n",
      "prevFCN = 26.37493074  p0=6.286e-10, \n",
      "prevFCN = 26.37493074  p0=1.367e-14, s=0.2103, \n",
      "prevFCN = 26.3749307  s=0.2103, \n",
      "prevFCN = 26.37493077  f=0.2654, m=2.259, s=0.2103, \n",
      "prevFCN = 26.37493101  m=2.259, p0=1.589e-08, \n",
      "prevFCN = 26.37493123  p0=1.367e-14, s=0.2104, \n",
      "prevFCN = 26.37493103  f=0.2652, m=2.259, p0=1.589e-08, s=0.2103, \n",
      "prevFCN = 26.37493099  p0=1.367e-14, s=0.2104, \n",
      "prevFCN = 26.37493085  m=2.259, p0=1.589e-08, \n",
      "prevFCN = 26.37493105  p0=1.367e-14, s=0.2103, "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator\n",
      "Info in <Minuit2>: MnSeedGenerator Evaluated function and gradient in 388.273 μs\n",
      "Info in <Minuit2>: MnSeedGenerator Initial state: FCN =       26.37498908 Edm =   5.938244792e-05 NCalls =     17\n",
      "Info in <Minuit2>: MnSeedGenerator Initial state  \n",
      "  Minimum value : 26.37498908\n",
      "  Edm           : 5.938244792e-05\n",
      "  Internal parameters:\t[    -0.4888788247     0.2279058433     -1.567438006     0.0210732128]\t\n",
      "  Internal gradient  :\t[  -0.001163072753     0.1952966321    0.02712900138     0.4716314037]\t\n",
      "  Internal covariance matrix:\n",
      "[[     0.23663072              0              0              0]\n",
      " [              0  0.00041386516              0              0]\n",
      " [              0              0     0.24756437              0]\n",
      " [              0              0              0  0.00017632678]]]\n",
      "Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 2000\n",
      "Info in <Minuit2>: VariableMetricBuilder    0 - FCN =       26.37498908 Edm =   5.938244792e-05 NCalls =     17\n",
      "Info in <Minuit2>: VariableMetricBuilder    1 - FCN =       26.37493072 Edm =   9.664079956e-08 NCalls =     26\n",
      "Info in <Minuit2>: MnHesse Done after 478.742 μs\n",
      "Info in <Minuit2>: VariableMetricBuilder After Hessian\n",
      "Info in <Minuit2>: VariableMetricBuilder    2 - FCN =       26.37493072 Edm =   8.785766707e-08 NCalls =     49\n",
      "Info in <Minuit2>: VariableMetricBuilder Stop iterating after 700.113 μs\n",
      "Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 2000\n",
      "Info in <Minuit2>: MnHesse Done after 528.643 μs\n",
      "Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.RooFitResult object at 0x(nil)>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fitTo(data, Verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8abf4cb8",
   "metadata": {},
   "source": [
    "Reset message service to default stream configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1fec4a95",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:27.314734Z",
     "iopub.status.busy": "2026-05-19T20:32:27.314586Z",
     "iopub.status.idle": "2026-05-19T20:32:27.417655Z",
     "shell.execute_reply": "2026-05-19T20:32:27.417120Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.RooMsgService.instance().reset()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dfc2d139",
   "metadata": {},
   "source": [
    "Example of another debugging stream\n",
    "---------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0079d2b9",
   "metadata": {},
   "source": [
    "Show DEBUG level messages on client/server link state management"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "160a3435",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:27.420294Z",
     "iopub.status.busy": "2026-05-19T20:32:27.420164Z",
     "iopub.status.idle": "2026-05-19T20:32:27.524577Z",
     "shell.execute_reply": "2026-05-19T20:32:27.524202Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All Message streams\n",
      "[0] MinLevel = PROGRESS Topic = Generation Minimization Plotting Fitting Integration LinkStateMgmt Eval Caching Optimization ObjectHandling InputArguments Tracing Contents DataHandling NumericIntegration FastEvaluations \n",
      "[1] MinLevel = INFO Topic = Minimization Plotting Fitting Eval Caching ObjectHandling InputArguments DataHandling NumericIntegration \n",
      "[2] MinLevel = INFO Topic = HistFactory \n",
      "[3] MinLevel = DEBUG Topic = LinkStateMgmt \n"
     ]
    }
   ],
   "source": [
    "ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic=ROOT.RooFit.LinkStateMgmt)\n",
    "ROOT.RooMsgService.instance().Print(\"v\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f31d9412",
   "metadata": {},
   "source": [
    "Clone composite pdf g to trigger some link state management activity"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "41ca4327",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:27.526879Z",
     "iopub.status.busy": "2026-05-19T20:32:27.526742Z",
     "iopub.status.idle": "2026-05-19T20:32:27.635925Z",
     "shell.execute_reply": "2026-05-19T20:32:27.635445Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x55b7a10ff550,g): adding server x(0x55b79afd0eb0) for value \n",
      "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x55b7a10ff550,g): adding server m(0x55b7a02ce7a0) for value \n",
      "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x55b7a10ff550,g): adding server s(0x55b7a02bbcc0) for value \n",
      "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x55b7a10ff550,g): adding server x(0x55b79afd0eb0) for value \n",
      "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x55b7a10ff550,g): adding server m(0x55b7a02ce7a0) for value \n",
      "[#3] DEBUG:LinkStateMgmt -- RooAbsArg::addServer(0x55b7a10ff550,g): adding server s(0x55b7a02bbcc0) for value \n",
      "RooGaussian::g[ x=x mean=m sigma=s ] = 8.804e-26\n"
     ]
    }
   ],
   "source": [
    "gprime = gauss.cloneTree()\n",
    "gprime.Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "900bba3d",
   "metadata": {},
   "source": [
    "Reset message service to default stream configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "12a4103c",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:32:27.638109Z",
     "iopub.status.busy": "2026-05-19T20:32:27.637981Z",
     "iopub.status.idle": "2026-05-19T20:32:27.741283Z",
     "shell.execute_reply": "2026-05-19T20:32:27.740636Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.RooMsgService.instance().reset()"
   ]
  }
 ],
 "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
}
