{ "cells": [ { "cell_type": "markdown", "id": "9c108065", "metadata": {}, "source": [ "# fitFraction\n", "FractionFitter example À la [HMCMLL](https://cds.cern.ch/record/2296378/files/hbook.pdf),\n", "see R. Barlow and C. Beeston, Comp. Phys. Comm. 77 (1993) 219-228,\n", "\n", "\n", "\n", "\n", "**Author:** \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:24 PM." ] }, { "cell_type": "markdown", "id": "05a5caaf", "metadata": {}, "source": [ "parameters and functions to generate the data" ] }, { "cell_type": "code", "execution_count": 1, "id": "fb73206d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:51.373212Z", "iopub.status.busy": "2026-05-19T20:24:51.373106Z", "iopub.status.idle": "2026-05-19T20:24:51.738748Z", "shell.execute_reply": "2026-05-19T20:24:51.737727Z" } }, "outputs": [], "source": [ "Int_t Ndata = 1000;\n", "Int_t N0 = 1000;\n", "Int_t N1 = 1000;\n", "Int_t N2 = 1000;\n", "\n", "Int_t nBins = 40;\n", "\n", "Double_t trueP0 = .01;\n", "Double_t trueP1 = .3;\n", "Double_t trueP2 = 1. - trueP0 - trueP1;" ] }, { "cell_type": "markdown", "id": "b5e30c3e", "metadata": {}, "source": [ "contribution 0" ] }, { "cell_type": "code", "execution_count": 2, "id": "6d5b03f8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:51.740197Z", "iopub.status.busy": "2026-05-19T20:24:51.740077Z", "iopub.status.idle": "2026-05-19T20:24:51.952176Z", "shell.execute_reply": "2026-05-19T20:24:51.948702Z" } }, "outputs": [], "source": [ "TF1 f0(\"f0\", \"[0]*(1-cos(x))/TMath::Pi()\", 0., TMath::Pi());\n", "f0.SetParameter(0, 1.);\n", "f0.SetLineColor(2);\n", "Double_t int0 = f0.Integral(0., TMath::Pi());" ] }, { "cell_type": "markdown", "id": "be830bd4", "metadata": {}, "source": [ "contribution 1" ] }, { "cell_type": "code", "execution_count": 3, "id": "1e0071e4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:51.958574Z", "iopub.status.busy": "2026-05-19T20:24:51.958440Z", "iopub.status.idle": "2026-05-19T20:24:52.172236Z", "shell.execute_reply": "2026-05-19T20:24:52.171708Z" } }, "outputs": [], "source": [ "TF1 f1(\"f1\", \"[0]*(1-cos(x)*cos(x))*2./TMath::Pi()\", 0., TMath::Pi());\n", "f1.SetParameter(0, 1.);\n", "f1.SetLineColor(3);\n", "Double_t int1 = f1.Integral(0., TMath::Pi());" ] }, { "cell_type": "markdown", "id": "fcabebeb", "metadata": {}, "source": [ "contribution 2" ] }, { "cell_type": "code", "execution_count": 4, "id": "02d8cc05", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:52.180144Z", "iopub.status.busy": "2026-05-19T20:24:52.180008Z", "iopub.status.idle": "2026-05-19T20:24:52.392530Z", "shell.execute_reply": "2026-05-19T20:24:52.391455Z" } }, "outputs": [], "source": [ "TF1 f2(\"f2\", \"[0]*(1+cos(x))/TMath::Pi()\", 0., TMath::Pi());\n", "f2.SetParameter(0, 1.);\n", "f2.SetLineColor(4);\n", "Double_t int2 = f2.Integral(0., TMath::Pi());" ] }, { "cell_type": "markdown", "id": "d98dcc55", "metadata": {}, "source": [ "generate data" ] }, { "cell_type": "code", "execution_count": 5, "id": "b9cb758e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:52.394103Z", "iopub.status.busy": "2026-05-19T20:24:52.393971Z", "iopub.status.idle": "2026-05-19T20:24:52.604103Z", "shell.execute_reply": "2026-05-19T20:24:52.597594Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_70:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n" ] } ], "source": [ "TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", "data.SetXTitle(\"x\");\n", "data.SetMarkerStyle(20);\n", "data.SetMarkerSize(.7);\n", "data.SetMinimum(0);\n", "TH1F htruemc0(data);\n", "htruemc0.SetLineColor(2);\n", "TH1F htruemc1(data);\n", "htruemc1.SetLineColor(3);\n", "TH1F htruemc2(data);\n", "htruemc2.SetLineColor(4);\n", "Double_t p, x;\n", "for (Int_t i = 0; i < Ndata; i++) {\n", " p = gRandom->Uniform();\n", " if (p < trueP0) {\n", " x = f0.GetRandom();\n", " htruemc0.Fill(x);\n", " } else if (p < trueP0 + trueP1) {\n", " x = f1.GetRandom();\n", " htruemc1.Fill(x);\n", " } else {\n", " x = f2.GetRandom();\n", " htruemc2.Fill(x);\n", " }\n", " data.Fill(x);\n", "}" ] }, { "cell_type": "markdown", "id": "b924da5e", "metadata": {}, "source": [ "generate MC samples" ] }, { "cell_type": "code", "execution_count": 6, "id": "3da7532a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:52.618307Z", "iopub.status.busy": "2026-05-19T20:24:52.618153Z", "iopub.status.idle": "2026-05-19T20:24:52.852121Z", "shell.execute_reply": "2026-05-19T20:24:52.849579Z" } }, "outputs": [], "source": [ "TH1F mc0(\"mc0\", \"MC sample 0 angle distribution\", nBins, 0, TMath::Pi()); // first MC histogram\n", "mc0.SetXTitle(\"x\");\n", "mc0.SetLineColor(2);\n", "mc0.SetMarkerColor(2);\n", "mc0.SetMarkerStyle(24);\n", "mc0.SetMarkerSize(.7);\n", "for (Int_t i = 0; i < N0; i++) {\n", " mc0.Fill(f0.GetRandom());\n", "}\n", "\n", "TH1F mc1(\"mc1\", \"MC sample 1 angle distribution\", nBins, 0, TMath::Pi()); // second MC histogram\n", "mc1.SetXTitle(\"x\");\n", "mc1.SetLineColor(3);\n", "mc1.SetMarkerColor(3);\n", "mc1.SetMarkerStyle(24);\n", "mc1.SetMarkerSize(.7);\n", "for (Int_t i = 0; i < N1; i++) {\n", " mc1.Fill(f1.GetRandom());\n", "}\n", "\n", "TH1F mc2(\"mc2\", \"MC sample 2 angle distribution\", nBins, 0, TMath::Pi()); // third MC histogram\n", "mc2.SetXTitle(\"x\");\n", "mc2.SetLineColor(4);\n", "mc2.SetMarkerColor(4);\n", "mc2.SetMarkerStyle(24);\n", "mc2.SetMarkerSize(.7);\n", "for (Int_t i = 0; i < N2; i++) {\n", " mc2.Fill(f2.GetRandom());\n", "}" ] }, { "cell_type": "markdown", "id": "db7bbee7", "metadata": {}, "source": [ "FractionFitter" ] }, { "cell_type": "code", "execution_count": 7, "id": "79a5b06f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:52.863457Z", "iopub.status.busy": "2026-05-19T20:24:52.863288Z", "iopub.status.idle": "2026-05-19T20:24:53.068413Z", "shell.execute_reply": "2026-05-19T20:24:53.068114Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_72:6:22: error: reference to 'data' is ambiguous\n", "TFractionFitter fit(&data, &mc); // initialise\n", " ^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "TObjArray mc(3); // MC histograms are put in this array\n", "mc.Add(&mc0);\n", "mc.Add(&mc1);\n", "mc.Add(&mc2);\n", "TFractionFitter fit(&data, &mc); // initialise\n", "fit.Constrain(0, 0.0, 1.0); // constrain fraction 1 to be between 0 and 1\n", "fit.Constrain(1, 0.0, 1.0); // constrain fraction 1 to be between 0 and 1\n", "fit.Constrain(2, 0.0, 1.0); // constrain fraction 1 to be between 0 and 1" ] }, { "cell_type": "markdown", "id": "ff6d92a4", "metadata": {}, "source": [ "fit.SetRangeX(1,15); // use only the first 15 bins in the fit" ] }, { "cell_type": "code", "execution_count": 8, "id": "d839cf85", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:53.075387Z", "iopub.status.busy": "2026-05-19T20:24:53.075265Z", "iopub.status.idle": "2026-05-19T20:24:53.281831Z", "shell.execute_reply": "2026-05-19T20:24:53.281232Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_74:2:3: error: use of undeclared identifier 'fit'\n", " (fit.Fit())\n", " ^\n", "Error in : Error evaluating expression (fit.Fit())\n", "Execution of your code was aborted.\n" ] } ], "source": [ "Int_t status = fit.Fit(); // perform the fit\n", "std::cout << \"Status: \" << status << std::endl;" ] }, { "cell_type": "markdown", "id": "34ac9893", "metadata": {}, "source": [ "Display" ] }, { "cell_type": "code", "execution_count": 9, "id": "df9bb128", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:53.283463Z", "iopub.status.busy": "2026-05-19T20:24:53.283338Z", "iopub.status.idle": "2026-05-19T20:24:53.495499Z", "shell.execute_reply": "2026-05-19T20:24:53.495150Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_75:13:1: error: reference to 'data' is ambiguous\n", "data.SetTitle(\"Data distribution with true contributions\");\n", "^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:14:1: error: reference to 'data' is ambiguous\n", "data.DrawClone(\"EP\");\n", "^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:25:24: error: use of undeclared identifier 'fit'\n", " auto mcp0 = (TH1F *)fit.GetMCPrediction(0);\n", " ^\n", "input_line_75:28:24: error: use of undeclared identifier 'fit'\n", " auto mcp1 = (TH1F *)fit.GetMCPrediction(1);\n", " ^\n", "input_line_75:31:24: error: use of undeclared identifier 'fit'\n", " auto mcp2 = (TH1F *)fit.GetMCPrediction(2);\n", " ^\n", "input_line_75:42:26: error: use of undeclared identifier 'fit'\n", " auto result = (TH1F *)fit.GetPlot();\n", " ^\n", "input_line_75:43:4: error: use of undeclared identifier 'fit'\n", " fit.GetResult(0, p0, errP0);\n", " ^\n", "input_line_75:45:4: error: use of undeclared identifier 'fit'\n", " fit.GetResult(1, p1, errP1);\n", " ^\n", "input_line_75:47:4: error: use of undeclared identifier 'fit'\n", " fit.GetResult(2, p2, errP2);\n", " ^\n", "input_line_75:49:4: error: reference to 'data' is ambiguous\n", " data.SetTitle(\"Data distribution with fitted contributions\");\n", " ^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:50:4: error: reference to 'data' is ambiguous\n", " data.DrawClone(\"Ep\");\n", " ^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:52:43: error: reference to 'data' is ambiguous\n", " f0.SetParameter(0, Ndata * p0 / int0 * data.GetBinWidth(1));\n", " ^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:55:43: error: reference to 'data' is ambiguous\n", " f1.SetParameter(0, Ndata * p1 / int1 * data.GetBinWidth(1));\n", " ^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:58:43: error: reference to 'data' is ambiguous\n", " f2.SetParameter(0, Ndata * p2 / int2 * data.GetBinWidth(1));\n", " ^\n", "input_line_70:2:7: note: candidate found by name lookup is 'data'\n", " TH1F data(\"data\", \"Data angle distribution\", nBins, 0, TMath::Pi()); // data histogram\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n" ] } ], "source": [ "gStyle->SetOptStat(0);\n", "TCanvas c(\"c\", \"FractionFitter example\", 700, 700);\n", "c.Divide(2, 2);\n", "\n", "c.cd(1);\n", "f0.DrawClone();\n", "f0.GetHistogram()->SetTitle(\"Original MC distributions\");\n", "f1.DrawClone(\"same\");\n", "f2.DrawClone(\"same\");\n", "\n", "c.cd(2);\n", "data.SetTitle(\"Data distribution with true contributions\");\n", "data.DrawClone(\"EP\");\n", "htruemc0.Draw(\"same\");\n", "htruemc1.Draw(\"same\");\n", "htruemc2.Draw(\"same\");\n", "\n", "c.cd(3);\n", "mc0.SetTitle(\"MC generated samples with fit predictions\");\n", "mc0.Draw(\"PE\");\n", "mc1.Draw(\"PEsame\");\n", "mc2.Draw(\"PEsame\");\n", "if (status == 0) { // check on fit status\n", " auto mcp0 = (TH1F *)fit.GetMCPrediction(0);\n", " mcp0->SetLineColor(2);\n", " mcp0->Draw(\"same\");\n", " auto mcp1 = (TH1F *)fit.GetMCPrediction(1);\n", " mcp1->SetLineColor(3);\n", " mcp1->Draw(\"same\");\n", " auto mcp2 = (TH1F *)fit.GetMCPrediction(2);\n", " mcp2->SetLineColor(4);\n", " mcp2->Draw(\"same\");\n", "}\n", "\n", "c.cd(4);\n", "Double_t p0, p1, p2, errP0, errP1, errP2;\n", "TLatex l;\n", "l.SetTextSize(.035);\n", "Char_t text[200];\n", "if (status == 0) { // check on fit status\n", " auto result = (TH1F *)fit.GetPlot();\n", " fit.GetResult(0, p0, errP0);\n", " printf(\" Parameter %d: true %.3f, estim. %.3f +/- %.3f\\n\", 0, trueP0, p0, errP0);\n", " fit.GetResult(1, p1, errP1);\n", " printf(\" Parameter %d: true %.3f, estim. %.3f +/- %.3f\\n\", 1, trueP1, p1, errP1);\n", " fit.GetResult(2, p2, errP2);\n", " printf(\" Parameter %d: true %.3f, estim. %.3f +/- %.3f\\n\", 2, trueP2, p2, errP2);\n", " data.SetTitle(\"Data distribution with fitted contributions\");\n", " data.DrawClone(\"Ep\");\n", " result->Draw(\"same\");\n", " f0.SetParameter(0, Ndata * p0 / int0 * data.GetBinWidth(1));\n", " f0.SetLineStyle(2);\n", " f0.DrawClone(\"same\");\n", " f1.SetParameter(0, Ndata * p1 / int1 * data.GetBinWidth(1));\n", " f1.SetLineStyle(2);\n", " f1.DrawClone(\"same\");\n", " f2.SetParameter(0, Ndata * p2 / int2 * data.GetBinWidth(1));\n", " f2.SetLineStyle(2);\n", " f2.DrawClone(\"same\");\n", " sprintf(text, \"%d: true %.2f, estimated %.2f +/- %.2f\\n\", 0, trueP0, p0, errP0);\n", " l.DrawTextNDC(.45, .30, text);\n", " sprintf(text, \"%d: true %.2f, estimated %.2f +/- %.2f\\n\", 1, trueP1, p1, errP1);\n", " l.DrawTextNDC(.45, .25, text);\n", " sprintf(text, \"%d: true %.2f, estimated %.2f +/- %.2f\\n\", 2, trueP2, p2, errP2);\n", " l.DrawTextNDC(.45, .20, text);\n", "}\n", "\n", "auto cnew = c.DrawClone();" ] }, { "cell_type": "markdown", "id": "7d1f4d52", "metadata": {}, "source": [ "Cleanup\n", "delete cnew;" ] }, { "cell_type": "markdown", "id": "359abfde", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 10, "id": "95694f1a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:53.502372Z", "iopub.status.busy": "2026-05-19T20:24:53.502244Z", "iopub.status.idle": "2026-05-19T20:24:53.709442Z", "shell.execute_reply": "2026-05-19T20:24:53.708801Z" } }, "outputs": [], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }