Module flarefly.components
Components module
PDFKind and PDFType classes define the types of probability density functions (PDFs) used in the flarefly package. F2PDFBase is the base class for all PDF implementations
Sub-modules
flarefly.components.pdf_base-
Module defining the base class for PDFs
flarefly.components.pdf_kind-
Module defining PDF kinds
Classes
class F2PDFBase (name_pdf: str, label_pdf: str, signal_bkg_or_refl: str, **kwargs)-
Expand source code
class F2PDFBase: # pylint: disable=too-many-public-methods, too-many-instance-attributes """Base class for PDFs""" def __init__( self, name_pdf: str, label_pdf: str, signal_bkg_or_refl: str, **kwargs ): if not name_pdf.startswith("chebpol"): self._kind_pdf = PDFKind(name_pdf) else: order = int(name_pdf.replace('chebpol', '')) self._kind_pdf = PDFKind("chebpol", order=order) self._pdf = None self._label_pdf = label_pdf self.set_signal_bkg_or_refl(signal_bkg_or_refl) self._hist_sample = None self._kde_sample = None self._kde_option = None self._refl_over_sgn = 0.0 self._at_threshold = kwargs.get('at_threshold', False) self._pars = {} self._parameter_setup = {} def set_signal_bkg_or_refl(self, signal_bkg_or_refl): """Set whether the PDF is signal, background, or reflection""" signal_bkg_or_refl = signal_bkg_or_refl.lower() if signal_bkg_or_refl == "signal": self._signal_bkg_or_refl = SignalBkgOrRefl.SIGNAL elif signal_bkg_or_refl == "background": self._signal_bkg_or_refl = SignalBkgOrRefl.BACKGROUND elif signal_bkg_or_refl == "reflection": self._signal_bkg_or_refl = SignalBkgOrRefl.REFLECTION else: Logger(f"Invalid value for signal_bkg_or_refl: {signal_bkg_or_refl}" ", expected 'signal', 'background', or 'reflection'.", "FATAL") def __repr__(self): return (f"F2PDFBase(PDF={self._pdf}, label={self._label_pdf}, kind={self._kind_pdf}, " f"Signal/Background/Reflection={self._signal_bkg_or_refl.name}, at_threshold={self._at_threshold}), " f"parameter_setup={self._parameter_setup}, parameters={self._pars}") # ------------------ # --- Properties --- # ------------------ # --- pdf --- @property def pdf(self): """Get the PDF name""" return self._pdf @pdf.setter def pdf(self, value): """Set the PDF name""" self._pdf = value # --- parameters --- @property def parameters(self): """Get the parameters""" return self._pars @parameters.setter def parameters(self, value): """Set the parameters""" self._pars = value # --- kde_sample --- @property def kde_sample(self): """Get the KDE sample""" return self._kde_sample @kde_sample.setter def kde_sample(self, value): """Set the KDE sample""" self._kde_sample = value # --- kde_option --- @property def kde_option(self): """Get the KDE options""" return self._kde_option @kde_option.setter def kde_option(self, value): """Set the KDE options""" self._kde_option = value # --- hist_sample --- @property def hist_sample(self): """Get the histogram sample""" return self._hist_sample @hist_sample.setter def hist_sample(self, value): """Set the histogram sample""" self._hist_sample = value # --- at_threshold --- @property def at_threshold(self): """Get the at_threshold flag""" return self._at_threshold # --- kind --- @property def kind(self): """Get the PDF kind""" return self._kind_pdf # --- label --- @property def label(self): """Get the PDF label""" return self._label_pdf # ---------------------- # --- Public Methods --- # ---------------------- def is_kde(self): """Check if this PDF type is KDE""" return self._kind_pdf.is_kde() def is_hist(self): """Check if this PDF type is histogram""" return self._kind_pdf.is_hist() def uses_m_not_mu(self): """Check if this PDF uses m instead of mu""" return self._kind_pdf.uses_m_not_mu() def has_sigma(self): """Check if PDF type has sigma parameter""" return self._kind_pdf.has_sigma() def has_hwhm(self): """Check if PDF type has a HWHM""" return self._kind_pdf.has_hwhm() def par_exists(self, name): """Check if the parameter exists""" return name in self._parameter_setup def create_par(self, name): """Create a new parameter""" self._parameter_setup[name] = {} def get_init_par(self, name): """Get the parameter initial value""" return self._parameter_setup[name]["init"] def get_limits_par(self, name): """Get the parameter limits""" return self._parameter_setup[name]["limits"] def get_fix_par(self, name): """Get the parameter fix flag""" return self._parameter_setup[name]["fix"] def get_init_pars(self): """Get the parameters initial value dictionary""" return {name: p["init"] for name, p in self._parameter_setup.items()} def get_limits_pars(self): """Get the parameters limits dictionary""" return {name: p["limits"] for name, p in self._parameter_setup.items()} def get_fix_pars(self): """Get the parameters fix dictionary""" return {name: p["fix"] for name, p in self._parameter_setup.items()} def set_init_par(self, name, value): """Set the parameter""" self._check_and_create_par(name) self._parameter_setup[name]["init"] = value def set_limits_par(self, name, value): """Set the parameter limits""" self._check_and_create_par(name) self._parameter_setup[name]["limits"] = value def set_fix_par(self, name, value): """Set the parameter fix flag""" self._check_and_create_par(name) self._parameter_setup[name]["fix"] = value def set_default_init_par(self, name, value): """Set default parameter""" self._check_and_create_par(name) self._parameter_setup[name].setdefault("init", value) def set_default_limits_par(self, name, value): """Set default parameter limits""" self._check_and_create_par(name) self._parameter_setup[name].setdefault("limits", value) def set_default_fix_par(self, name, value): """Set default parameter fix flag""" self._check_and_create_par(name) self._parameter_setup[name].setdefault("fix", value) def set_default_par(self, name, init=None, limits=None, fix=None): """Set default values for a parameter (only if not already defined).""" self._check_and_create_par(name) if init is not None: self._parameter_setup[name].setdefault("init", init) if limits is not None: self._parameter_setup[name].setdefault("limits", limits) if fix is not None: self._parameter_setup[name].setdefault("fix", fix) # ----------------------- # --- Private Methods --- # ----------------------- def _check_and_create_par(self, name: str): """Check if parameter exists, if not create it""" if not self.par_exists(name): self.create_par(name)Base class for PDFs
Instance variables
prop at_threshold-
Expand source code
@property def at_threshold(self): """Get the at_threshold flag""" return self._at_thresholdGet the at_threshold flag
prop hist_sample-
Expand source code
@property def hist_sample(self): """Get the histogram sample""" return self._hist_sampleGet the histogram sample
prop kde_option-
Expand source code
@property def kde_option(self): """Get the KDE options""" return self._kde_optionGet the KDE options
prop kde_sample-
Expand source code
@property def kde_sample(self): """Get the KDE sample""" return self._kde_sampleGet the KDE sample
prop kind-
Expand source code
@property def kind(self): """Get the PDF kind""" return self._kind_pdfGet the PDF kind
prop label-
Expand source code
@property def label(self): """Get the PDF label""" return self._label_pdfGet the PDF label
prop parameters-
Expand source code
@property def parameters(self): """Get the parameters""" return self._parsGet the parameters
prop pdf-
Expand source code
@property def pdf(self): """Get the PDF name""" return self._pdfGet the PDF name
Methods
def create_par(self, name)-
Expand source code
def create_par(self, name): """Create a new parameter""" self._parameter_setup[name] = {}Create a new parameter
def get_fix_par(self, name)-
Expand source code
def get_fix_par(self, name): """Get the parameter fix flag""" return self._parameter_setup[name]["fix"]Get the parameter fix flag
def get_fix_pars(self)-
Expand source code
def get_fix_pars(self): """Get the parameters fix dictionary""" return {name: p["fix"] for name, p in self._parameter_setup.items()}Get the parameters fix dictionary
def get_init_par(self, name)-
Expand source code
def get_init_par(self, name): """Get the parameter initial value""" return self._parameter_setup[name]["init"]Get the parameter initial value
def get_init_pars(self)-
Expand source code
def get_init_pars(self): """Get the parameters initial value dictionary""" return {name: p["init"] for name, p in self._parameter_setup.items()}Get the parameters initial value dictionary
def get_limits_par(self, name)-
Expand source code
def get_limits_par(self, name): """Get the parameter limits""" return self._parameter_setup[name]["limits"]Get the parameter limits
def get_limits_pars(self)-
Expand source code
def get_limits_pars(self): """Get the parameters limits dictionary""" return {name: p["limits"] for name, p in self._parameter_setup.items()}Get the parameters limits dictionary
def has_hwhm(self)-
Expand source code
def has_hwhm(self): """Check if PDF type has a HWHM""" return self._kind_pdf.has_hwhm()Check if PDF type has a HWHM
def has_sigma(self)-
Expand source code
def has_sigma(self): """Check if PDF type has sigma parameter""" return self._kind_pdf.has_sigma()Check if PDF type has sigma parameter
def is_hist(self)-
Expand source code
def is_hist(self): """Check if this PDF type is histogram""" return self._kind_pdf.is_hist()Check if this PDF type is histogram
def is_kde(self)-
Expand source code
def is_kde(self): """Check if this PDF type is KDE""" return self._kind_pdf.is_kde()Check if this PDF type is KDE
def par_exists(self, name)-
Expand source code
def par_exists(self, name): """Check if the parameter exists""" return name in self._parameter_setupCheck if the parameter exists
def set_default_fix_par(self, name, value)-
Expand source code
def set_default_fix_par(self, name, value): """Set default parameter fix flag""" self._check_and_create_par(name) self._parameter_setup[name].setdefault("fix", value)Set default parameter fix flag
def set_default_init_par(self, name, value)-
Expand source code
def set_default_init_par(self, name, value): """Set default parameter""" self._check_and_create_par(name) self._parameter_setup[name].setdefault("init", value)Set default parameter
def set_default_limits_par(self, name, value)-
Expand source code
def set_default_limits_par(self, name, value): """Set default parameter limits""" self._check_and_create_par(name) self._parameter_setup[name].setdefault("limits", value)Set default parameter limits
def set_default_par(self, name, init=None, limits=None, fix=None)-
Expand source code
def set_default_par(self, name, init=None, limits=None, fix=None): """Set default values for a parameter (only if not already defined).""" self._check_and_create_par(name) if init is not None: self._parameter_setup[name].setdefault("init", init) if limits is not None: self._parameter_setup[name].setdefault("limits", limits) if fix is not None: self._parameter_setup[name].setdefault("fix", fix)Set default values for a parameter (only if not already defined).
def set_fix_par(self, name, value)-
Expand source code
def set_fix_par(self, name, value): """Set the parameter fix flag""" self._check_and_create_par(name) self._parameter_setup[name]["fix"] = valueSet the parameter fix flag
def set_init_par(self, name, value)-
Expand source code
def set_init_par(self, name, value): """Set the parameter""" self._check_and_create_par(name) self._parameter_setup[name]["init"] = valueSet the parameter
def set_limits_par(self, name, value)-
Expand source code
def set_limits_par(self, name, value): """Set the parameter limits""" self._check_and_create_par(name) self._parameter_setup[name]["limits"] = valueSet the parameter limits
def set_signal_bkg_or_refl(self, signal_bkg_or_refl)-
Expand source code
def set_signal_bkg_or_refl(self, signal_bkg_or_refl): """Set whether the PDF is signal, background, or reflection""" signal_bkg_or_refl = signal_bkg_or_refl.lower() if signal_bkg_or_refl == "signal": self._signal_bkg_or_refl = SignalBkgOrRefl.SIGNAL elif signal_bkg_or_refl == "background": self._signal_bkg_or_refl = SignalBkgOrRefl.BACKGROUND elif signal_bkg_or_refl == "reflection": self._signal_bkg_or_refl = SignalBkgOrRefl.REFLECTION else: Logger(f"Invalid value for signal_bkg_or_refl: {signal_bkg_or_refl}" ", expected 'signal', 'background', or 'reflection'.", "FATAL")Set whether the PDF is signal, background, or reflection
def uses_m_not_mu(self)-
Expand source code
def uses_m_not_mu(self): """Check if this PDF uses m instead of mu""" return self._kind_pdf.uses_m_not_mu()Check if this PDF uses m instead of mu
class PDFKind (kind: PDFType | str,
order: int | None = None)-
Expand source code
@dataclass class PDFKind: """Class representing the kind of PDF""" kind: Union[PDFType, str] order: Union[int, None] = None def __post_init__(self): # Allow to use string representation for kind if isinstance(self.kind, str): self.kind = PDFType(self.kind) def __eq__(self, other): if isinstance(other, PDFKind): return self.kind is other.kind if isinstance(other, PDFType): return self.kind is other return NotImplemented def __hash__(self): return hash(self.kind) def __getattr__(self, name): """Delegate unknown attributes/methods to PDFType Enum""" return getattr(self.kind, name)Class representing the kind of PDF
Instance variables
var kind : PDFType | strvar order : int | None
class PDFType (*args, **kwds)-
Expand source code
class PDFType(Enum): """Enumeration of supported PDF types""" # Signal PDFs NO_SIGNAL = "nosignal" GAUSSIAN = "gaussian" DOUBLE_GAUS = "doublegaus" GAUS_EXP_TAIL = "gausexptail" GENER_GAUS_EXP_TAIL = "genergausexptail" GENER_GAUS_EXP_TAIL_SYMM = "genergausexptailsymm" BIFUR_GAUS = "bifurgaus" CRYSTAL_BALL = "crystalball" DOUBLE_CB = "doublecb" DOUBLE_CB_SYMM = "doublecbsymm" GENER_CRYSTAL_BALL = "genercrystalball" CAUCHY = "cauchy" VOIGTIAN = "voigtian" KDE_EXACT = "kde_exact" KDE_GRID = "kde_grid" KDE_FFT = "kde_fft" KDE_ISJ = "kde_isj" HIST = "hist" # Background PDFs NO_BKG = "nobkg" CHEBPOL = "chebpol" EXPO = "expo" POW_LAW = "powlaw" EXPO_POW = "expopow" EXPO_POW_EXT = "expopowext" # Reflection PDFs NONE = "none" def is_kde(self) -> bool: """Check if PDF type is KDE""" return self.value.startswith("kde_") def is_hist(self) -> bool: """Check if PDF type is histogram""" return self.value == "hist" def has_sigma(self) -> bool: """Check if PDF type has sigma parameter""" return self.value in [ "gaussian", "gausexptail", "genergausexptailsymm", "crystalball", "doublecb", "doublecbsymm", "voigtian", "hist", ] def has_hwhm(self) -> bool: """Check if PDF type has HWHM""" return self.value in ["gaussian", "cauchy", "voigtian"] def uses_m_not_mu(self) -> bool: """Check if PDF uses 'm' instead of 'mu' for mass parameter""" return self.value in ["cauchy", "voigtian"] def mass_limits(self) -> bool: """Check if PDF has mass limits""" return self.value in ["powlaw", "expopow", "expopowext"]Enumeration of supported PDF types
Ancestors
- enum.Enum
Class variables
var BIFUR_GAUSvar CAUCHYvar CHEBPOLvar CRYSTAL_BALLvar DOUBLE_CBvar DOUBLE_CB_SYMMvar DOUBLE_GAUSvar EXPOvar EXPO_POWvar EXPO_POW_EXTvar GAUSSIANvar GAUS_EXP_TAILvar GENER_CRYSTAL_BALLvar GENER_GAUS_EXP_TAILvar GENER_GAUS_EXP_TAIL_SYMMvar HISTvar KDE_EXACTvar KDE_FFTvar KDE_GRIDvar KDE_ISJvar NONEvar NO_BKGvar NO_SIGNALvar POW_LAWvar VOIGTIAN
Methods
def has_hwhm(self) ‑> bool-
Expand source code
def has_hwhm(self) -> bool: """Check if PDF type has HWHM""" return self.value in ["gaussian", "cauchy", "voigtian"]Check if PDF type has HWHM
def has_sigma(self) ‑> bool-
Expand source code
def has_sigma(self) -> bool: """Check if PDF type has sigma parameter""" return self.value in [ "gaussian", "gausexptail", "genergausexptailsymm", "crystalball", "doublecb", "doublecbsymm", "voigtian", "hist", ]Check if PDF type has sigma parameter
def is_hist(self) ‑> bool-
Expand source code
def is_hist(self) -> bool: """Check if PDF type is histogram""" return self.value == "hist"Check if PDF type is histogram
def is_kde(self) ‑> bool-
Expand source code
def is_kde(self) -> bool: """Check if PDF type is KDE""" return self.value.startswith("kde_")Check if PDF type is KDE
def mass_limits(self) ‑> bool-
Expand source code
def mass_limits(self) -> bool: """Check if PDF has mass limits""" return self.value in ["powlaw", "expopow", "expopowext"]Check if PDF has mass limits
def uses_m_not_mu(self) ‑> bool-
Expand source code
def uses_m_not_mu(self) -> bool: """Check if PDF uses 'm' instead of 'mu' for mass parameter""" return self.value in ["cauchy", "voigtian"]Check if PDF uses 'm' instead of 'mu' for mass parameter