...
 
Commits (2)
......@@ -59,7 +59,7 @@ parent particle.
.. code-block:: python
>>> parent = tau_1 + tau_2
>>> "%.2f" % abs(parent.m)
>>> "%.2f" % parent.m
'3150.21'
>>> "%.2f" % parent.eta
'0.00'
......
......@@ -66,7 +66,7 @@ parent particle.
.. doctest::
>>> parent = tau_1 + tau_2
>>> "%.2f" % abs(parent.m)
>>> "%.2f" % parent.m
'3150.21'
>>> "%.2f" % parent.eta
'0.00'
......
......@@ -208,7 +208,10 @@ class Vector4:
"""
Magnitude of vector.
"""
return cmath.sqrt(self.mag2)
mag = cmath.sqrt(self.mag2)
if mag.imag == 0:
return abs(mag)
return mag
@property
def mag2(self):
......@@ -296,13 +299,8 @@ class Vector4:
The method returns the transformed 4-vector.
"""
gamma = momentum.e / momentum.m
if gamma.imag != 0:
raise ValueError("Invalid boost momentum.")
gamma = abs(gamma)
return self.boost(*(-momentum.components)[1:], gamma=gamma)
return self.boost(*(-momentum.components)[1:],
gamma=momentum.e/momentum.m)
class Momentum4(Vector4):
"""
......
......@@ -84,3 +84,10 @@ class Momentum4TestCase(unittest.TestCase):
self.assertAlmostEqual(momentum.phi, 1.23)
self.assertAlmostEqual(momentum.m, 1.777)
self.assertAlmostEqual(momentum.e**2, momentum.p**2 + momentum.m**2)
def test_type_m(self):
"""
Check that the mass is real valued.
"""
momentum = Momentum4.e_m_eta_phi(2, 1.777, 2.5, 1.23)
self.assertIsInstance(momentum.m, float)