These commands give us access to some tools for plotting histograms and other graphs:


In [1]:
import pylab
import matplotlib.pyplot as plt
%matplotlib inline
pylab.rcParams['figure.figsize'] = 12,8

This command opens the file. You may have to edit it to reflect the actual name of the file containing your results:


In [2]:
data_file = open('Invariant_Masses.txt')

In [3]:
masses = []                      # Create an empty list, ready to store the invariant masses
for line in data_file:           # Loop over each line in the file
    mass, channel = line.split() # Each line contains a mass (in GeV) and a "channel" (m for mu+mu-, etc.)
    m = float(mass)              # Mass is read in as a string, but we need to interpret it as a (floating point) number
    masses.append(m)             # Add the mass from this line to the list of masses

Print the list of masses, just to make sure it looks sensible:


In [4]:
print(masses)


[121.33243250466965, 2.545028134530284, 997.277809458241, 91.29896757132627, 11.001061853556504, 102.98656285181453]

If it looks OK, we can try plotting the results as a histogram:


In [5]:
plt.hist(masses, bins=100, range=(0,200))
plt.xlim(0,200)
plt.xlabel('Mass [GeV]')


Out[5]:
<matplotlib.text.Text at 0x7f46e1519490>

To present our data better, there are various tricks we can try. See Basic Data Plotting with Matplotlib Part 3: Histograms for some possibilities.


In [ ]: