Skip to content

Commit

Permalink
refactor: deactivate default spin alignment (#295)
Browse files Browse the repository at this point in the history
`HelicityModelBuilder.align_spin` needs to be set explicitly to
activate spin alignment for multiple topologies.
  • Loading branch information
redeboer committed May 31, 2022
1 parent e4ad513 commit 7f3a794
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
22 changes: 19 additions & 3 deletions docs/usage/helicity/spin-alignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As described in {doc}`compwa-org:report/015`, the {doc}`'standard' helicity formalism </usage/helicity/formalism>` is not suited for state transitions that have different decay topologies. For this reason, the {class}`.HelicityAmplitudeBuilder` insert a number of Wigner-$D$ function into the amplitude model in case there is more than one underlying {class}`~qrules.topology.Topology`. It is easiest to see this by inspecting the resulting {attr}`.HelicityModel.intensity` and its {attr}`~.HelicityModel.amplitudes`:"
"As described in {doc}`compwa-org:report/015`, the {doc}`'standard' helicity formalism </usage/helicity/formalism>` is not suited for state transitions that have different decay topologies. For this reason, the {class}`.HelicityAmplitudeBuilder` can insert a number of Wigner-$D$ function into the amplitude model in case there is more than one underlying {class}`~qrules.topology.Topology`. It is easiest to see this by inspecting the resulting {attr}`.HelicityModel.intensity` and its {attr}`~.HelicityModel.amplitudes`:"
]
},
{
Expand Down Expand Up @@ -135,6 +135,13 @@
"graphviz.Source(dot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"'Spin alignment' can be now switched off or on by setting {attr}`.HelicityAmplitudeBuilder.align_spin`:"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -146,6 +153,7 @@
"outputs": [],
"source": [
"builder = ampform.get_builder(reaction)\n",
"builder.align_spin = True\n",
"model = builder.formulate()\n",
"model.intensity"
]
Expand Down Expand Up @@ -195,7 +203,7 @@
"source": [
"For more information about these angles, see {ref}`compwa-org:report/015:Compute Wigner rotation angles` in TR-015.\n",
"\n",
"Spin alignment can be switched off or on by setting {attr}`.HelicityAmplitudeBuilder.align_spin`:"
"By default, {attr}`~.HelicityAmplitudeBuilder.align_spin` is set to {obj}`False` and the total {attr}`.HelicityModel.intensity` does not contain alignment Wigner-$D$ functions:"
]
},
{
Expand All @@ -219,8 +227,16 @@
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.8.12"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
14 changes: 3 additions & 11 deletions src/ampform/helicity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

from .decay import (
TwoBodyDecay,
collect_topologies,
get_parent_id,
get_prefactor,
get_sibling_state_id,
Expand Down Expand Up @@ -518,7 +517,7 @@ def __init__(
self.__ingredients = _HelicityModelIngredients()
self.__dynamics_choices = DynamicsSelector(reaction)
self.__adapter = HelicityAdapter(reaction)
self.align_spin: bool | None = None
self.align_spin: bool = False
"""(De)activate :doc:`spin alignment </usage/helicity/spin-alignment>`."""
self.use_helicity_couplings: bool = False
"""Use helicity couplings instead of amplitude coefficients.
Expand Down Expand Up @@ -587,7 +586,7 @@ def formulate(self) -> HelicityModel:
self.__ingredients.reset()
main_intensity = self.__formulate_top_expression()
kinematic_variables = self.__adapter.create_expressions(
generate_wigner_angles=self.__is_align_spin
generate_wigner_angles=self.align_spin
)
if self.stable_final_state_ids is not None:
for state_id in self.stable_final_state_ids:
Expand Down Expand Up @@ -628,7 +627,7 @@ def __formulate_top_expression(self) -> PoolSum:
spin_projections[symbol].add(value)

topology_groups = group_by_topology(self.__reaction.transitions)
if self.__is_align_spin:
if self.align_spin:
amplitude = self.__formulate_aligned_amplitude(topology_groups)
else:
indices = list(spin_projections)
Expand Down Expand Up @@ -659,13 +658,6 @@ def __formulate_aligned_amplitude(
)
return amplitude

@property
def __is_align_spin(self) -> bool:
if self.align_spin is None:
topologies = collect_topologies(self.__reaction.transitions)
return len(topologies) > 1
return self.align_spin

def __register_amplitudes(
self, transition_group: list[StateTransition]
) -> None:
Expand Down
7 changes: 0 additions & 7 deletions src/ampform/helicity/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,6 @@ def is_opposite_helicity_state(topology: Topology, state_id: int) -> bool:
return tuple(state_fs_ids) > tuple(sibling_fs_ids)


@lru_cache(maxsize=None)
def collect_topologies(
transitions: tuple[StateTransition, ...]
) -> list[Topology]:
return sorted({t.topology for t in transitions})


def get_sibling_state_id(topology: Topology, state_id: int) -> int:
r"""Get the sibling state ID for a state in an isobar decay.
Expand Down

0 comments on commit 7f3a794

Please sign in to comment.