{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"\n",
"# Plotting the invariant mass histogram"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
" \n",
"\n",
"\n",
"! Read the instructions first !\n",
"\n",
"In this exercise we will learn how to use Python-programming to plot a histogram and analyse it. We use a dataset collected by the CMS detector in 2011 [1]. The data consists of such events, where two muons were created in a collision. We want to plot a histogram of the invariant mass of the two muons created in the collision. Events with specific criteria [2] have been selected in the CSV file _Ymumu_\\__Run2011A.csv_ which we are using.\n",
"\n",
"Explore the different code cells below and run the codes by clicking the code cell active and pressing the _Run_-button. In the code cells the lines which begin with #-character are comment lines, which will tell you what the actual code does. Other lines are code lines. To gain a better understanding of the code, read the comment lines carefully.\n",
"\n",
"At first you should run the demonstration cells through. After that you can try to write code yourself and plot a histogram from a different dataset.\n",
"\n",
"Note that you can also modify text cells (Markdown cells) by double-clicking them. Text cells support markdown and HTML text. After you are done modifying a text cell, you can run it just like a code cell.\n",
"
\n",
"
\n",
"[1] CMS collaboration (2016). DoubleMu primary dataset in AOD format from RunA of 2011 (/DoubleMu/Run2011A-12Oct2013-v1/AOD). CERN Open Data Portal. DOI: [10.7483/OPENDATA.CMS.RZ34.QR6N](http://doi.org/10.7483/OPENDATA.CMS.RZ34.QR6N).\n",
"
\n",
"[2] Thomas McCauley (2016). Ymumu. Jupyter Notebook file. https://github.com/tpmccauley/cmsopendata-jupyter/blob/hst-0.1/Ymumu.ipynb."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1) Start"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# First we need to import the modules needed to do data-analysis using Python.\n",
"# Pandas-module is needed to read the csv-file.\n",
"# Matplotlib.pylab-module is needed to make plots.\n",
"# Modules are named as pd and plt so that we don't have to write the whole name in the future.\n",
"import pandas as pd\n",
"import matplotlib.pylab as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2) Reading the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Read the file \"Ymumu_Run2011A.csv\" and save the content to a variable called \"dataset\"\n",
"dataset = pd.read_csv(\"https://raw.githubusercontent.com/cms-opendata-education/cms-jupyter-materials-english/master/Data/Ymumu_Run2011A.csv\")\n",
"\n",
"# Let's see what our datafile contains. You can read more lines by inserting a number in\n",
"# parenthesis. The default is 5 lines.\n",
"dataset.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# We want to make a histogram of the invariant masses, which can be found in the column \"M\". \n",
"# Let's save the column \"M\" from the \"dataset\" to the variable \"invariant_mass\".\n",
"invariant_mass = dataset['M']\n",
"\n",
"# Furthermore let's see how many values of invariant masses we have in the variable \"invariant_mass\"\n",
"print(len(invariant_mass))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3) Presenting the data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can create and plot the histogram from the values of the invariant masses that we got. Histogram consists of multiple bins. Each bin shows how many events occured in the corresponding range of invariant mass. Note that we will use a total of 500 bins in the histogram, so it is hard to see separate bins because there are so many of them. You can also change the number of bins and see how the figure looks like."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot the histogram with the function hist() of the matplotlib.pylab-module\n",
"# \"bins\" determines the number of the bins used in the histogram.\n",
"plt.hist(invariant_mass, bins=500)\n",
"\n",
"# Name the axes and give the title.\n",
"plt.xlabel('Invariant mass [GeV]')\n",
"plt.ylabel('Number of events')\n",
"plt.title('The histogram of the invariant masses of two muons')\n",
"\n",
"# Show the plot.\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4) Analysis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- What does the histogram tell us?\n",
"- What happens around the invariant mass of 9.5 GeV?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5) Exercise"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. The following datafile contains data from similar events than the one we already plotted, but it has a wider range of invariant masses Use this datafile to make a similar histogram than in the demonstration.\n",
"\n",
"