Created
August 9, 2018 14:49
-
-
Save benkrikler/e300722832a9bb1e5a01bb5f87edc822 to your computer and use it in GitHub Desktop.
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
from math import pi, cos, sin, sinh, sqrt, asinh, atan2, fabs | |
class LorentzVector(object): | |
def __init__(self, x, y, z, T, r2=None): | |
self.x = x | |
self.y = y | |
self.z = z | |
self.T = T | |
if r2: | |
self.__r2 = r2 | |
else: | |
self.__r2 = x**2 + y**2 + z**2 | |
@classmethod | |
def fromPtEtaPhiM(self, pt, eta, phi, mass): | |
sinh_eta = sinh(eta) | |
x = pt * cos(phi) | |
y = pt * sin(phi) | |
z = pt * sinh_eta | |
r2 = pt**2*(1. + sinh_eta**2) | |
T = sqrt(r2 + mass**2) | |
return LorentzVector(x, y, z, T, r2) | |
@property | |
def r2(self): | |
return self.__r2 | |
@property | |
def Pt2(self): | |
return self.__r2 - self.z**2 | |
@property | |
def mass(self): | |
return sqrt(self.T**2 - self.__r2) | |
@property | |
def phi(self): | |
return atan2(self.y, self.x) | |
@property | |
def eta(self): | |
return asinh(self.z/sqrt(self.Pt2)) | |
def __add__(self, rhs): | |
return LorentzVector(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z, self.T + rhs.T) | |
def __sub__(self, rhs): | |
return LorentzVector(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z, self.T - rhs.T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To calculate the dijet invariant mass: