{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# ROOT Basics\n", "## Import Required Modules and Turn on Javascript" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "\n", "require(['notebook'],\n", " function() {\n", " IPython.CodeCell.config_defaults.highlight_modes['magic_text/x-c++src'] = {'reg':[/^%%cpp/]};\n", " console.log(\"JupyROOT - %%cpp magic configured\");\n", " }\n", ");\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Welcome to JupyROOT 6.07/07\n" ] } ], "source": [ "from ROOT import TFile, TCanvas, TH1F\n", "\n", "%jsroot on" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Open a Data File" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "file = TFile(\"opendata/data/Dimuons.root\",\"READ\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Declare a Histogram\n", "### Histogram is a Graphical Way to Visualize Data\n", "\n", "#### Divide Data into Equal Intervals (Bins) and Count How Many Values in Each Bin\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example Histogram of Distribution of Muon Charges" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [], "source": [ "histogram = TH1F(\"Muon1_Charge\",\"Muon1_Charge\", 50, -2, 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### declaration format: TH1F(name, title, number of bins, min value, max value)\n", "## ROOT Exercise 1: \n", "## Declare another histogram for x-component of muon momentum called Muon1_Px\n" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "" ] } ], "source": [ "histogram2 = TH1F(\"Muon1_Px\",\"Muon1_Px\", 100, -60, 60)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loop Over Events in Data File" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fill the histogram with muon charge values (+1 or -1)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [], "source": [ "for dimuon in file.Dimuons:\n", " \n", " histogram.Fill(dimuon.Muon1_Charge) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Draw a Histogram on a Canvas" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "