{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# A more difficult notebook in python\n", "\n", "### In this notebook you can find a more difficult program that shows further high energy physics (HEP) analysis techniques.\n", "\n", "##### The following analysis is searching for events where [Z bosons](https://en.wikipedia.org/wiki/W_and_Z_bosons) decay to two leptons of same flavour and opposite charge (to be seen for example in the [Feynman diagram](https://en.wikipedia.org/wiki/Feynman_diagram))." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First of all - like we did it in the first notebook - ROOT is imported to read the files in the _.root_ data format." ] }, { "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. As described above the data is stored in a _*.root_ file." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "f = ROOT.TFile.Open(\"mc_105986.ZZ.root\")\n", "#f = ROOT.TFile.Open(\"mc_147770.Zee.root\")\n", "#f = ROOT.TFile.Open(\"http://opendata.atlas.cern/release/samples/MC/mc_147770.Zee.root\")" ] }, { "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 _c_. The two following arguments define the width and the height of the canvas." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "canvas = ROOT.TCanvas(\"Canvas\",\"c\",800,600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next step is to define a tree named _t_ to get the data out of the _.root_ file." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "tree = f.Get(\"mini\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we define a histogram that will later be placed on this canvas. Its name is _variable_, the header of the histogram is _Mass of the Z boson_, the x axis is named _mass [GeV]_ and the y axis is named _events_. The three following arguments indicate that this histogram contains 30 bins which have a range from 40 to 140." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "hist = ROOT.TH1F(\"variable\",\"Mass of the Z boson; mass [GeV]; events\",30,40,140)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Time to fill our above defined histogram. At first we define some variables and then we loop over the data. We also make some cuts as you can see in the # _comments_." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "leadLepton = ROOT.TLorentzVector()\n", "trailLepton = ROOT.TLorentzVector()\n", "\n", "for event in tree:\n", " \n", " # Cut #1: At least 2 leptons\n", " if tree.lep_n == 2:\n", " \n", " # Cut #2: Leptons with opposite charge\n", " if (tree.lep_charge[0] != tree.lep_charge[1]):\n", " \n", " # Cut #3: Leptons of the same family (2 electrons or 2 muons)\n", " if (tree.lep_type[0] == tree.lep_type[1]):\n", " \n", " # Let's define one TLorentz vector for each, e.i. two vectors!\n", " leadLepton.SetPtEtaPhiE(tree.lep_pt[0]/1000., tree.lep_eta[0], tree.lep_phi[0], tree.lep_E[0]/1000.)\n", " trailLepton.SetPtEtaPhiE(tree.lep_pt[1]/1000., tree.lep_eta[1], tree.lep_phi[1], tree.lep_E[1]/1000.)\n", " # Next line: addition of two TLorentz vectors above --> ask mass very easy (devide by 1000 to get value in GeV)\n", " invmass = leadLepton + trailLepton\n", " \n", " hist.Fill(invmass.M())" ] }, { "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": [], "source": [ "hist.Draw()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "canvas.Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }