{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
In this notebook you can find an easy set of commands that show some basic computing techniques commonly used in High Energy Physics (HEP) analyzes.
\n", "\n", "It also shows how to create an histogram, fill it and draw it. Moreover it is an introduction to ROOT too. The final output is a plot with the number of leptons.
\n", "\n", "Check the description of the varibles inside the dataset at the end of this notebook
\n", "\n", "All done with less that 15 lines of code!
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a notebook using the ROOT Prompt kernel that using c++ language, is intended to show the internal content and the way to call and interact with the datasets released by the ATLAS experiment with focus in Education and Training activities:
\n", "\n", "\n", "\n", "where physics objects can be represented as below
\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First of all ROOT is imported to read the files in the _.root_ data format. A _.root_ file consists of a tree having branches and leaves.
\n", "At this point you could also import further programs that contain other formulas that you maybe use more often. But here we don't import other programs to keep it simple.
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "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.08/04\n" ] } ], "source": [ "import ROOT" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to activate the interactive visualisation of the histogram that is later created we can use the JSROOT magic:
" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%jsroot on" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we have to open the data that we want to analyze. It is stored in a _*.root_ file that consists of a tree having branches and leaves.
\n", "As you can see, we are reading the data directly from the source! but you can read the file locally too.
" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "f = ROOT.TFile.Open(\"http://opendata.atlas.cern/release/samples/MC/mc_147770.Zee.root\")\n", "## f = ROOT.TFile.Open(\"mc_105986.ZZ.root\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next step is to define a tree named (we called _tree_) to get the data out of the _*.root_ file, that is into a tree called _mini_:
" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "tree = f.Get(\"mini\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After the data is opened we create a canvas on which we can draw a histogram. If we do not have a canvas we cannot see our histogram at the end. Its name is _Canvas_ and its header is _a first way to plot a variable_. The two following arguments define the width and the height of the canvas.
" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "canvas = ROOT.TCanvas(\"Canvas\",\"a first way to plot a variable\",800,600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we define a histogram that will later be placed on this canvas. Its name is _variable_ and the header of the histogram is _Example plot: Number of leptons_. The three following arguments indicate that this histogram contains 4 so called bins which have a range from 0 to 4.
" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "hist = ROOT.TH1F(\"variable\",\"Example plot: Number of leptons\",4,0,4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following lines are a loop that goes over the data that is stored in the tree and fills the histogram _h_ that we already defined. In this first notebook we don't do any cuts to keep it simple. Accordingly the loop fills the histogram for each event stored in the tree. After the program has looped over all the data it prints the word
\n", "__Done!__." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done!\n" ] } ], "source": [ "for event in tree:\n", " hist.Fill(tree.lep_n)\n", " \n", "print \"Done!\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After filling the histogram we want to see the results of the analysis. First we draw the histogram on the canvas and then the canvas on which the histogram lies:
" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "...
" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "scale = hist.Integral()\n", "hist.Scale(1/scale)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...
" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "