{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Simple pyROOT notebook example using TLorentz Vectors

" ] }, { "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": "code", "execution_count": 2, "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": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "c = ROOT.TCanvas(\"testCanvas\",\"a first way to plot a variable\",800,600)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "t = f.Get(\"mini\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "h = ROOT.TH1F(\"variable\",\"Example plot: Number of Leptons\",4,0,4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "h_Mll = ROOT.TH1F(\"h_Mll\",\"Invariant mass of the two Leptons\",50,0,200)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for event in t:\n", " \"\"\"This is the cut #1: request at least 2 leptons\"\"\"\n", " if t.lep_n > 1:\n", " \"\"\"Let's define one TLorentz vector for each, e.i. two vectors!\"\"\"\n", " leadingLep = ROOT.TLorentzVector(t.lep_pt[0], t.lep_eta[0], t.lep_phi[0], t.lep_E[0])\n", " secondLep = ROOT.TLorentzVector(t.lep_pt[1], t.lep_eta[1], t.lep_phi[1], t.lep_E[1])\n", "\n", " \"\"\"Next line does the addition of the two TLorentz vectors above and so,\n", " we can ask the mass very easy\"\"\"\n", " TL_ll = leadingLep + secondLep\n", " \n", " \"\"\"We devide the value of the combined vector by 1000 to get the value in GeV\"\"\"\n", " mll = TL_ll.M()/1000.\n", " h_Mll.Fill(mll,w)\n", "\n", "print \"Done!\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Now les't plot the mass of the lepton-lepton system\"\"\"\n", "h_Mll.Draw()\n", "c.Draw()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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": 1 }