old_contents: #
  # Plot dimuon mass distribution for SWC HEP 2015
  #
  from ROOT import TFile, TH1D
  
  file_events = TFile("test_data/events.root")
  tree_events = file_events.Get("events")
  n_events = tree_events.GetEntries()
  print "Number of events = " + str(n_events)
  
  for i_event in xrange(n_events):
      tree_events.GetEntry(i_event)
      n_particles = tree_events.nPart
      print "Number of particles = " + str(n_particles)
  
  h = TH1D("hist_m", "dimuon mass", 100, 0, 200)
  h.Draw()
  
new_contents: #
  # Plot dimuon mass distribution for SWC HEP 2015
  #
  from ROOT import TFile, TH1D
  
  def tree_from_file(path):
      global file_events
      file_events = TFile(path)
      tree_events = file_events.Get("events")
      print type(tree_events)
      return tree_events
      
  def dimuon_masses(tree):
      n_events = tree.GetEntries()
      for i_event in xrange(n_events):
          tree.GetEntry(i_event)
          n_particles = tree.nPart
          print "Number of particles = " + str(n_particles)
      h = TH1D("hist_m", "dimuon mass", 100, 0, 200)
      return h
  
  tree_events = tree_from_file("test_data/events.root")
  print type(tree_events)
  hist_dimuon_mass = dimuon_masses(tree_events)
  hist_dimuon_mass.Draw()
subject: split code into functions