Skip to content

Commit

Permalink
Using namedtuple to contain the flavor transformations in chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheshuk committed Nov 22, 2024
1 parent 3629a90 commit c64fe1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 8 additions & 6 deletions python/snewpy/flavor_transformation/TransformationChain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
from .in_sn import SNTransformation
from .in_vacuum import VacuumTransformation, NoVacuumTransformation
from .in_earth import EarthTransformation, NoEarthMatter
from collections import namedtuple

#a tuple to hold the transformations list
TransformationsTuple = namedtuple('TransformationsTuple',['in_sn','in_vacuum','in_earth'])

class TransformationChain(FlavorTransformation):

r"""This class calculates the probability matrix :math:`P_{\beta\alpha}` of the :math:`\nu_\alpha\to\nu_\beta` flavor transition as multiplication of :math:`P^{SN}` transformation in SN, :math:`P^{Vac}` transformation in vacuum and :math:`P^{Earth}` transformation in Earth:
.. math::
Expand Down Expand Up @@ -42,10 +46,7 @@ def __init__(self,
Neutrino mixing parameters (to be applied to all individual transformations in chain)
By default use standard `MixingParameters` with normal neutrino ordering
"""
self.in_sn = in_sn
self.in_vacuum = in_vacuum
self.in_earth = in_earth
self.transforms = [in_sn, in_vacuum, in_earth]
self.transforms = TransformationsTuple(in_sn, in_vacuum, in_earth)
self.set_mixing_params(mixing_params)

def set_mixing_params(self, mixing_params):
Expand All @@ -61,8 +62,9 @@ def __call__(self, mixing_params):
return self

def P_ff(self, t, E)->FlavorMatrix:
in_sn, in_vacuum, in_earth = self.transforms
return in_earth.P_fm(t,E) @ in_vacuum.P_mm(t,E) @ in_sn.P_mf(t,E)
return self.transforms.in_earth.P_fm(t,E) @ \
self.transforms.in_vacuum.P_mm(t,E) @ \
self.transforms.in_sn.P_mf(t,E)

def __str__(self):
s = '+'.join([t.__class__.__name__ for t in self.transforms])+'_'+self.mixing_params.mass_order.name
Expand Down
20 changes: 10 additions & 10 deletions python/snewpy/test/test_04_xforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_AdiabaticMSWes_NMO(self):
xform = xforms.TransformationChain(xforms.in_sn.AdiabaticMSWes(), mixing_params=mixpars)
#test the probability matrix shape
U2 = xform.mixing_params.Pmf_HighDensityLimit().T
P_SN = xform.in_sn.P_mf(t,E)
P_SN = xform.transforms.in_sn.P_mf(t,E)
#check with eq (A48) from snewpy_v2.0 paper
assert np.allclose(P_SN['NU','NU'],
[[0, U2['mu','1'], U2['tau','1'],0],
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_AdiabaticMSWes_IMO(self):
xform = xforms.TransformationChain(xforms.in_sn.AdiabaticMSWes(), mixing_params=mixpars)
#test the probability matrix shape
U2 = xform.mixing_params.Pmf_HighDensityLimit().T
P_SN = xform.in_sn.P_mf(t,E)
P_SN = xform.transforms.in_sn.P_mf(t,E)
#check with eq (A50) from snewpy_v2.0 paper
assert np.allclose(P_SN['NU','NU'],
[[0, U2['mu','1'], U2['tau','1'],0],
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_NonAdiabaticMSWes_NMO(self):
xform = xforms.TransformationChain(xforms.in_sn.NonAdiabaticMSWes(), mixing_params=mixpars)
#test the probability matrix shape
U2 = xform.mixing_params.Pmf_HighDensityLimit().T
P_SN = xform.in_sn.P_mf(t,E)
P_SN = xform.transforms.in_sn.P_mf(t,E)
#check with eq (A52) from snewpy_v2.0 paper
assert np.allclose(P_SN['NU','NU'],
[[0, U2['mu','1'], U2['tau','1'],0],
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_NonAdiabaticMSWes_IMO(self):
xform = xforms.TransformationChain(xforms.in_sn.NonAdiabaticMSWes(), mixing_params=mixpars)
#test the probability matrix shape
U2 = xform.mixing_params.Pmf_HighDensityLimit().T
P_SN = xform.in_sn.P_mf(t,E)
P_SN = xform.transforms.in_sn.P_mf(t,E)
#check with eq (A54) from snewpy_v2.0 paper
assert np.allclose(P_SN['NU','NU'],
[[0, U2['mu','1'], U2['tau','1'],0],
Expand Down Expand Up @@ -354,7 +354,7 @@ def test_TwoFlavorDecoherence_NMO(self):

#test the probability matrix shape
U2 = xform.mixing_params.Pmf_HighDensityLimit().T
P_SN = xform.in_sn.P_mf(t,E)
P_SN = xform.transforms.in_sn.P_mf(t,E)
#check with eq (A29) from snewpy_v2.0 paper
assert np.allclose(P_SN['NU','NU'],
[
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_TwoFlavorDecoherence_IMO(self):
xform = xforms.TransformationChain(xforms.in_sn.TwoFlavorDecoherence(), mixing_params=mixpars)
#test the probability matrix shape
U2 = xform.mixing_params.Pmf_HighDensityLimit().T
P_SN = xform.in_sn.P_mf(t,E)
P_SN = xform.transforms.in_sn.P_mf(t,E)
#check with eq (A30) from snewpy_v2.0 paper
assert np.allclose(P_SN['NU_BAR','NU_BAR'],
[
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_NeutrinoDecay_NMO(self, t, E):
mixing_params=mixpars)

#test the probability matrix shape
P_V = xform.in_vacuum.P_mm(t,E[0])
P_V = xform.transforms.in_vacuum.P_mm(t,E[0])
#check with eq (8) from snewpy_v2.0 paper
assert np.allclose(P_V['NU','NU'],
[
Expand Down Expand Up @@ -503,7 +503,7 @@ def test_NeutrinoDecay_IMO(self, t, E):
in_vacuum=xforms.in_vacuum.NeutrinoDecay(mass=mass, tau=lifetime, dist=distance),
mixing_params=mixpars)
#test the probability matrix shape
P_V = xform.in_vacuum.P_mm(t,E[0])
P_V = xform.transforms.in_vacuum.P_mm(t,E[0])
#check with eq (9) from snewpy_v2.0 paper
assert np.allclose(P_V['NU_BAR','NU_BAR'],
[
Expand Down Expand Up @@ -557,7 +557,7 @@ def test_QuantumDecoherence_NMO(self, t, E):
E0=energy_ref),
mixing_params=mixpars)
#check the flavor transformation matrix
Pmm = xform.in_vacuum.P_mm(t, E)
Pmm = xform.transforms.in_vacuum.P_mm(t, E)
x = (E/energy_ref)**n
# Test computation survival and transition probabilities of mass states.
#check with the formulas (10-13) in snewpy v2.0 paper
Expand Down Expand Up @@ -628,7 +628,7 @@ def test_QuantumDecoherence_IMO(self, t, E):
E0=energy_ref),
mixing_params=mixpars)
#check the flavor transformation matrix
Pmm = xform.in_vacuum.P_mm(t, E)
Pmm = xform.transforms.in_vacuum.P_mm(t, E)
x = (E/energy_ref)**n
# Test computation survival and transition probabilities of mass states.
#check with the formulas (10-13) in snewpy v2.0 paper
Expand Down

0 comments on commit c64fe1f

Please sign in to comment.