{ "cells": [ { "cell_type": "markdown", "id": "d9699c6f", "metadata": {}, "source": [ "# fitCircle\n", "Generate points distributed with some errors around a circle\n", "Fit a circle through the points and draw\n", "To run the script, do, eg\n", "\n", "```cpp\n", " root > .x fitCircle.C (10000 points by default)\n", " root > .x fitCircle.C(100); (with only 100 points\n", " root > .x fitCircle.C++(100000); with ACLIC\n", "```\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \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": "code", "execution_count": 1, "id": "16304ffa", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:45.049874Z", "iopub.status.busy": "2026-05-19T20:24:45.049728Z", "iopub.status.idle": "2026-05-19T20:24:45.052985Z", "shell.execute_reply": "2026-05-19T20:24:45.052308Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"TCanvas.h\"\n", "#include \"TRandom3.h\"\n", "#include \"TGraph.h\"\n", "#include \"TMath.h\"\n", "#include \"TArc.h\"\n", "#include \"Fit/Fitter.h\"\n", "#include " ] }, { "cell_type": "markdown", "id": "deebbf4d", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 2, "id": "1b8bdcd9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:45.058462Z", "iopub.status.busy": "2026-05-19T20:24:45.058320Z", "iopub.status.idle": "2026-05-19T20:24:45.387277Z", "shell.execute_reply": "2026-05-19T20:24:45.386836Z" } }, "outputs": [], "source": [ "int n=10000;" ] }, { "cell_type": "markdown", "id": "0e961e1b", "metadata": {}, "source": [ "generates n points around a circle and fit them" ] }, { "cell_type": "code", "execution_count": 3, "id": "7fbeb6d4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:45.394346Z", "iopub.status.busy": "2026-05-19T20:24:45.394215Z", "iopub.status.idle": "2026-05-19T20:24:45.700932Z", "shell.execute_reply": "2026-05-19T20:24:45.699944Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "TCanvas *c1 = new TCanvas(\"c1\",\"c1\",600,600);\n", "c1->SetGrid();\n", "TGraph* gr = new TGraph(n);\n", "if (n> 999) gr->SetMarkerStyle(1);\n", "else gr->SetMarkerStyle(3);\n", "TRandom3 r;\n", "double x,y;\n", "for (int i=0;iSetPoint(i,x,y);\n", "}\n", "c1->DrawFrame(-5,-5,5,5);\n", "gr->Draw(\"p\");\n", "\n", "\n", "auto chi2Function = [&](const double *par) {\n", " //minimisation function computing the sum of squares of residuals\n", " // looping at the graph points\n", " int np = gr->GetN();\n", " double f = 0;\n", " double *x = gr->GetX();\n", " double *y = gr->GetY();\n", " for (int i=0;iSetLineColor(kRed);\n", "arc->SetLineWidth(4);\n", "arc->SetFillStyle(0);\n", "arc->Draw();" ] }, { "cell_type": "markdown", "id": "bbf9ccd7", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 7, "id": "15fe4d2a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:46.398205Z", "iopub.status.busy": "2026-05-19T20:24:46.398083Z", "iopub.status.idle": "2026-05-19T20:24:46.604245Z", "shell.execute_reply": "2026-05-19T20:24:46.603707Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "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 }