13std::optional<LhaID> canonicalize_legacy_polarization_id(
const LhaID& ext) {
15 if (parts.size() < 2) {
30 return LhaID(std::move(parts));
36 const auto key =
nk(s);
39 if (
nk(name) == key) {
44 throw std::out_of_range(
"Unknown builtin observable: " + std::string(s));
50 throw std::out_of_range(
"Unknown observable (FLHA): " + ext.
to_string());
53 auto maybeEnum =
enum_of(*maybeId);
55 throw std::out_of_range(
"ObservableId has no builtin enum: " + maybeId->str());
66 const auto canonical = canonicalize_legacy_polarization_id(ext);
80 }
catch (
const std::exception&) {
88 }
catch (
const std::exception&) {
96 throw std::runtime_error(
"Unknown binned observable (FLHA): " + ext.
to_string());
106 std::vector<std::string> aliases,
107 std::optional<LhaID> ext,
130 std::vector<std::string> aliases,
131 std::optional<LhaID> ext,
143 std::vector<std::string> aliases,
144 std::optional<LhaID> ext,
145 std::string_view parent_decay_str)
158 throw std::runtime_error(
"Observable has no FLHA: " +
id.
str());
166 throw std::runtime_error(
"BinnedObservableId has no FLHA: " +
id.
str());
Utilities for identifying observables together with numerical bins.
const std::map< Observables, std::string > & observable_mapping()
Returns the mapping between Observables and their string names.
const std::map< Observables, LhaID > & observable_flha_mapping()
Returns the mapping between Observables and their FLHA identifiers.
Helpers for project-defined FLHA observable-type identifiers.
constexpr long kLegacyFermionPolarizationTypeId
Legacy v1.0.0–v1.0.1 type used for charged-lepton polarization.
constexpr long kLegacyLongitudinalVectorPolarizationTypeId
Legacy v1.0.0–v1.0.1 type used for longitudinal vector polarization.
constexpr long make_polarization_type_id(PolarizationKind kind, unsigned int daughter_position)
Build a project-defined FLHA polarization type id using 92ij.
static DecayGraph & instance()
Return the unique global graph instance.
void link(const DecayId &decay, const ObservableId &obs)
Link an observable to a parent decay.
static bool register_custom(std::string canonical, std::vector< std::string > aliases={}, std::optional< LhaID > ext=std::nullopt)
Registers a custom entry with optional external key.
static std::optional< LhaID > external_of(const IdOf< ObservableTag > &id)
Returns the external key associated with a given identifier.
static std::optional< Observables > enum_of(const IdOf< ObservableTag > &id)
Attempts to recover the enum value associated with an identifier.
static std::optional< IdOf< ObservableTag > > from_external(const LhaID &k)
Resolves an external key into an identifier.
static IdOf< DecayTag > to_id(Decays e)
Converts an enum value to an IdOf<Tag>.
static IdOf< DecayTag > id_of(std::string_view s)
Resolves a string into an IdOf<Tag> via the registry.
static std::string str(const IdOf< ObservableTag > &id)
Returns the string representation of an identifier.
static std::optional< ObservableId > from_flha(const LhaID &ext)
Resolve a FLHA id to a dynamic observable id.
static BinnedObservableId binned_from_flha(const LhaID &ext)
Throwing variant of from_binned_flha().
static std::optional< LhaID > flha_of(const ObservableId &id)
Return the FLHA id attached to an observable id, if any.
static std::optional< LhaID > binned_flha_of(const BinnedObservableId &id)
Encode a binned observable id into its FLHA representation.
static LhaID flha(const Observables &id)
Return the FLHA id associated with a builtin enum value.
static Observables enum_elt(const LhaID &ext)
Legacy builtin-only lookup from FLHA id to enum.
static bool register_custom(const std::string &canonical, std::vector< std::string > aliases, std::optional< LhaID > ext, const DecayId &parent_decay)
Register a custom observable and attach it to a parent decay.
static Observables enum_elt_legacy(std::string_view s)
Legacy builtin-only lookup from string to enum.
static std::optional< BinnedObservableId > from_binned_flha(const LhaID &ext)
Decode a binned FLHA id into a binned observable id.
Returns an uppercase copy of the input string.
const std::string & str() const
Returns the underlying string.
Mapper and dynamic identifiers for decay channels.
std::string nk(std::string_view s)
Shortcut helper to normalize a string_view into a canonical key.
Mapper for builtin and runtime observable identifiers.
Identifies an observable together with a numerical bin.
static BinnedObservableId from_flha(LhaID const &id)
Reconstructs a binned observable identifier from an FLHA encoding.
Represents an identifier of a LHA element, possibly containing several sub-ids.
std::vector< long > get_parts() const
Returns the underlying vector of sub-ids.
std::string to_string() const
Returns the canonical string representation of this LhaID.