Created
June 19, 2014 06:12
-
-
Save cshimmin/49e9a35191dad8cf2318 to your computer and use it in GitHub Desktop.
example of MC truth filtering using analysis_utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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