Skip to content

Instantly share code, notes, and snippets.

@cshimmin
Created June 19, 2014 06:12
Show Gist options
  • Save cshimmin/795278b4bc177367807e to your computer and use it in GitHub Desktop.
Save cshimmin/795278b4bc177367807e to your computer and use it in GitHub Desktop.
example of MC truth filtering using analysis_utils
import sys
import ROOT as r
from analysis_utils.root.dpd_object import get_objects, build_tlv
if __name__ == "__main__":
t = r.TChain("physics")
map(t.Add, sys.argv[1:])
for evt in t:
# pull lightweight 'objects' from the mc_* branches
truth_particles = get_objects(t, 'mc')
# select only the electrons
truth_electrons = [p for p in truth_particles if abs(p.pdgId)==11]
# require status == 3
final_electrons = [el for el in truth_electrons if el.status==3]
# require truth pt > 7 GeV
hard_electrons = [el for el in truth_electrons if el.pt > 7e3]
# require 2 such electrons
if not len(hard_electrons) >= 2: continue
# build a TLorentzVector from the (pt,eta,phi,m) for all electrons
map(build_tlv, hard_electrons)
# grab the first two and print some info:
el1, el2 = hard_electrons[:2]
print 'el1 pt=%d, eta=%.2f, phi=%.2f' % (el1.pt, el1.eta, el1.phi)
print 'el2 pt=%d, eta=%.2f, phi=%.2f' % (el2.pt, el2.eta, el2.phi)
# add up the tlv's for the electrons and print the inv. mass
electron_system = el1.tlv + el2.tlv
print "Electron system mass: ", electron_system.M()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment