Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_valid_width_lifetime_conversions():
assert lifetime_to_width(1.5 * ps) / GeV == approx(4.388079676311604e-13)
assert 1.5 * ps * lifetime_to_width(1.5 * ps) == hbar
assert width_to_lifetime(hbar) == 1 * MeV
Parameters
----------
Gamma : float > 0
Particle decay width, typically in MeV (any HEP energy unit is OK).
Returns
-------
Particle lifetime, in the HEP standard time unit ns.
"""
if Gamma <= 0.:
raise ValueError( 'Input provided, %s <= 0!'.format(Gamma) )
# Just need to first make sure that the width is in the standard unit MeV
return hbar / float(Gamma / MeV)
0.001520119980246514
>>>
>>> width_to_lifetime(4.33e-4*eV) # result again returned in ns
0.001520119980246514
>>>
>>> width_to_lifetime(4.33e-10*MeV)/ps # result converted to ps
1.520119980246514
"""
if Gamma < 0.0:
raise ValueError("Input provided, {0} <= 0!".format(Gamma))
elif Gamma == 0:
return float("inf")
# Just need to first make sure that the width is in the standard unit MeV
return hbar / float(Gamma / MeV)