{
"cells": [
{
"cell_type": "markdown",
"id": "70185e75",
"metadata": {},
"source": [
"# TestNonCentral\n",
"Demonstrates non central chi-square.\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Lorenzo Moneta \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:36 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "fab2dc9d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:37.411218Z",
"iopub.status.busy": "2026-05-19T20:36:37.411107Z",
"iopub.status.idle": "2026-05-19T20:36:37.747661Z",
"shell.execute_reply": "2026-05-19T20:36:37.747083Z"
}
},
"outputs": [],
"source": [
"using namespace RooFit;"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "68931108",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:37.749692Z",
"iopub.status.busy": "2026-05-19T20:36:37.749546Z",
"iopub.status.idle": "2026-05-19T20:36:37.956352Z",
"shell.execute_reply": "2026-05-19T20:36:37.955229Z"
}
},
"outputs": [],
"source": [
"RooWorkspace w(\"w\");"
]
},
{
"cell_type": "markdown",
"id": "f57ba28f",
"metadata": {},
"source": [
"k <2, must use sum"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f1a20ec2",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:37.958014Z",
"iopub.status.busy": "2026-05-19T20:36:37.957887Z",
"iopub.status.idle": "2026-05-19T20:36:38.176395Z",
"shell.execute_reply": "2026-05-19T20:36:38.175254Z"
}
},
"outputs": [],
"source": [
"w.factory(\"NonCentralChiSquare::nc(x[0,50],k[1.99,0,5],lambda[5])\");"
]
},
{
"cell_type": "markdown",
"id": "114722b1",
"metadata": {},
"source": [
"kk > 2 can use bessel"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "593ce4ca",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:38.178061Z",
"iopub.status.busy": "2026-05-19T20:36:38.177942Z",
"iopub.status.idle": "2026-05-19T20:36:38.398742Z",
"shell.execute_reply": "2026-05-19T20:36:38.397653Z"
}
},
"outputs": [],
"source": [
"w.factory(\"NonCentralChiSquare::ncc(x,kk[2.01,0,5],lambda)\");"
]
},
{
"cell_type": "markdown",
"id": "bbb790ab",
"metadata": {},
"source": [
"kk > 2, force sum"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "11a858ba",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:38.400422Z",
"iopub.status.busy": "2026-05-19T20:36:38.400304Z",
"iopub.status.idle": "2026-05-19T20:36:38.628039Z",
"shell.execute_reply": "2026-05-19T20:36:38.619449Z"
}
},
"outputs": [],
"source": [
"w.factory(\"NonCentralChiSquare::nccc(x,kk,lambda)\");\n",
"((RooNonCentralChiSquare *)w.pdf(\"nccc\"))->SetForceSum(true);"
]
},
{
"cell_type": "markdown",
"id": "0d0a0f3c",
"metadata": {},
"source": [
"a normal \"central\" chi-square for comparison when lambda->0"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "9ec123a3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:38.633319Z",
"iopub.status.busy": "2026-05-19T20:36:38.633177Z",
"iopub.status.idle": "2026-05-19T20:36:38.839272Z",
"shell.execute_reply": "2026-05-19T20:36:38.838795Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#0] WARNING:InputArguments -- The parameter 'x' with range [0, 50] of the RooChiSquarePdf 'cs' exceeds the safe range of (0, inf). Advise to limit its range.\n",
"[#0] WARNING:InputArguments -- The parameter 'k' with range [0, 5] of the RooChiSquarePdf 'cs' exceeds the safe range of (0, inf). Advise to limit its range.\n"
]
}
],
"source": [
"w.factory(\"ChiSquarePdf::cs(x,k)\");"
]
},
{
"cell_type": "markdown",
"id": "67737a1a",
"metadata": {},
"source": [
"w.var(\"kk\")->setVal(4.); // test a large kk"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "9fbab39e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:38.840863Z",
"iopub.status.busy": "2026-05-19T20:36:38.840746Z",
"iopub.status.idle": "2026-05-19T20:36:39.050180Z",
"shell.execute_reply": "2026-05-19T20:36:39.049682Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#1] INFO:InputArguments -- RooNonCentralChiSquare sum being forced\n",
"[#0] WARNING:Eval -- RooNonCentralChiSquare did not converge: for x=36 k=2.01, lambda=5 fractional error = 0.00108172\n",
" either adjust tolerance with SetErrorTolerance(tol) or max_iter with SetMaxIter(max_it)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : created default TCanvas with name c1\n"
]
}
],
"source": [
"std::unique_ptr ncdata{w.pdf(\"nc\")->generate(*w.var(\"x\"), 100)};\n",
"std::unique_ptr csdata{w.pdf(\"cs\")->generate(*w.var(\"x\"), 100)};\n",
"RooPlot *plot = w.var(\"x\")->frame();\n",
"ncdata->plotOn(plot, MarkerColor(kRed));\n",
"csdata->plotOn(plot, MarkerColor(kBlue));\n",
"w.pdf(\"nc\")->plotOn(plot, LineColor(kRed));\n",
"w.pdf(\"ncc\")->plotOn(plot, LineColor(kGreen));\n",
"w.pdf(\"nccc\")->plotOn(plot, LineColor(kYellow), LineStyle(kDashed));\n",
"w.pdf(\"cs\")->plotOn(plot, LineColor(kBlue), LineStyle(kDotted));\n",
"plot->Draw();"
]
},
{
"cell_type": "markdown",
"id": "b59eeca5",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "76faa043",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:36:39.051700Z",
"iopub.status.busy": "2026-05-19T20:36:39.051559Z",
"iopub.status.idle": "2026-05-19T20:36:39.298937Z",
"shell.execute_reply": "2026-05-19T20:36:39.298490Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%jsroot on\n",
"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
}