Skip to content

Instantly share code, notes, and snippets.

@lukedeo
Created January 17, 2016 18:23
Show Gist options
  • Save lukedeo/ba7374634a38e5a3fac8 to your computer and use it in GitHub Desktop.
Save lukedeo/ba7374634a38e5a3fac8 to your computer and use it in GitHub Desktop.
Better jet object
from rootpy.vector import LorentzVector
class Jet(object):
"""
Better Jet Class!
Example:
>>> j = Jet(100.1, 1.2, 1.0, 12)
>>> j.lv.Pt()
100.1
>>> j.pt = 205
>>> j.lv.Pt()
205
"""
def __init__(self, pt, eta, phi, m):
super(Jet, self).__init__()
# -- make these guys hidden to most usage
self._pt = pt
self._eta = eta
self._phi = phi
self._m = m
# -- your fancy stuff
self.lv = LorentzVector()
self.lv.SetPtEtaPhiM(self._pt, self._eta, self._phi, self._m)
def _internal_update(self):
self.lv.SetPtEtaPhiM(self._pt, self._eta, self._phi, self._m)
@property
def pt(self):
return self._pt
@pt.setter
def pt(self, value):
self._pt = value
self._internal_update()
@property
def eta(self):
return self._eta
@eta.setter
def eta(self, value):
self._eta = value
self._internal_update()
@property
def phi(self):
return self._phi
@phi.setter
def phi(self, value):
self._phi = value
self._internal_update()
@property
def m(self):
return self._m
@m.setter
def m(self, value):
self._m = value
self._internal_update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment