{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# PyROOT Exercise 2: Graphs and Fits" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise\n", "\n", "Write a python macro `ExerciseGraph.py`.\n", "\n", "1. Create a graph with symmetric errors and 5 points.\n", "2. Set the following points:\n", " `(1.0, 2.1), (2.0, 2.9), (3.0, 4.05), (4.0, 5.2), (5.0, 5.95)`\n", "3. Set the errors on `x` to 0.0 and the errors on `y` to 0.1 (all at once).\n", "4. Draw the graph including the axes and error bars.\n", "5. Create a one dimensional function `f(x) = ax + b` and fit it to the graph.\n", "\n", "Bonus questions:\n", "1. Programatically obtain the two parameters `a` and `b` and their estimated uncertainties." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Solution" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Welcome to JupyROOT 6.28/00\n" ] } ], "source": [ "import ROOT\n", "%jsroot on" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a = 1.000000 +/- 0.031623\n", "b = 1.040000 +/- 0.104881\n", " FCN=5.7 FROM MIGRAD STATUS=CONVERGED 33 CALLS 34 TOTAL\n", " EDM=2.71359e-21 STRATEGY= 1 ERROR MATRIX ACCURATE \n", " EXT PARAMETER STEP FIRST \n", " NO. NAME VALUE ERROR SIZE DERIVATIVE \n", " 1 p0 1.00000e+00 3.16228e-02 1.70422e-05 -2.08465e-09\n", " 2 p1 1.04000e+00 1.04881e-01 5.65226e-05 -1.21781e-09\n" ] }, { "data": { "text/html": [ "\n", "\n", "