1"""Python wrappers for decay-configuration objects.
3This module mirrors the decay configuration structs exposed by the C++
4observable binding. The Python classes are lightweight value wrappers: they
5store Python enum values and build the corresponding pybind11 C++ config object
6through ``to_cpp()`` when passed to
7``ObservableInterface.set_decay_config(...)``.
10 >>> from pyhyperiso.core.BusinessLogic.DecayConfig import BKllConfig, BPFFSource
11 >>> from pyhyperiso.core.BusinessLogic.ObservableInterface import ObservableInterface
12 >>> from pyhyperiso.core.Common.GeneralEnum import Decays
13 >>> oi = ObservableInterface()
14 >>> cfg = BKllConfig(ff_src=BPFFSource.GKvD_SR_LAT, n_threads=8)
15 >>> oi.set_decay_config(Decays.B__K_l_l, cfg)
18from __future__
import annotations
20from dataclasses
import dataclass
22from typing
import Any, Type, TypeVar
24from pyhyperiso.phyperiso.pyhyperiso.observable
import (
25 B_FF_Type
as _CppB_FF_Type,
26 BP_FF_Src
as _CppBP_FF_Src,
27 BV_FF_Src
as _CppBV_FF_Src,
28 LbL_FF_Src
as _CppLbL_FF_Src,
29 BDlnuConfig
as _CppBDlnuConfig,
30 BDstarlnuConfig
as _CppBDstarlnuConfig,
31 BKllConfig
as _CppBKllConfig,
32 BKstarGammaConfig
as _CppBKstarGammaConfig,
33 BKstarllConfig
as _CppBKstarllConfig,
34 BsPhiConfig
as _CppBsPhiConfig,
35 BXsllConfig
as _CppBXsllConfig,
36 DecayConfig
as _CppDecayConfig,
37 KllDecayConfig
as _CppKllDecayConfig,
38 LbLllConfig
as _CppLbLllConfig,
43 """Form-factor treatment for exclusive B decays.
46 FULL: Use the full form-factor basis.
47 SOFT: Use the soft form-factor approximation.
50 FULL = _CppB_FF_Type.FULL
51 SOFT = _CppB_FF_Type.SOFT
55 """Source of B -> pseudoscalar form factors.
57 These values are used by :class:`BKllConfig`.
61 GRvDV = _CppBP_FF_Src.GRvDV
62 GKvD_SR_LAT = _CppBP_FF_Src.GKvD_SR_LAT
63 GKvD_SR = _CppBP_FF_Src.GKvD_SR
64 FLAG24 = _CppBP_FF_Src.FLAG24
65 HPQCD22 = _CppBP_FF_Src.HPQCD22
69 """Source of B -> vector form factors.
71 These values are used by :class:`BKstarllConfig`,
72 :class:`BKstarGammaConfig`, and :class:`BsPhiConfig`.
75 BSZ_SR_LAT = _CppBV_FF_Src.BSZ_SR_LAT
76 BSZ_SR = _CppBV_FF_Src.BSZ_SR
77 GRvDV = _CppBV_FF_Src.GRvDV
78 GKvD_SR_LAT = _CppBV_FF_Src.GKvD_SR_LAT
79 GKvD_SR = _CppBV_FF_Src.GKvD_SR
80 HLMW = _CppBV_FF_Src.HLMW
84 """Source of Lambda_b -> Lambda form factors.
86 Currently only the values exposed by the available C++ binding are listed.
89 DM = _CppLbL_FF_Src.DM
93 """B-meson charge choice for :class:`BDlnuConfig`."""
95 B_0 = _CppBDlnuConfig.BCharge.B_0
96 B_PLUS = _CppBDlnuConfig.BCharge.B_PLUS
100 """B-meson charge choice for :class:`BDstarlnuConfig`."""
102 B_0 = _CppBDstarlnuConfig.BCharge.B_0
103 B_PLUS = _CppBDstarlnuConfig.BCharge.B_PLUS
107 """B-meson charge choice for :class:`BKllConfig`."""
109 B_0 = _CppBKllConfig.BCharge.B_0
110 B_PLUS = _CppBKllConfig.BCharge.B_PLUS
114 """Lepton-generation choice for :class:`BKllConfig`."""
116 E = _CppBKllConfig.Lepton.E
117 MU = _CppBKllConfig.Lepton.MU
118 TAU = _CppBKllConfig.Lepton.TAU
122 """Power-correction prescription for :class:`BKstarllConfig`."""
124 BFS = _CppBKstarllConfig.PowerCorrectionsImpl.BFS
125 BCvDV = _CppBKstarllConfig.PowerCorrectionsImpl.BCvDV
126 KMPW = _CppBKstarllConfig.PowerCorrectionsImpl.KMPW
130 """B-meson charge choice for :class:`BKstarllConfig`."""
132 B_0 = _CppBKstarllConfig.BCharge.B_0
133 B_PLUS = _CppBKstarllConfig.BCharge.B_PLUS
137 """Lepton-generation choice for :class:`BKstarllConfig`."""
139 E = _CppBKstarllConfig.Lepton.E
140 MU = _CppBKstarllConfig.Lepton.MU
141 TAU = _CppBKstarllConfig.Lepton.TAU
145 """B-meson charge choice for :class:`BKstarGammaConfig`."""
147 B_0 = _CppBKstarGammaConfig.BCharge.B_0
148 B_PLUS = _CppBKstarGammaConfig.BCharge.B_PLUS
152 """Lepton-generation choice for :class:`BsPhiConfig`."""
154 E = _CppBsPhiConfig.Lepton.E
155 MU = _CppBsPhiConfig.Lepton.MU
156 TAU = _CppBsPhiConfig.Lepton.TAU
160 """Lepton-generation choice for :class:`BXsllConfig`."""
162 E = _CppBXsllConfig.Lepton.E
163 MU = _CppBXsllConfig.Lepton.MU
164 TAU = _CppBXsllConfig.Lepton.TAU
168 """Lepton-generation choice for :class:`LbLllConfig`."""
170 E = _CppLbLllConfig.Lepton.E
171 MU = _CppLbLllConfig.Lepton.MU
172 TAU = _CppLbLllConfig.Lepton.TAU
175EnumT = TypeVar(
"EnumT", bound=Enum)
178def _as_cpp_enum(value: EnumT | Any, enum_type: Type[EnumT], name: str) -> Any:
179 """Return the C++ enum value stored by a Python wrapper enum.
182 value: Python enum value or raw pybind11 enum value.
183 enum_type: Expected Python enum class.
184 name: Field name used in error messages.
187 The pybind11 enum value to assign on the C++ config object.
190 TypeError: If ``value`` is a different Python enum type.
192 if isinstance(value, enum_type):
194 if isinstance(value, Enum):
195 raise TypeError(f
"{name} must be {enum_type.__name__}, got {type(value).__name__}.")
200 """Base decay-configuration wrapper.
202 This class is useful for decay engines whose concrete configuration is the
203 empty C++ ``DecayConfig`` marker. It is also used as the common Python base
204 class for legacy C++ config structs that do not inherit from ``DecayConfig``
205 but are still accepted by ``ObservableInterface.set_decay_config`` through
206 typed pybind overloads.
210 def from_cpp(cls, cpp_obj: _CppDecayConfig) ->
"DecayConfig":
211 """Wrap an existing C++ ``DecayConfig`` object.
214 cpp_obj: Bound C++ config object.
217 A base Python configuration wrapper.
220 inst._cpp_obj = cpp_obj
224 """Build a C++ base decay configuration.
227 Bound C++ ``DecayConfig`` instance.
229 return _CppDecayConfig()
232 """Alias for ``to_cpp()`` used by other wrappers."""
236@dataclass(slots=True)
238 """Configuration for ``B -> D l nu`` decays.
241 charge: B-meson charge convention. Defaults to ``B_PLUS``.
244 charge: BDlnuBCharge = BDlnuBCharge.B_PLUS
247 def from_cpp(cls, cpp_obj: _CppBDlnuConfig) ->
"BDlnuConfig":
248 """Create a Python wrapper from a C++ ``BDlnuConfig``."""
252 """Build the C++ ``BDlnuConfig`` object."""
253 cfg = _CppBDlnuConfig()
258@dataclass(slots=True)
260 """Configuration for ``B -> D* l nu`` decays.
263 charge: B-meson charge convention. Defaults to ``B_PLUS``.
266 charge: BDstarlnuBCharge = BDstarlnuBCharge.B_PLUS
269 def from_cpp(cls, cpp_obj: _CppBDstarlnuConfig) ->
"BDstarlnuConfig":
270 """Create a Python wrapper from a C++ ``BDstarlnuConfig``."""
274 """Build the C++ ``BDstarlnuConfig`` object."""
275 cfg = _CppBDstarlnuConfig()
280@dataclass(slots=True)
282 """Configuration for exclusive ``B -> K l+ l-`` decays.
285 ff_src: Source of B -> K form factors.
286 ff_type: Form-factor treatment, full or soft.
287 charge: B-meson charge convention.
288 gen: Lepton generation.
289 n_threads: Requested number of worker threads. ``0`` may be interpreted
290 by the C++ decay as "use hardware concurrency" when supported.
293 ff_src: BPFFSource = BPFFSource.AS
294 ff_type: BFFType = BFFType.FULL
295 charge: BKllBCharge = BKllBCharge.B_PLUS
296 gen: BKllLepton = BKllLepton.MU
300 def from_cpp(cls, cpp_obj: _CppBKllConfig) ->
"BKllConfig":
301 """Create a Python wrapper from a C++ ``BKllConfig``."""
304 ff_type=
BFFType(cpp_obj.ff_type),
307 n_threads=int(cpp_obj.n_threads),
311 """Build the C++ ``BKllConfig`` object."""
312 cfg = _CppBKllConfig()
321@dataclass(slots=True)
323 """Configuration for exclusive ``B -> K* l+ l-`` decays.
326 ff_src: Source of B -> K* form factors.
327 ff_type: Form-factor treatment, full or soft.
328 power_corr_impl: Non-factorisable power-correction prescription.
329 charge: B-meson charge convention.
330 gen: Lepton generation.
331 n_threads: Requested number of worker threads. ``0`` may be interpreted
332 by the C++ decay as "use hardware concurrency" when supported.
335 ff_src: BVFFSource = BVFFSource.BSZ_SR_LAT
336 ff_type: BFFType = BFFType.FULL
337 power_corr_impl: BKstarllPowerCorrectionsImpl = BKstarllPowerCorrectionsImpl.BFS
338 charge: BKstarllBCharge = BKstarllBCharge.B_PLUS
339 gen: BKstarllLepton = BKstarllLepton.MU
343 def from_cpp(cls, cpp_obj: _CppBKstarllConfig) ->
"BKstarllConfig":
344 """Create a Python wrapper from a C++ ``BKstarllConfig``."""
347 ff_type=
BFFType(cpp_obj.ff_type),
351 n_threads=int(cpp_obj.n_threads),
355 """Build the C++ ``BKstarllConfig`` object."""
356 cfg = _CppBKstarllConfig()
368@dataclass(slots=True)
370 """Configuration for exclusive ``B -> K* gamma`` decays.
373 ff_src: Source of B -> K* form factors.
374 charge: B-meson charge convention.
377 ff_src: BVFFSource = BVFFSource.BSZ_SR_LAT
378 charge: BKstarGammaBCharge = BKstarGammaBCharge.B_PLUS
381 def from_cpp(cls, cpp_obj: _CppBKstarGammaConfig) ->
"BKstarGammaConfig":
382 """Create a Python wrapper from a C++ ``BKstarGammaConfig``."""
388 def to_cpp(self) -> _CppBKstarGammaConfig:
389 """Build the C++ ``BKstarGammaConfig`` object."""
390 cfg = _CppBKstarGammaConfig()
396@dataclass(slots=True)
398 """Configuration for exclusive ``Bs -> phi l+ l-`` decays.
401 ff_src: Source of Bs -> phi form factors.
402 ff_type: Form-factor treatment, full or soft.
403 gen: Lepton generation.
404 n_threads: Requested number of worker threads.
407 ff_src: BVFFSource = BVFFSource.BSZ_SR_LAT
408 ff_type: BFFType = BFFType.FULL
409 gen: BsPhiLepton = BsPhiLepton.MU
413 def from_cpp(cls, cpp_obj: _CppBsPhiConfig) ->
"BsPhiConfig":
414 """Create a Python wrapper from a C++ ``BsPhiConfig``."""
417 ff_type=
BFFType(cpp_obj.ff_type),
419 n_threads=int(cpp_obj.n_threads),
423 """Build the C++ ``BsPhiConfig`` object."""
424 cfg = _CppBsPhiConfig()
432@dataclass(slots=True)
434 """Configuration for inclusive ``B -> X_s l+ l-`` decays.
437 gen: Lepton generation. Defaults to ``MU``.
440 gen: BXsllLepton = BXsllLepton.MU
443 def from_cpp(cls, cpp_obj: _CppBXsllConfig) ->
"BXsllConfig":
444 """Create a Python wrapper from a C++ ``BXsllConfig``."""
448 """Build the C++ ``BXsllConfig`` object."""
449 cfg = _CppBXsllConfig()
454@dataclass(slots=True)
456 """Configuration for ``K_L,S -> l+ l-`` decays.
459 N_L_sign: Sign convention for the long-distance ``K_L -> gamma gamma``
460 term. Defaults to ``1``.
461 gen: Lepton generation using the integer convention expected by the C++
462 backend. Defaults to ``2``.
469 def from_cpp(cls, cpp_obj: _CppKllDecayConfig) ->
"KllDecayConfig":
470 """Create a Python wrapper from a C++ ``KllDecayConfig``."""
471 return cls(N_L_sign=int(cpp_obj.N_L_sign), gen=int(cpp_obj.gen))
474 """Build the C++ ``KllDecayConfig`` object."""
475 cfg = _CppKllDecayConfig()
477 cfg.gen = int(self.
gen)
481@dataclass(slots=True)
483 """Configuration for ``Lambda_b -> Lambda l+ l-`` decays.
486 ff_src: Source of Lambda_b -> Lambda form factors.
487 gen: Lepton generation. Defaults to ``MU``.
488 n_threads: Requested number of worker threads. ``0`` may be interpreted
489 by the C++ layer as ``std::thread::hardware_concurrency``.
492 ff_src: LbLFFSource = LbLFFSource.DM
493 gen: LbLllLepton = LbLllLepton.MU
497 def from_cpp(cls, cpp_obj: _CppLbLllConfig) ->
"LbLllConfig":
498 """Create a Python wrapper from a C++ ``LbLllConfig``."""
502 n_threads=int(cpp_obj.n_threads),
506 """Build the C++ ``LbLllConfig`` object."""
507 cfg = _CppLbLllConfig()
516BP_FF_Src = BPFFSource
517BV_FF_Src = BVFFSource
518LbL_FF_Src = LbLFFSource
534 "BKstarllPowerCorrectionsImpl",
537 "BKstarGammaBCharge",
"BDlnuConfig" from_cpp(cls, _CppBDlnuConfig cpp_obj)
_CppBDlnuConfig to_cpp(self)
_CppBDstarlnuConfig to_cpp(self)
"BDstarlnuConfig" from_cpp(cls, _CppBDstarlnuConfig cpp_obj)
_CppBKllConfig to_cpp(self)
"BKllConfig" from_cpp(cls, _CppBKllConfig cpp_obj)
BKstarGammaBCharge charge
"BKstarGammaConfig" from_cpp(cls, _CppBKstarGammaConfig cpp_obj)
_CppBKstarGammaConfig to_cpp(self)
"BKstarllConfig" from_cpp(cls, _CppBKstarllConfig cpp_obj)
_CppBKstarllConfig to_cpp(self)
BKstarllPowerCorrectionsImpl power_corr_impl
_CppBXsllConfig to_cpp(self)
"BXsllConfig" from_cpp(cls, _CppBXsllConfig cpp_obj)
_CppBsPhiConfig to_cpp(self)
"BsPhiConfig" from_cpp(cls, _CppBsPhiConfig cpp_obj)
_CppDecayConfig _to_cpp(self)
_CppDecayConfig to_cpp(self)
"DecayConfig" from_cpp(cls, _CppDecayConfig cpp_obj)
_CppKllDecayConfig to_cpp(self)
"KllDecayConfig" from_cpp(cls, _CppKllDecayConfig cpp_obj)
_CppLbLllConfig to_cpp(self)
"LbLllConfig" from_cpp(cls, _CppLbLllConfig cpp_obj)
Any _as_cpp_enum(EnumT|Any value, Type[EnumT] enum_type, str name)