pyhs3.distributions.RelativisticBreitWignerDist¶
- class pyhs3.distributions.RelativisticBreitWignerDist(**data)[source]¶
Relativistic Breit-Wigner distribution for a resonance in a two-body mass spectrum.
Implements the HS3 line shape for the invariant mass \(m\) of the observed two-particle system, with the resonance coupled to a list of two-body channels (the first is the observed final state). For \(m > m_{1,1} + m_{2,1}\):
\[f(m) \propto \frac{m\,\Gamma_1(m)} {\left| m_\text{BW}^2 - m^2 - i\,m_\text{BW}\,\Gamma(m) \right|^2}, \qquad \Gamma(m) = \sum_i \Gamma_i(m)\]and \(f(m) = 0\) below the observed channel’s threshold. Each channel contributes
\[\Gamma_i(m) = \Gamma_{\text{BW},i}\; n_{l_i}^2(m)\; \rho_i(m), \quad \rho_i = \frac{2 q_i}{m}, \quad n_{l}^2 = z^{2l} h_l^2(z), \quad z = q_i R_i,\]with breakup momentum
\[q_i(m) = \frac{\sqrt{\left(m^2 - (m_{1i}+m_{2i})^2\right) \left(m^2 - (m_{1i}-m_{2i})^2\right)}}{2m}\]and Blatt-Weisskopf factors \(h_l^2(z) = 1/(P_l(z)P_l(-z))\), \(P_0 = 1\), \(P_1 = 1 - iz\), \(P_{l+1} = (2l+1)P_l - z^2 P_{l-1}\) (for example \(h_1^2 = 1/(1+z^2)\)).
Channels that are closed at \(m\) still enter the denominator: their breakup momentum is continued analytically to \(q = +i\sqrt{-q^2}\) between \(|m_{1}-m_{2}|\) and \(m_{1}+m_{2}\), and \(q\) is negative real below \(|m_{1}-m_{2}|\). This implementation evaluates the complex width in real arithmetic: open channels contribute to \(\mathrm{Re}\,\Gamma\) and continued channels to \(\mathrm{Im}\,\Gamma\), so the denominator is \((m_\text{BW}^2 - m^2 + m_\text{BW}\,\mathrm{Im}\,\Gamma)^2 + (m_\text{BW}\,\mathrm{Re}\,\Gamma)^2\).
The density is normalized over the observable’s domain by the standard automatic normalization (64-point Gauss-Legendre quadrature, see PDF Normalization). The line shape has a square-root onset at the observed channel’s threshold, which the quadrature resolves poorly if the threshold lies inside the domain; start the domain at or above the threshold.
- Parameters:
mass (str) – Name of the observable mass variable \(m\).
resonance (str | float) – Nominal mass \(m_\text{BW}\) (strictly positive; not in general the pole mass).
channels (list[RelativisticBreitWignerChannel]) – Non-empty list of channels, observed channel first. The first channel’s
Gammamust be strictly positive.
Note
Following HS3,
Gammais a width coefficient, not the partial width at the nominal mass: no division by the phase space at \(m_\text{BW}\) is made, unlike the nominal-partial-width convention of Eq. (50.35) in the PDG review. The density carries the factor \(m\) (the Jacobian from \(m^2\) to \(m\)) and no mass-dependent production factors, so it differs from ROOT’sRooBreitWigner(a constant-width, non-relativistic Cauchy shape) and from ROOT’sRooRelBreitWigner, which uses its own parametrization of the running width and barrier factors.HS3 Reference
relativistic_breit_wigner_dist
- Parameters:
data (
Any)
Fields¶ Field
Type
Required
Default
Constraints
Yes
min_length=1
Yes
Yes
Yes
Literal[‘relativistic_breit_wigner_dist’]No
'relativistic_breit_wigner_dist'- __init__(**data)¶
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (
Any)
Methods
expression(context)Evaluate and return a named PyTensor expression.
extended_likelihood(_context[, _data])Extended likelihood contribution in normal space.
get_parameter_list(context, param_key)Reconstruct a parameter list from flattened indexed keys.
likelihood(context)Builds a symbolic expression for the unnormalized relativistic Breit-Wigner density.
log_expression(context)Log-probability combining main likelihood with extended terms.
log_likelihood(context)Log-space counterpart of
likelihood().log_prob_terms(_expressions, ...)Structured contributions of this distribution to the joint log-likelihood.
model_post_init(context, /)This function is meant to behave like a BaseModel method to initialise private attributes.
normalization_expression(_context, ...)Return the antiderivative expression, or None for numerical fallback.
process_parameter(param_key)Process a single parameter that can be either a string reference or numeric value.
process_parameter_list(param_key)Process a list parameter containing mixed string references and numeric values.
Identity of this distribution's expression, independent of its name.
Parameters this distribution scales a positive yield with but does not constrain.
Attributes
Dictionary of PyTensor constants generated from numeric field values.
Set of parameter names this component depends on.
Whether two distributions of this class that are equal in every field except
namemay share one built expression (seestructural_key()).
- RelativisticBreitWignerDist.expression(context)¶
Evaluate and return a named PyTensor expression.
This is a template method that calls
_expression()to get the result, then names the result before returning._expression()may return a tensor it does not own — for example a single-summandSumFunctionor a single-factorProductFunctionreturnscontext[param]directly, which is the same tensor object stored inmodel.parameters. Renaming such a shared tensor in place would silently corrupt the parameter it borrows (e.g.model.parameters['mu']would be renamed to the function’s name). To avoid this, a result that already carries a different name is wrapped in a fresh identity copy before being renamed; freshly built (unnamed) expressions are named in place as before so that compilation andgraph_summarykeep working.
- RelativisticBreitWignerDist.extended_likelihood(_context, _data=None)¶
Extended likelihood contribution in normal space.
Returns additional likelihood terms for extended ML fitting. Override only when the extended terms belong in the distribution’s per-event density, like constraint terms (HistFactory). Terms that enter the likelihood once per channel (e.g. the Poisson yield term of an extended MixtureDist, which involves the observed event count) must not use this hook:
_expression()multiplies the result into the density, soModel.log_probwould count it once per event when summing over data. Such terms are assembled once per channel byModel.log_prob, which owns the channel-dataset pairing.Default: no contribution (returns 1.0 in normal space).
- RelativisticBreitWignerDist.get_parameter_list(context, param_key)¶
Reconstruct a parameter list from flattened indexed keys.
Used to recover the original list structure from the indexed parameter mapping created by process_parameter_list().
- Parameters:
- Return type:
- Returns:
List of parameter values in original order.
Example
>>> from typing import Literal >>> class TestEvaluable(Evaluable): ... type: Literal["test"] = "test" ... factors: list[str | float] ... def _expression(self, _: Context) -> TensorVar: ... return None >>> >>> eval1 = TestEvaluable(name="test", factors=["a", 1.0, "b"]) >>> context = { ... "a": "tensor_a", ... "constant_test_factors[1]": "tensor_1", ... "b": "tensor_b" ... } >>> eval1.get_parameter_list(context, "factors") ['tensor_a', 'tensor_1', 'tensor_b']
- RelativisticBreitWignerDist.likelihood(context)[source]¶
Builds a symbolic expression for the unnormalized relativistic Breit-Wigner density.
The density is zero at and below the observed channel’s threshold. Normalization over the observable’s domain is applied by
pyhs3.distributions.Distribution.expression().- Parameters:
context (dict) – Mapping of names to pytensor variables.
- Returns:
Symbolic representation of the unnormalized density, with the shape of the mass variable.
- Return type:
- RelativisticBreitWignerDist.log_expression(context)¶
Log-probability combining main likelihood with extended terms.
Returns log_likelihood() plus log(extended_likelihood()), minus the log of the normalization integral where normalization applies. This is mathematically equivalent to log(likelihood * extended_likelihood) but starts from log_likelihood() so that a distribution’s analytic log form (e.g. Gaussian, Poisson, LogNormal) is used directly instead of round- tripping through a probability value that can underflow to 0.0.
Normalization itself stays probability-space: the normalization integral (whether analytic or Gauss-Legendre quadrature) is a sum of positive terms and is far less underflow-prone than the raw density, so log(integral) is subtracted rather than computed as its own analytic log form.
All distributions are automatically normalized over observables present in the context, unless explicitly opted out via _normalizable = False.
PyTensor handles optimization and simplification automatically.
- RelativisticBreitWignerDist.log_likelihood(context)¶
Log-space counterpart of
likelihood().Default implementation takes the log of the probability-space likelihood. Override with an analytic log-space form wherever one exists (e.g. Gaussian, Poisson, LogNormal): the default round-trips through a probability value that can underflow to 0.0 for parameter points far from the mode, at which point
pt.log(0.0)is-infeven though the true log-density is finite.
- RelativisticBreitWignerDist.log_prob_terms(_expressions, log_expressions, _distributions)¶
Structured contributions of this distribution to the joint log-likelihood.
Called by
pyhs3.Model.log_probfor each channel after the model graph is built. Override when the distribution’s terms do not all enter the likelihood as a per-event log-density — e.g. once-per- channel yield terms (extendedMixtureDist) or globally-deduplicated constraint factors (ProductDist).Default: a single per-event
log(PDF)term sourced from the pre-built log-space expression so it stays finite where the probability-space PDF underflows.- Parameters:
_expressions (
Mapping[str,TensorVar]) – Compiled symbolic expressions for all distributions, keyed by name (model.distributions). Unused in the base implementation; subclasses may reference it.log_expressions (
Mapping[str,TensorVar]) – Compiled log-space symbolic expressions for all distributions, keyed by name (model.log_distributions)._distributions (
Distributions) – Distribution objects keyed by name, so composite distributions can delegate to their components’ hooks.
- Returns:
per-event, per-channel, and constraint contributions.
- Return type:
- RelativisticBreitWignerDist.model_post_init(context, /)¶
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- RelativisticBreitWignerDist.normalization_expression(_context, _observable_name)¶
Return the antiderivative expression, or None for numerical fallback.
Override in subclasses to provide analytical normalization. The returned expression should be the antiderivative F(x) such that the integral ∫f(x)dx from a to b equals F(b) - F(a).
- RelativisticBreitWignerDist.process_parameter(param_key)¶
Process a single parameter that can be either a string reference or numeric value.
For numeric values, generates a unique constant name. For string values, returns the value as-is.
- Parameters:
param_key (
str) – The parameter field name to process (e.g., “mean”, “sigma”).- Return type:
- Returns:
(processed_name, numeric_value).processed_nameis either the original string value or a generated constant name;numeric_valueis the numeric value if the input was numeric,Noneotherwise.
Example
>>> from typing import Literal >>> class TestEvaluable(Evaluable): ... type: Literal["test"] = "test" ... some_param: str | float ... def _expression(self, _: Context) -> TensorVar: ... return None >>> >>> # String parameter >>> eval1 = TestEvaluable(name="test1", some_param="alpha") >>> eval1.process_parameter("some_param") ('alpha', None)
>>> # Numeric parameter >>> eval2 = TestEvaluable(name="test2", some_param=1.5) >>> eval2.process_parameter("some_param") ('constant_test2_some_param', 1.5)
- RelativisticBreitWignerDist.process_parameter_list(param_key)¶
Process a list parameter containing mixed string references and numeric values.
For numeric values, generates indexed unique names and stores the values. For string values, returns the values as-is. Also updates internal parameter mapping with indexed keys.
- Parameters:
param_key (
str) – The parameter field name to process (e.g., “factors”, “coefficients”).- Return type:
- Returns:
(processed_names, numeric_values).processed_nameslists the parameter names (original strings or generated constant names);numeric_valueslists the numeric values (Nonefor string entries).
Example
>>> from typing import Literal >>> class TestEvaluable(Evaluable): ... type: Literal["test"] = "test" ... factors: list[str | float] ... def _expression(self, _: Context) -> TensorVar: ... return None >>> >>> eval1 = TestEvaluable(name="test", factors=["param1", 2.0, "param2"]) >>> names, values = eval1.process_parameter_list("factors") >>> names ['param1', 'constant_test_factors[1]', 'param2'] >>> values [None, 2.0, None]
- RelativisticBreitWignerDist.structural_key()¶
Identity of this distribution’s expression, independent of its name.
Two distributions with the same key reference the same parameters, functions and constants in the same fields, so in one model they build identical expressions. The key is the class name plus the JSON dump of every field except
name.Examples
Equal fields under different names give the same key:
>>> from pyhs3.distributions import GaussianDist >>> a = GaussianDist(name="sig", x="m", mean="mu", sigma=1.0) >>> b = GaussianDist(name="bkg", x="m", mean="mu", sigma=1.0) >>> a.structural_key() == b.structural_key() True
A different value, or a constant in place of a parameter reference, gives a different key:
>>> c = GaussianDist(name="bkg", x="m", mean="mu", sigma=2.0) >>> d = GaussianDist(name="bkg", x="m", mean=0.0, sigma=1.0) >>> a.structural_key() in {c.structural_key(), d.structural_key()} False
- Returns:
The structural key.
- Return type:
- RelativisticBreitWignerDist.unconstrained_parameters()¶
Parameters this distribution scales a positive yield with but does not constrain.
Such a parameter must be
constin the parameter point an analysis uses, or it floats unconstrained. Only HistFactory channels have any (per-bin parameters of bins with zero uncertainty).
- RelativisticBreitWignerDist.constants¶
Dictionary of PyTensor constants generated from numeric field values.
- Returns:
Mapping from generated constant names to PyTensor constant tensors. Empty if all fields are string references.
- RelativisticBreitWignerDist.parameters¶
Set of parameter names this component depends on.
- Returns:
Set of parameter names, including both string references and generated constant names for numeric values.
Whether two distributions of this class that are equal in every field except
namemay share one built expression (seestructural_key()). Classes that keep per-object state while their expression is built must set this toFalse: an alias reuses the first object’s tensors and never builds, so its own state would be missing.
- RelativisticBreitWignerDist.type¶
- RelativisticBreitWignerDist.mass¶
- RelativisticBreitWignerDist.resonance¶
- RelativisticBreitWignerDist.channels¶
- RelativisticBreitWignerDist.name¶