ComPWA / ampform

Automatically generate symbolic amplitude models for Partial Wave Analysis
https://ampform.rtfd.io
Apache License 2.0
11 stars 6 forks source link

Remove QRules from interface #281

Open redeboer opened 2 years ago

redeboer commented 2 years ago

It would be better if AmpForm modules can be built from an internal data structure, just like is happening in https://github.com/ComPWA/compwa-org/pull/129 and https://github.com/ComPWA/compwa-org/pull/133 (see in particular https://github.com/ComPWA/compwa-org/pull/133#issuecomment-1104053626). That would make it easier to build up an amplitude model without having to generate all transitions with QRules. A problem with QRules is that its Transition class is too general for isobar decays, which makes the amplitude building code clunky.

So we need a data structure that:

  1. contains all information about an isobar decay that's required to formulate a complete amplitude model, including:
    • polarizations (helicities) of initial state and final states
    • resonances and their decay products (particularly the final state products to which they decay)
    • (?) spectator particles of those resonances
    • optional: LS-couplings
    • ...?
  2. is easy to navigate over while building up the amplitude expression
  3. is easy to construct for users
redeboer commented 2 years ago

Some idea:

from typing import Generic

from attrs import frozen

State = TypeVar("State")
Interaction = TypeVar("Interaction")

@frozen
class IsobarNode(Generic[State, Interaction]):
    parent: State
    child1: State | IsobarNode
    child2: State | IsobarNode
    interaction: Interaction | None = field(default=None)

    @property
    def children(self) -> tuple[State, ...]:
        def flatten(
            obj: State | IsobarNode[State, Interaction]
        ) -> Sequence[State]:
            if isinstance(obj, IsobarNode):
                return obj.children
            return [obj]

        return (*flatten(self.child1), *flatten(self.child2))

where State and Interaction could be further specified with e.g.:

import sympy as sp

@frozen
class Particle:  # State
    name: str
    spin: sp.Rational
    # polarization: sp.Rational  # (?)
    parity: int

@frozen
class LSCoupling:  # Interaction
    L: int
    S: sp.Rational