{ "cells": [ { "cell_type": "markdown", "id": "8ac798d6", "metadata": {}, "source": [ "# multidimfit\n", "Multi-Dimensional Parametrisation and Fitting\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun, Christian Holm Christensen \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:25 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "dea8836b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:10.784746Z", "iopub.status.busy": "2026-05-19T20:25:10.784630Z", "iopub.status.idle": "2026-05-19T20:25:10.791650Z", "shell.execute_reply": "2026-05-19T20:25:10.791246Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"Riostream.h\"\n", "#include \"TROOT.h\"\n", "#include \"TApplication.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TH1.h\"\n", "#include \"TSystem.h\"\n", "#include \"TBrowser.h\"\n", "#include \"TFile.h\"\n", "#include \"TRandom.h\"\n", "#include \"TMultiDimFit.h\"\n", "#include \"TVectorD.h\"\n", "#include \"TMath.h\"" ] }, { "cell_type": "markdown", "id": "6561715b", "metadata": {}, "source": [ " ____________________________________________________________________\n", " " ] }, { "cell_type": "code", "execution_count": 2, "id": "c1bd9fef", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:10.792778Z", "iopub.status.busy": "2026-05-19T20:25:10.792665Z", "iopub.status.idle": "2026-05-19T20:25:10.797261Z", "shell.execute_reply": "2026-05-19T20:25:10.796881Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void makeData(double* x, double& d, double& e)\n", "{\n", " // Make data points\n", " double upp[5] = { 10, 10, 10, 10, 1 };\n", " double low[5] = { 0, 0, 0, 0, .1 };\n", " for (int i = 0; i < 4; i++)\n", " x[i] = (upp[i] - low[i]) * gRandom->Rndm() + low[i];\n", "\n", " d = x[0] * TMath::Sqrt(x[1] * x[1] + x[2] * x[2] + x[3] * x[3]);\n", "\n", " e = gRandom->Gaus(upp[4],low[4]);\n", "}" ] }, { "cell_type": "markdown", "id": "7dd2ad23", "metadata": {}, "source": [ " ____________________________________________________________________\n", " " ] }, { "cell_type": "code", "execution_count": 3, "id": "62cad2df", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:10.798372Z", "iopub.status.busy": "2026-05-19T20:25:10.798262Z", "iopub.status.idle": "2026-05-19T20:25:10.806179Z", "shell.execute_reply": "2026-05-19T20:25:10.805802Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "int CompareResults(TMultiDimFit *fit, bool doFit)\n", "{\n", " //Compare results with reference run\n", "\n", "\n", " // the right coefficients (before fit)\n", " double GoodCoeffsNoFit[] = {\n", " -4.37056,\n", " 43.1468,\n", " 13.432,\n", " 13.4632,\n", " 13.3964,\n", " 13.328,\n", " 13.3016,\n", " 13.3519,\n", " 4.49724,\n", " 4.63876,\n", " 4.89036,\n", " -3.69982,\n", " -3.98618,\n", " -3.86195,\n", " 4.36054,\n", " -4.02597,\n", " 4.57037,\n", " 4.69845,\n", " 2.83819,\n", " -3.48855,\n", " -3.97612\n", " };\n", "\n", " // the right coefficients (after fit)\n", " double GoodCoeffs[] = {\n", " -4.399,\n", " 43.15,\n", " 13.41,\n", " 13.49,\n", " 13.4,\n", " 13.23,\n", " 13.34,\n", " 13.29,\n", " 4.523,\n", " 4.659,\n", " 4.948,\n", " -4.026,\n", " -4.045,\n", " -3.939,\n", " 4.421,\n", " -4.006,\n", " 4.626,\n", " 4.378,\n", " 3.516,\n", " -4.111,\n", " -3.823,\n", " };\n", "\n", " // Good Powers\n", " int GoodPower[] = {\n", " 1, 1, 1, 1,\n", " 2, 1, 1, 1,\n", " 1, 1, 1, 2,\n", " 1, 1, 2, 1,\n", " 1, 2, 1, 1,\n", " 2, 2, 1, 1,\n", " 2, 1, 1, 2,\n", " 2, 1, 2, 1,\n", " 1, 1, 1, 3,\n", " 1, 3, 1, 1,\n", " 1, 1, 5, 1,\n", " 1, 1, 2, 2,\n", " 1, 2, 1, 2,\n", " 1, 2, 2, 1,\n", " 2, 1, 1, 3,\n", " 2, 2, 1, 2,\n", " 2, 1, 3, 1,\n", " 2, 3, 1, 1,\n", " 1, 2, 2, 2,\n", " 2, 1, 2, 2,\n", " 2, 2, 2, 1\n", " };\n", "\n", " int nc = fit->GetNCoefficients();\n", " int nv = fit->GetNVariables();\n", " const int *powers = fit->GetPowers();\n", " const int *pindex = fit->GetPowerIndex();\n", " if (nc != 21) return 1;\n", " const TVectorD *coeffs = fit->GetCoefficients();\n", " int k = 0;\n", " for (int i=0;i 5e-5) return 2;\n", " }\n", " for (int j=0;jProcessLine(\".L MDF.C\");\n", "\n", " double refMDF = (doFit) ? 43.95 : 43.98;\n", " // this does not work in CLing since the function is not defined\n", " //double x[] = {5,5,5,5};\n", " //double rMDF = MDF(x);\n", " //LM: need to return the address of the result since it is casted to a long (this should not be in a tutorial !)\n", " std::intptr_t iret = gROOT->ProcessLine(\" double xvalues[] = {5,5,5,5}; double result=MDF(xvalues); &result;\");\n", " double rMDF = * ( (double*)iret);\n", " //printf(\"%f\\n\",rMDF);\n", " if (TMath::Abs(rMDF -refMDF) > 1e-2) return 4;\n", " return 0;\n", "}" ] }, { "cell_type": "markdown", "id": "552a2c37", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 4, "id": "c1bb424e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:10.807234Z", "iopub.status.busy": "2026-05-19T20:25:10.807121Z", "iopub.status.idle": "2026-05-19T20:25:11.127229Z", "shell.execute_reply": "2026-05-19T20:25:11.126765Z" } }, "outputs": [], "source": [ "bool doFit = true;" ] }, { "cell_type": "code", "execution_count": 5, "id": "a752ac82", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:11.128823Z", "iopub.status.busy": "2026-05-19T20:25:11.128697Z", "iopub.status.idle": "2026-05-19T20:25:11.335298Z", "shell.execute_reply": "2026-05-19T20:25:11.334865Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*************************************************\n", "* Multidimensional Fit *\n", "* *\n", "* By Christian Holm 14/10/00 *\n", "*************************************************\n", "\n" ] } ], "source": [ "std::cout << \"*************************************************\" << std::endl;\n", "std::cout << \"* Multidimensional Fit *\" << std::endl;\n", "std::cout << \"* *\" << std::endl;\n", "std::cout << \"* By Christian Holm 14/10/00 *\" << std::endl;\n", "std::cout << \"*************************************************\" << std::endl;\n", "std::cout << std::endl;" ] }, { "cell_type": "markdown", "id": "94a005ca", "metadata": {}, "source": [ "Initialize global TRannom object." ] }, { "cell_type": "code", "execution_count": 6, "id": "de3b4b09", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:11.336670Z", "iopub.status.busy": "2026-05-19T20:25:11.336474Z", "iopub.status.idle": "2026-05-19T20:25:11.563147Z", "shell.execute_reply": "2026-05-19T20:25:11.561715Z" } }, "outputs": [], "source": [ "gRandom = new TRandom();" ] }, { "cell_type": "markdown", "id": "35fc285c", "metadata": {}, "source": [ "Open output file" ] }, { "cell_type": "code", "execution_count": 7, "id": "906b0156", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:11.564984Z", "iopub.status.busy": "2026-05-19T20:25:11.564807Z", "iopub.status.idle": "2026-05-19T20:25:11.770880Z", "shell.execute_reply": "2026-05-19T20:25:11.769651Z" } }, "outputs": [], "source": [ "TFile* output = new TFile(\"mdf.root\", \"RECREATE\");" ] }, { "cell_type": "markdown", "id": "5f2ec95a", "metadata": {}, "source": [ "Global data parameters" ] }, { "cell_type": "code", "execution_count": 8, "id": "f3c148d6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:11.772489Z", "iopub.status.busy": "2026-05-19T20:25:11.772328Z", "iopub.status.idle": "2026-05-19T20:25:11.980684Z", "shell.execute_reply": "2026-05-19T20:25:11.979795Z" } }, "outputs": [], "source": [ "int nVars = 4;\n", "int nData = 500;\n", "double x[4];" ] }, { "cell_type": "markdown", "id": "d92949d1", "metadata": {}, "source": [ "make fit object and set parameters on it." ] }, { "cell_type": "code", "execution_count": 9, "id": "e1b7633a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:11.982038Z", "iopub.status.busy": "2026-05-19T20:25:11.981918Z", "iopub.status.idle": "2026-05-19T20:25:12.188644Z", "shell.execute_reply": "2026-05-19T20:25:12.187770Z" } }, "outputs": [], "source": [ "TMultiDimFit* fit = new TMultiDimFit(nVars, TMultiDimFit::kMonomials,\"v\");\n", "\n", "int mPowers[] = { 6 , 6, 6, 6 };\n", "fit->SetMaxPowers(mPowers);\n", "fit->SetMaxFunctions(1000);\n", "fit->SetMaxStudy(1000);\n", "fit->SetMaxTerms(30);\n", "fit->SetPowerLimit(1);\n", "fit->SetMinAngle(10);\n", "fit->SetMaxAngle(10);\n", "fit->SetMinRelativeError(.01);" ] }, { "cell_type": "markdown", "id": "5da78433", "metadata": {}, "source": [ "variables to hold the temporary input data" ] }, { "cell_type": "code", "execution_count": 10, "id": "f560d2f1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:12.190011Z", "iopub.status.busy": "2026-05-19T20:25:12.189892Z", "iopub.status.idle": "2026-05-19T20:25:12.396147Z", "shell.execute_reply": "2026-05-19T20:25:12.395738Z" } }, "outputs": [], "source": [ "double d;\n", "double e;" ] }, { "cell_type": "markdown", "id": "61456067", "metadata": {}, "source": [ "Print out the start parameters" ] }, { "cell_type": "code", "execution_count": 11, "id": "0775fa82", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:12.397908Z", "iopub.status.busy": "2026-05-19T20:25:12.397783Z", "iopub.status.idle": "2026-05-19T20:25:12.603621Z", "shell.execute_reply": "2026-05-19T20:25:12.602959Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "User parameters:\n", "----------------\n", " Variables: 4\n", " Data points: 0\n", " Max Terms: 30\n", " Power Limit Parameter: 1\n", " Max functions: 1000\n", " Max functions to study: 1000\n", " Max angle (optional): 10\n", " Min angle: 10\n", " Relative Error accepted: 0.01\n", " Maximum Powers: 6 6 6 6\n", "\n", " Parameterisation will be done using Monomials\n", "\n", "======================================\n" ] } ], "source": [ "fit->Print(\"p\");\n", "\n", "printf(\"======================================\\n\");" ] }, { "cell_type": "markdown", "id": "6f8aa6cc", "metadata": {}, "source": [ "Create training sample" ] }, { "cell_type": "code", "execution_count": 12, "id": "7a915951", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:12.604903Z", "iopub.status.busy": "2026-05-19T20:25:12.604782Z", "iopub.status.idle": "2026-05-19T20:25:12.807097Z", "shell.execute_reply": "2026-05-19T20:25:12.806245Z" } }, "outputs": [], "source": [ "int i;\n", "for (i = 0; i < nData ; i++) {\n", "\n", " // Make some data\n", " makeData(x,d,e);\n", "\n", " // Add the row to the fit object\n", " fit->AddRow(x,d,e);\n", "}" ] }, { "cell_type": "markdown", "id": "c867db36", "metadata": {}, "source": [ "Print out the statistics" ] }, { "cell_type": "code", "execution_count": 13, "id": "fe806f42", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:12.808459Z", "iopub.status.busy": "2026-05-19T20:25:12.808339Z", "iopub.status.idle": "2026-05-19T20:25:13.014455Z", "shell.execute_reply": "2026-05-19T20:25:13.013773Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sample statistics:\n", "------------------\n", " D 1 2 3 4\n", " Max: 141.6264 9.954 9.99 9.998 9.995\n", " Min: 0.149448 0.0455 0.01523 0.04109 0.003819\n", " Mean: 48.40441 5.033 5.044 5 5.002\n", " Function Sum Squares: 1.678e+06\n", "\n" ] } ], "source": [ "fit->Print(\"s\");" ] }, { "cell_type": "markdown", "id": "7a91c950", "metadata": {}, "source": [ "Book histograms" ] }, { "cell_type": "code", "execution_count": 14, "id": "f4335cf6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:13.015851Z", "iopub.status.busy": "2026-05-19T20:25:13.015725Z", "iopub.status.idle": "2026-05-19T20:25:13.222558Z", "shell.execute_reply": "2026-05-19T20:25:13.221629Z" } }, "outputs": [], "source": [ "fit->MakeHistograms();" ] }, { "cell_type": "markdown", "id": "b8c0b910", "metadata": {}, "source": [ "Find the parameterization" ] }, { "cell_type": "code", "execution_count": 15, "id": "fa67fcc7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:13.224019Z", "iopub.status.busy": "2026-05-19T20:25:13.223893Z", "iopub.status.idle": "2026-05-19T20:25:13.432640Z", "shell.execute_reply": "2026-05-19T20:25:13.431935Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Coeff SumSqRes Contrib Angle QM Func Value W^2 Powers\n", " 1 5.065e+05 2.886e-24 10 6.67e-07 0 -7.597e-14 500 0 0 0 0\n", " 2 1.15e+05 3.915e+05 50 0.167 2 47.33 174.7 1 0 0 0\n", " 3 8.755e+04 2.749e+04 80 0.167 1 13.26 156.3 0 0 0 1\n", " 4 6.188e+04 2.568e+04 80 0.167 3 12.39 167.3 0 0 1 0\n", " 5 3.708e+04 2.48e+04 80 0.167 4 12.6 156.3 0 1 0 0\n", " 6 2.596e+04 1.112e+04 85 0.333 8 14.91 50.03 1 1 0 0\n", " 7 1.667e+04 9290 85 0.333 9 13.02 54.78 1 0 0 1\n", " 8 7382 9287 85 0.333 14 12.64 58.13 1 0 1 0\n", " 9 6235 1147 87.5 0.333 5 5.095 44.16 0 0 0 2\n", " 10 5218 1018 87.5 0.333 12 4.983 40.99 0 2 0 0\n", " 11 4193 1025 87.5 0.667 53 5.229 37.5 0 0 4 0\n", " 12 3299 893.8 88.8 0.333 6 -4.058 54.27 0 0 1 1\n", " 13 2458 841.2 88.8 0.333 7 -4.155 48.73 0 1 0 1\n", " 14 1933 524.7 88.8 0.333 13 -3.291 48.45 0 1 1 0\n", " 15 1675 258.1 88.8 0.5 19 4.211 14.56 1 0 0 2\n", " 16 1334 340.6 88.8 0.5 26 -4.731 15.22 1 1 0 1\n", " 17 1079 255.5 88.8 0.5 33 3.953 16.35 1 0 2 0\n", " 18 788.2 290.4 88.8 0.5 34 4.687 13.22 1 2 0 0\n", " 19 709.2 78.94 89.4 0.5 21 2.23 15.88 0 1 1 1\n", " 20 473.4 235.8 89.4 0.5 23 -3.543 18.78 1 0 1 1\n", " 21 235.4 238 89.4 0.5 28 -3.976 15.06 1 1 1 0\n" ] } ], "source": [ "fit->FindParameterization();" ] }, { "cell_type": "markdown", "id": "263c1532", "metadata": {}, "source": [ "Print coefficents" ] }, { "cell_type": "code", "execution_count": 16, "id": "71948578", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:13.434023Z", "iopub.status.busy": "2026-05-19T20:25:13.433899Z", "iopub.status.idle": "2026-05-19T20:25:13.640791Z", "shell.execute_reply": "2026-05-19T20:25:13.640267Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Results of Parameterisation:\n", "----------------------------\n", " Total reduction of square residuals 5.063e+05\n", " Relative precision obtained: 0.01185\n", " Error obtained: 235.4\n", " Multiple correlation coefficient: 0.9995\n", " Reduced Chi square over sample: 0.4975\n", " Maximum residual value: 3.243\n", " Minimum residual value: -2.59\n", " Estimated root mean square: 0.6862\n", " Maximum powers used: 1 2 4 2 \n", " Function codes of candidate functions.\n", " 1: considered, 2: too little contribution, 3: accepted.\n", " 3333333333 1133311113 1313113131 1113311111 1111111111 1113111111\n", " 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111\n", " 111111\n", " Loop over candidates stopped because max allowed studies reached\n", "\n", "Coefficients:\n", "-------------\n", " # Value Error Powers\n", " ---------------------------------------\n", " 0 -4.371 0.08798 0 0 0 0\n", " 1 43.15 0.1601 1 0 0 0\n", " 2 13.43 0.08032 0 0 0 1\n", " 3 13.46 0.07805 0 0 1 0\n", " 4 13.4 0.08054 0 1 0 0\n", " 5 13.33 0.1423 1 1 0 0\n", " 6 13.3 0.1367 1 0 0 1\n", " 7 13.35 0.1331 1 0 1 0\n", " 8 4.497 0.1511 0 0 0 2\n", " 9 4.639 0.1585 0 2 0 0\n", " 10 4.89 0.164 0 0 4 0\n", " 11 -3.7 0.1364 0 0 1 1\n", " 12 -3.986 0.1438 0 1 0 1\n", " 13 -3.862 0.1458 0 1 1 0\n", " 14 4.361 0.2614 1 0 0 2\n", " 15 -4.026 0.2555 1 1 0 1\n", " 16 4.57 0.2477 1 0 2 0\n", " 17 4.698 0.2729 1 2 0 0\n", " 18 2.838 0.2525 0 1 1 1\n", " 19 -3.489 0.2292 1 0 1 1\n", " 20 -3.976 0.2566 1 1 1 0\n", "\n" ] } ], "source": [ "fit->Print(\"rc\");" ] }, { "cell_type": "markdown", "id": "8c2e9b8f", "metadata": {}, "source": [ "Get the min and max of variables from the training sample, used\n", "for cuts in test sample." ] }, { "cell_type": "code", "execution_count": 17, "id": "e4d10207", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:13.642201Z", "iopub.status.busy": "2026-05-19T20:25:13.642081Z", "iopub.status.idle": "2026-05-19T20:25:13.849406Z", "shell.execute_reply": "2026-05-19T20:25:13.848420Z" } }, "outputs": [], "source": [ "double *xMax = new double[nVars];\n", "double *xMin = new double[nVars];\n", "for (i = 0; i < nVars; i++) {\n", " xMax[i] = (*fit->GetMaxVariables())(i);\n", " xMin[i] = (*fit->GetMinVariables())(i);\n", "}\n", "\n", "nData = fit->GetNCoefficients() * 100;\n", "int j;" ] }, { "cell_type": "markdown", "id": "10abc4ec", "metadata": {}, "source": [ "Create test sample" ] }, { "cell_type": "code", "execution_count": 18, "id": "17720557", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:13.850805Z", "iopub.status.busy": "2026-05-19T20:25:13.850683Z", "iopub.status.idle": "2026-05-19T20:25:14.064795Z", "shell.execute_reply": "2026-05-19T20:25:14.064294Z" } }, "outputs": [], "source": [ "for (i = 0; i < nData ; i++) {\n", " // Make some data\n", " makeData(x,d,e);\n", "\n", " for (j = 0; j < nVars; j++)\n", " if (x[j] < xMin[j] || x[j] > xMax[j])\n", " break;\n", "\n", " // If we get through the loop above, all variables are in range\n", " if (j == nVars)\n", " // Add the row to the fit object\n", " fit->AddTestRow(x,d,e);\n", " else\n", " i--;\n", "}" ] }, { "cell_type": "markdown", "id": "d8963cc6", "metadata": {}, "source": [ "delete gRandom;" ] }, { "cell_type": "markdown", "id": "0ff7dfa0", "metadata": {}, "source": [ "Test the parameterizatio and coefficents using the test sample." ] }, { "cell_type": "code", "execution_count": 19, "id": "99c8013a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:14.067427Z", "iopub.status.busy": "2026-05-19T20:25:14.067304Z", "iopub.status.idle": "2026-05-19T20:25:14.815489Z", "shell.execute_reply": "2026-05-19T20:25:14.814900Z" } }, "outputs": [], "source": [ "if (doFit)\n", " fit->Fit(\"M\");" ] }, { "cell_type": "markdown", "id": "ac31a47a", "metadata": {}, "source": [ "Print result" ] }, { "cell_type": "code", "execution_count": 20, "id": "9e267788", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:14.817428Z", "iopub.status.busy": "2026-05-19T20:25:14.817303Z", "iopub.status.idle": "2026-05-19T20:25:15.023952Z", "shell.execute_reply": "2026-05-19T20:25:15.023459Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Results of Fit:\n", "---------------\n", " Test sample size: 2100\n", " Multiple correlation coefficient: 0.9994\n", " Relative precision obtained: 0.0001753\n", " Error obtained: 1275\n", " Reduced Chi square over sample: 2.47\n", "\n", " FCN=1 FROM MIGRAD STATUS=CONVERGED 861 CALLS 862 TOTAL\n", " EDM=1.67352e-06 STRATEGY= 1 ERROR MATRIX ACCURATE \n", " EXT PARAMETER PHYSICAL LIMITS \n", " NO. NAME VALUE ERROR NEGATIVE POSITIVE \n", " 1 coeff00 -4.39851e+00 4.44260e-02\n", " 2 coeff01 4.31493e+01 8.56451e-02\n", " 3 coeff02 1.34121e+01 3.78565e-02\n", " 4 coeff03 1.34869e+01 3.80951e-02\n", " 5 coeff04 1.33954e+01 3.74054e-02\n", " 6 coeff05 1.32280e+01 6.57916e-02\n", " 7 coeff06 1.33441e+01 6.75855e-02\n", " 8 coeff07 1.32943e+01 6.66410e-02\n", " 9 coeff08 4.52254e+00 7.39945e-02\n", " 10 coeff09 4.65912e+00 7.21745e-02\n", " 11 coeff10 4.94808e+00 8.14935e-02\n", " 12 coeff11 -4.02586e+00 6.53780e-02\n", " 13 coeff12 -4.04534e+00 6.55396e-02\n", " 14 coeff13 -3.93856e+00 6.51725e-02\n", " 15 coeff14 4.42141e+00 1.30526e-01\n", " 16 coeff15 -4.00581e+00 1.17191e-01\n", " 17 coeff16 4.62595e+00 1.30233e-01\n", " 18 coeff17 4.37782e+00 1.28579e-01\n", " 19 coeff18 3.51629e+00 1.13771e-01\n", " 20 coeff19 -4.11068e+00 1.17446e-01\n", " 21 coeff20 -3.82302e+00 1.16486e-01\n", "\n", "Coefficients:\n", "-------------\n", " # Value Error Powers\n", " ---------------------------------------\n", " 0 -4.399 0.04443 0 0 0 0\n", " 1 43.15 0.08565 1 0 0 0\n", " 2 13.41 0.03786 0 0 0 1\n", " 3 13.49 0.0381 0 0 1 0\n", " 4 13.4 0.03741 0 1 0 0\n", " 5 13.23 0.06579 1 1 0 0\n", " 6 13.34 0.06759 1 0 0 1\n", " 7 13.29 0.06664 1 0 1 0\n", " 8 4.523 0.07399 0 0 0 2\n", " 9 4.659 0.07217 0 2 0 0\n", " 10 4.948 0.08149 0 0 4 0\n", " 11 -4.026 0.06538 0 0 1 1\n", " 12 -4.045 0.06554 0 1 0 1\n", " 13 -3.939 0.06517 0 1 1 0\n", " 14 4.421 0.1305 1 0 0 2\n", " 15 -4.006 0.1172 1 1 0 1\n", " 16 4.626 0.1302 1 0 2 0\n", " 17 4.378 0.1286 1 2 0 0\n", " 18 3.516 0.1138 0 1 1 1\n", " 19 -4.111 0.1174 1 0 1 1\n", " 20 -3.823 0.1165 1 1 1 0\n", "\n" ] } ], "source": [ "fit->Print(\"fc v\");" ] }, { "cell_type": "markdown", "id": "a1acfda7", "metadata": {}, "source": [ "Write code to file" ] }, { "cell_type": "code", "execution_count": 21, "id": "099f4905", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:15.025968Z", "iopub.status.busy": "2026-05-19T20:25:15.025841Z", "iopub.status.idle": "2026-05-19T20:25:15.232848Z", "shell.execute_reply": "2026-05-19T20:25:15.232380Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing on file \"MDF.C\" ... done\n" ] } ], "source": [ "fit->MakeCode();" ] }, { "cell_type": "markdown", "id": "6df3eaba", "metadata": {}, "source": [ "Write histograms to disk, and close file" ] }, { "cell_type": "code", "execution_count": 22, "id": "36a4bdd8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:15.234316Z", "iopub.status.busy": "2026-05-19T20:25:15.234196Z", "iopub.status.idle": "2026-05-19T20:25:15.449045Z", "shell.execute_reply": "2026-05-19T20:25:15.446511Z" } }, "outputs": [], "source": [ "output->Write();\n", "output->Close();\n", "delete output;" ] }, { "cell_type": "markdown", "id": "f0fe0b38", "metadata": {}, "source": [ "Compare results with reference run" ] }, { "cell_type": "code", "execution_count": 23, "id": "b7d44de6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:15.450658Z", "iopub.status.busy": "2026-05-19T20:25:15.450516Z", "iopub.status.idle": "2026-05-19T20:25:15.652850Z", "shell.execute_reply": "2026-05-19T20:25:15.652370Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "multidimfit .............................................. OK\n" ] } ], "source": [ "int compare = CompareResults(fit, doFit);\n", "if (!compare) {\n", " printf(\"\\nmultidimfit .............................................. OK\\n\");\n", "} else {\n", " printf(\"\\nmultidimfit .............................................. fails case %d\\n\",compare);\n", "}" ] }, { "cell_type": "markdown", "id": "7c6949d2", "metadata": {}, "source": [ "We're done" ] }, { "cell_type": "code", "execution_count": 24, "id": "5582fa18", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:15.654336Z", "iopub.status.busy": "2026-05-19T20:25:15.654223Z", "iopub.status.idle": "2026-05-19T20:25:15.860770Z", "shell.execute_reply": "2026-05-19T20:25:15.860228Z" } }, "outputs": [], "source": [ "delete fit;\n", "delete [] xMin;\n", "delete [] xMax;\n", "return compare;" ] } ], "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 }