Trying to read and process some data from a ROOT file over the network. Using material from
Import the usual Matplotlib stuff for plotting histograms etc.
In [1]:
import pylab
import matplotlib.pyplot as plt
%matplotlib inline
pylab.rcParams['figure.figsize'] = 12,8
Import whatever classes we need from ROOT:
In [2]:
from ROOT import TChain, TFile
Create a "chain" of files (but just one file for now):
In [3]:
data = TChain("mini"); # "mini" is the name of the TTree stored in the data files
data.Add("http://atlas-opendata.web.cern.ch/atlas-opendata/release/samples/Data/DataMuons.root")
Out[3]:
Count the number of events in the data:
In [4]:
n_events = data.GetEntries()
print(n_events)
This is the list of "leaves" in the "tree", corresponding to bits of data stored for each event:
In [5]:
leaves = data.GetListOfLeaves()
for branch in leaves:
print branch.GetName()
This is how to read the first event into memory:
In [6]:
data.GetEntry(0)
Out[6]:
Let's look at some of the data from the first event. There is a list of variable names in the ATLAS Open Data documentation on the web. It doesn't state the units used, but it looks like momenta are in MeV. The names on the web also don't always match exactly the names in the data, so a bit of guesswork is required!
In [7]:
num_leptons = data.lep_n # number of identified leptons in the event
pt_lepton = data.lep_pt[0] # transverse momentum of the first lepton
print("Number of leptons = {}".format(num_leptons))
print("Pt of first lepton = {}".format(pt_lepton))
Let's construct a histogram of the missing transverse energy in each event, but just the first 1000 events for now so we're not waiting too long:
In [8]:
met = []
for event_num in xrange(1000):
data.GetEntry(event_num)
met.append(data.met_et)
In [9]:
plt.hist(met)
plt.xlabel('Missing Et [MeV]')
plt.ylabel('Events per bin')
Out[9]: