Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
DecayConfig.py
Go to the documentation of this file.
1"""Python wrappers for decay-configuration objects.
2
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(...)``.
8
9Example:
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)
16"""
17
18from __future__ import annotations
19
20from dataclasses import dataclass
21from enum import Enum
22from typing import Any, Type, TypeVar
23
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,
39)
40
41
42class BFFType(Enum):
43 """Form-factor treatment for exclusive B decays.
44
45 Attributes:
46 FULL: Use the full form-factor basis.
47 SOFT: Use the soft form-factor approximation.
48 """
49
50 FULL = _CppB_FF_Type.FULL
51 SOFT = _CppB_FF_Type.SOFT
52
53
54class BPFFSource(Enum):
55 """Source of B -> pseudoscalar form factors.
56
57 These values are used by :class:`BKllConfig`.
58 """
59
60 AS = _CppBP_FF_Src.AS
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
66
67
68class BVFFSource(Enum):
69 """Source of B -> vector form factors.
70
71 These values are used by :class:`BKstarllConfig`,
72 :class:`BKstarGammaConfig`, and :class:`BsPhiConfig`.
73 """
74
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
81
82
83class LbLFFSource(Enum):
84 """Source of Lambda_b -> Lambda form factors.
85
86 Currently only the values exposed by the available C++ binding are listed.
87 """
88
89 DM = _CppLbL_FF_Src.DM
90
91
92class BDlnuBCharge(Enum):
93 """B-meson charge choice for :class:`BDlnuConfig`."""
94
95 B_0 = _CppBDlnuConfig.BCharge.B_0
96 B_PLUS = _CppBDlnuConfig.BCharge.B_PLUS
97
98
99class BDstarlnuBCharge(Enum):
100 """B-meson charge choice for :class:`BDstarlnuConfig`."""
101
102 B_0 = _CppBDstarlnuConfig.BCharge.B_0
103 B_PLUS = _CppBDstarlnuConfig.BCharge.B_PLUS
104
105
106class BKllBCharge(Enum):
107 """B-meson charge choice for :class:`BKllConfig`."""
108
109 B_0 = _CppBKllConfig.BCharge.B_0
110 B_PLUS = _CppBKllConfig.BCharge.B_PLUS
111
112
113class BKllLepton(Enum):
114 """Lepton-generation choice for :class:`BKllConfig`."""
115
116 E = _CppBKllConfig.Lepton.E
117 MU = _CppBKllConfig.Lepton.MU
118 TAU = _CppBKllConfig.Lepton.TAU
119
120
122 """Power-correction prescription for :class:`BKstarllConfig`."""
123
124 BFS = _CppBKstarllConfig.PowerCorrectionsImpl.BFS
125 BCvDV = _CppBKstarllConfig.PowerCorrectionsImpl.BCvDV
126 KMPW = _CppBKstarllConfig.PowerCorrectionsImpl.KMPW
127
128
129class BKstarllBCharge(Enum):
130 """B-meson charge choice for :class:`BKstarllConfig`."""
131
132 B_0 = _CppBKstarllConfig.BCharge.B_0
133 B_PLUS = _CppBKstarllConfig.BCharge.B_PLUS
134
135
136class BKstarllLepton(Enum):
137 """Lepton-generation choice for :class:`BKstarllConfig`."""
138
139 E = _CppBKstarllConfig.Lepton.E
140 MU = _CppBKstarllConfig.Lepton.MU
141 TAU = _CppBKstarllConfig.Lepton.TAU
142
143
145 """B-meson charge choice for :class:`BKstarGammaConfig`."""
146
147 B_0 = _CppBKstarGammaConfig.BCharge.B_0
148 B_PLUS = _CppBKstarGammaConfig.BCharge.B_PLUS
149
150
151class BsPhiLepton(Enum):
152 """Lepton-generation choice for :class:`BsPhiConfig`."""
153
154 E = _CppBsPhiConfig.Lepton.E
155 MU = _CppBsPhiConfig.Lepton.MU
156 TAU = _CppBsPhiConfig.Lepton.TAU
157
158
159class BXsllLepton(Enum):
160 """Lepton-generation choice for :class:`BXsllConfig`."""
161
162 E = _CppBXsllConfig.Lepton.E
163 MU = _CppBXsllConfig.Lepton.MU
164 TAU = _CppBXsllConfig.Lepton.TAU
165
166
167class LbLllLepton(Enum):
168 """Lepton-generation choice for :class:`LbLllConfig`."""
169
170 E = _CppLbLllConfig.Lepton.E
171 MU = _CppLbLllConfig.Lepton.MU
172 TAU = _CppLbLllConfig.Lepton.TAU
173
174
175EnumT = TypeVar("EnumT", bound=Enum)
176
177
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.
180
181 Args:
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.
185
186 Returns:
187 The pybind11 enum value to assign on the C++ config object.
188
189 Raises:
190 TypeError: If ``value`` is a different Python enum type.
191 """
192 if isinstance(value, enum_type):
193 return value.value
194 if isinstance(value, Enum):
195 raise TypeError(f"{name} must be {enum_type.__name__}, got {type(value).__name__}.")
196 return value
197
198
200 """Base decay-configuration wrapper.
201
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.
207 """
208
209 @classmethod
210 def from_cpp(cls, cpp_obj: _CppDecayConfig) -> "DecayConfig":
211 """Wrap an existing C++ ``DecayConfig`` object.
212
213 Args:
214 cpp_obj: Bound C++ config object.
215
216 Returns:
217 A base Python configuration wrapper.
218 """
219 inst = cls()
220 inst._cpp_obj = cpp_obj
221 return inst
222
223 def to_cpp(self) -> _CppDecayConfig:
224 """Build a C++ base decay configuration.
225
226 Returns:
227 Bound C++ ``DecayConfig`` instance.
228 """
229 return _CppDecayConfig()
230
231 def _to_cpp(self) -> _CppDecayConfig:
232 """Alias for ``to_cpp()`` used by other wrappers."""
233 return self.to_cpp()
234
235
236@dataclass(slots=True)
238 """Configuration for ``B -> D l nu`` decays.
239
240 Args:
241 charge: B-meson charge convention. Defaults to ``B_PLUS``.
242 """
243
244 charge: BDlnuBCharge = BDlnuBCharge.B_PLUS
245
246 @classmethod
247 def from_cpp(cls, cpp_obj: _CppBDlnuConfig) -> "BDlnuConfig":
248 """Create a Python wrapper from a C++ ``BDlnuConfig``."""
249 return cls(charge=BDlnuBCharge(cpp_obj.charge))
250
251 def to_cpp(self) -> _CppBDlnuConfig:
252 """Build the C++ ``BDlnuConfig`` object."""
253 cfg = _CppBDlnuConfig()
254 cfg.charge = _as_cpp_enum(self.charge, BDlnuBCharge, "charge")
255 return cfg
256
257
258@dataclass(slots=True)
260 """Configuration for ``B -> D* l nu`` decays.
261
262 Args:
263 charge: B-meson charge convention. Defaults to ``B_PLUS``.
264 """
265
266 charge: BDstarlnuBCharge = BDstarlnuBCharge.B_PLUS
267
268 @classmethod
269 def from_cpp(cls, cpp_obj: _CppBDstarlnuConfig) -> "BDstarlnuConfig":
270 """Create a Python wrapper from a C++ ``BDstarlnuConfig``."""
271 return cls(charge=BDstarlnuBCharge(cpp_obj.charge))
272
273 def to_cpp(self) -> _CppBDstarlnuConfig:
274 """Build the C++ ``BDstarlnuConfig`` object."""
275 cfg = _CppBDstarlnuConfig()
276 cfg.charge = _as_cpp_enum(self.charge, BDstarlnuBCharge, "charge")
277 return cfg
278
279
280@dataclass(slots=True)
282 """Configuration for exclusive ``B -> K l+ l-`` decays.
283
284 Args:
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.
291 """
292
293 ff_src: BPFFSource = BPFFSource.AS
294 ff_type: BFFType = BFFType.FULL
295 charge: BKllBCharge = BKllBCharge.B_PLUS
296 gen: BKllLepton = BKllLepton.MU
297 n_threads: int = 1
298
299 @classmethod
300 def from_cpp(cls, cpp_obj: _CppBKllConfig) -> "BKllConfig":
301 """Create a Python wrapper from a C++ ``BKllConfig``."""
302 return cls(
303 ff_src=BPFFSource(cpp_obj.ff_src),
304 ff_type=BFFType(cpp_obj.ff_type),
305 charge=BKllBCharge(cpp_obj.charge),
306 gen=BKllLepton(cpp_obj.gen),
307 n_threads=int(cpp_obj.n_threads),
308 )
309
310 def to_cpp(self) -> _CppBKllConfig:
311 """Build the C++ ``BKllConfig`` object."""
312 cfg = _CppBKllConfig()
313 cfg.ff_src = _as_cpp_enum(self.ff_src, BPFFSource, "ff_src")
314 cfg.ff_type = _as_cpp_enum(self.ff_type, BFFType, "ff_type")
315 cfg.charge = _as_cpp_enum(self.charge, BKllBCharge, "charge")
316 cfg.gen = _as_cpp_enum(self.gen, BKllLepton, "gen")
317 cfg.n_threads = int(self.n_threads)
318 return cfg
319
320
321@dataclass(slots=True)
323 """Configuration for exclusive ``B -> K* l+ l-`` decays.
324
325 Args:
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.
333 """
334
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
340 n_threads: int = 1
341
342 @classmethod
343 def from_cpp(cls, cpp_obj: _CppBKstarllConfig) -> "BKstarllConfig":
344 """Create a Python wrapper from a C++ ``BKstarllConfig``."""
345 return cls(
346 ff_src=BVFFSource(cpp_obj.ff_src),
347 ff_type=BFFType(cpp_obj.ff_type),
348 power_corr_impl=BKstarllPowerCorrectionsImpl(cpp_obj.power_corr_impl),
349 charge=BKstarllBCharge(cpp_obj.charge),
350 gen=BKstarllLepton(cpp_obj.gen),
351 n_threads=int(cpp_obj.n_threads),
352 )
353
354 def to_cpp(self) -> _CppBKstarllConfig:
355 """Build the C++ ``BKstarllConfig`` object."""
356 cfg = _CppBKstarllConfig()
357 cfg.ff_src = _as_cpp_enum(self.ff_src, BVFFSource, "ff_src")
358 cfg.ff_type = _as_cpp_enum(self.ff_type, BFFType, "ff_type")
359 cfg.power_corr_impl = _as_cpp_enum(
360 self.power_corr_implpower_corr_impl, BKstarllPowerCorrectionsImpl, "power_corr_impl"
361 )
362 cfg.charge = _as_cpp_enum(self.charge, BKstarllBCharge, "charge")
363 cfg.gen = _as_cpp_enum(self.gen, BKstarllLepton, "gen")
364 cfg.n_threads = int(self.n_threads)
365 return cfg
366
367
368@dataclass(slots=True)
370 """Configuration for exclusive ``B -> K* gamma`` decays.
371
372 Args:
373 ff_src: Source of B -> K* form factors.
374 charge: B-meson charge convention.
375 """
376
377 ff_src: BVFFSource = BVFFSource.BSZ_SR_LAT
378 charge: BKstarGammaBCharge = BKstarGammaBCharge.B_PLUS
379
380 @classmethod
381 def from_cpp(cls, cpp_obj: _CppBKstarGammaConfig) -> "BKstarGammaConfig":
382 """Create a Python wrapper from a C++ ``BKstarGammaConfig``."""
383 return cls(
384 ff_src=BVFFSource(cpp_obj.ff_src),
385 charge=BKstarGammaBCharge(cpp_obj.charge),
386 )
387
388 def to_cpp(self) -> _CppBKstarGammaConfig:
389 """Build the C++ ``BKstarGammaConfig`` object."""
390 cfg = _CppBKstarGammaConfig()
391 cfg.ff_src = _as_cpp_enum(self.ff_src, BVFFSource, "ff_src")
392 cfg.charge = _as_cpp_enum(self.charge, BKstarGammaBCharge, "charge")
393 return cfg
394
395
396@dataclass(slots=True)
398 """Configuration for exclusive ``Bs -> phi l+ l-`` decays.
399
400 Args:
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.
405 """
406
407 ff_src: BVFFSource = BVFFSource.BSZ_SR_LAT
408 ff_type: BFFType = BFFType.FULL
409 gen: BsPhiLepton = BsPhiLepton.MU
410 n_threads: int = 1
411
412 @classmethod
413 def from_cpp(cls, cpp_obj: _CppBsPhiConfig) -> "BsPhiConfig":
414 """Create a Python wrapper from a C++ ``BsPhiConfig``."""
415 return cls(
416 ff_src=BVFFSource(cpp_obj.ff_src),
417 ff_type=BFFType(cpp_obj.ff_type),
418 gen=BsPhiLepton(cpp_obj.gen),
419 n_threads=int(cpp_obj.n_threads),
420 )
421
422 def to_cpp(self) -> _CppBsPhiConfig:
423 """Build the C++ ``BsPhiConfig`` object."""
424 cfg = _CppBsPhiConfig()
425 cfg.ff_src = _as_cpp_enum(self.ff_src, BVFFSource, "ff_src")
426 cfg.ff_type = _as_cpp_enum(self.ff_type, BFFType, "ff_type")
427 cfg.gen = _as_cpp_enum(self.gen, BsPhiLepton, "gen")
428 cfg.n_threads = int(self.n_threads)
429 return cfg
430
431
432@dataclass(slots=True)
434 """Configuration for inclusive ``B -> X_s l+ l-`` decays.
435
436 Args:
437 gen: Lepton generation. Defaults to ``MU``.
438 """
439
440 gen: BXsllLepton = BXsllLepton.MU
441
442 @classmethod
443 def from_cpp(cls, cpp_obj: _CppBXsllConfig) -> "BXsllConfig":
444 """Create a Python wrapper from a C++ ``BXsllConfig``."""
445 return cls(gen=BXsllLepton(cpp_obj.gen))
446
447 def to_cpp(self) -> _CppBXsllConfig:
448 """Build the C++ ``BXsllConfig`` object."""
449 cfg = _CppBXsllConfig()
450 cfg.gen = _as_cpp_enum(self.gen, BXsllLepton, "gen")
451 return cfg
452
453
454@dataclass(slots=True)
456 """Configuration for ``K_L,S -> l+ l-`` decays.
457
458 Args:
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``.
463 """
464
465 N_L_sign: int = 1
466 gen: int = 2
467
468 @classmethod
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))
472
473 def to_cpp(self) -> _CppKllDecayConfig:
474 """Build the C++ ``KllDecayConfig`` object."""
475 cfg = _CppKllDecayConfig()
476 cfg.N_L_sign = int(self.N_L_sign)
477 cfg.gen = int(self.gen)
478 return cfg
479
480
481@dataclass(slots=True)
483 """Configuration for ``Lambda_b -> Lambda l+ l-`` decays.
484
485 Args:
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``.
490 """
491
492 ff_src: LbLFFSource = LbLFFSource.DM
493 gen: LbLllLepton = LbLllLepton.MU
494 n_threads: int = 1
495
496 @classmethod
497 def from_cpp(cls, cpp_obj: _CppLbLllConfig) -> "LbLllConfig":
498 """Create a Python wrapper from a C++ ``LbLllConfig``."""
499 return cls(
500 ff_src=LbLFFSource(cpp_obj.ff_src),
501 gen=LbLllLepton(cpp_obj.gen),
502 n_threads=int(cpp_obj.n_threads),
503 )
504
505 def to_cpp(self) -> _CppLbLllConfig:
506 """Build the C++ ``LbLllConfig`` object."""
507 cfg = _CppLbLllConfig()
508 cfg.ff_src = _as_cpp_enum(self.ff_src, LbLFFSource, "ff_src")
509 cfg.gen = _as_cpp_enum(self.gen, LbLllLepton, "gen")
510 cfg.n_threads = int(self.n_threads)
511 return cfg
512
513
514# Backward/low-level aliases matching the C++ naming style.
515B_FF_Type = BFFType
516BP_FF_Src = BPFFSource
517BV_FF_Src = BVFFSource
518LbL_FF_Src = LbLFFSource
519
520
521__all__ = [
522 "BFFType",
523 "BPFFSource",
524 "BVFFSource",
525 "LbLFFSource",
526 "B_FF_Type",
527 "BP_FF_Src",
528 "BV_FF_Src",
529 "LbL_FF_Src",
530 "BDlnuBCharge",
531 "BDstarlnuBCharge",
532 "BKllBCharge",
533 "BKllLepton",
534 "BKstarllPowerCorrectionsImpl",
535 "BKstarllBCharge",
536 "BKstarllLepton",
537 "BKstarGammaBCharge",
538 "BsPhiLepton",
539 "BXsllLepton",
540 "LbLllLepton",
541 "DecayConfig",
542 "BDlnuConfig",
543 "BDstarlnuConfig",
544 "BKllConfig",
545 "BKstarllConfig",
546 "BKstarGammaConfig",
547 "BsPhiConfig",
548 "BXsllConfig",
549 "KllDecayConfig",
550 "LbLllConfig",
551]
"BDlnuConfig" from_cpp(cls, _CppBDlnuConfig cpp_obj)
"BDstarlnuConfig" from_cpp(cls, _CppBDstarlnuConfig cpp_obj)
"BKllConfig" from_cpp(cls, _CppBKllConfig cpp_obj)
"BKstarGammaConfig" from_cpp(cls, _CppBKstarGammaConfig cpp_obj)
"BKstarllConfig" from_cpp(cls, _CppBKstarllConfig cpp_obj)
"BXsllConfig" from_cpp(cls, _CppBXsllConfig cpp_obj)
"BsPhiConfig" from_cpp(cls, _CppBsPhiConfig cpp_obj)
"DecayConfig" from_cpp(cls, _CppDecayConfig cpp_obj)
"KllDecayConfig" from_cpp(cls, _CppKllDecayConfig cpp_obj)
"LbLllConfig" from_cpp(cls, _CppLbLllConfig cpp_obj)
Any _as_cpp_enum(EnumT|Any value, Type[EnumT] enum_type, str name)