Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
wcoef_ids.hpp
Go to the documentation of this file.
1#ifndef WCOEF_IDS_H
2#define WCOEF_IDS_H
3
4#include "generic_mapper.h"
5#include "Map.h"
6#include "hash_utils.hpp"
7#include "GeneralEnum.h"
8#include <stdexcept>
9#include "LhaID.h"
10
28struct WCoefTag {};
29
32
53 WCoefTag, WCoef,
54 std::pair<int,int>, PairHash,
55 wcoef_mapping, wcoef_flha_mapping
56 >
57{
58public:
62
74 static WCoef from_flha(int a,int b){
75 static const auto inv = []{
76 std::map<std::pair<int,int>, WCoef> m;
77 for (auto& [e,p] : wcoef_flha_mapping()) m.emplace(p,e);
78 return m;
79 }();
80 auto it = inv.find({a,b});
81 if (it==inv.end()) throw std::out_of_range("Unsupported FLHA key");
82 return it->second;
83 }
84
94 static std::optional<WCoefId> from_flha_key(int a,int b){ return Base::from_external({a,b}); }
95
104 static std::pair<int,int> flha_base(WCoef e){
106 }
107
119 static std::pair<int,int> flha_base(const WCoefId& id){
120 if (auto e = enum_of(id)) {
121 const WCoef canonical = canonical_flha_coef(*e);
122 auto it = wcoef_flha_mapping().find(canonical);
123 if (it != wcoef_flha_mapping().end()) return it->second;
124 }
125
126 auto k = external_of(id);
127 if (!k) throw std::runtime_error("No FLHA key for " + id.str());
128 return *k; // std::pair<int,int>
129 }
130
147 switch (e) {
148 case WCoef::CQ1: return WCoef::CQ1_MU;
149 case WCoef::CQ2: return WCoef::CQ2_MU;
150 case WCoef::CPQ1: return WCoef::CPQ1_MU;
151 case WCoef::CPQ2: return WCoef::CPQ2_MU;
152 default: return e;
153 }
154 }
155
157 auto [x,y] = wcoef_flha_mapping().at(canonical_flha_coef(e));
158 return LhaID{x,y, int(q)-1, int(c)};
159 }
160
173 static std::pair<WCoefId, std::pair<QCDOrder, ContributionType>> lha_wilson_deserialize(LhaID id) {
174 auto parts = id.get_parts();
175 auto w_id = std::make_pair(parts[0], parts[1]);
176
177 auto maybe = WCoefMapper::from_flha_key(w_id.first, w_id.second);
178 if (!maybe) {
179 LOG_ERROR("ValueError", "bad lha id for wilson conversion (unknown custom/base key)");
180 }
181 WCoefId coef = *maybe;
182 QCDOrder order = parts[2] ? ((parts[2] -1) ? QCDOrder::NNLO : QCDOrder::NLO) : QCDOrder::LO;
184
185 std::pair<WCoefId, std::pair<QCDOrder, ContributionType>> ret;
186 ret = {coef, {order, part}};
187
188 return ret;
189 }
204 if (auto e = enum_of(id)) {
205 const WCoef canonical = canonical_flha_coef(*e);
206 auto it = wcoef_flha_mapping().find(canonical);
207 if (it != wcoef_flha_mapping().end()) {
208 return LhaID{it->second.first, it->second.second, int(q)-1, int(c)};
209 }
210 }
211
212 auto k = external_of(id);
213 if (!k) throw std::runtime_error("No FLHA key for "+id.str());
214 return LhaID{k->first, k->second, int(q)-1, int(c)};
215 }
216
220 static size_t n_wilsons(){ return wcoef_mapping().size(); }
221
229 static const std::map<std::pair<int,int>, WCoef>& inverse_flha_mapping() {
230 static const std::map<std::pair<int,int>, WCoef> inv = []{
231 std::map<std::pair<int,int>, WCoef> m;
232 for (const auto& [e, ab] : wcoef_flha_mapping()) m.emplace(ab, e);
233 return m;
234 }();
235 return inv;
236 }
237
239 static const std::vector<WCoef>& B_group(){
240 static const std::vector<WCoef> g = {
243 }; return g;
244 }
245
246 static constexpr int lepton_mass_slot_from_index(int lepton_index) {
247 return 31 + lepton_index;
248 }
249
250 static constexpr int thdm_lepton_yukawa_slot_from_index(int lepton_index) {
251 return 101 + lepton_index;
252 }
253
254 static constexpr int lepton_index_from_pdg(int pdg) {
255 return pdg == 11 ? 0 : pdg == 13 ? 1 : pdg == 15 ? 2 : -1;
256 }
257
258
259 static int lepton_index_from_cq1(WCoef coef) {
260 switch (coef) {
261 case WCoef::CQ1_E: return 0;
262 case WCoef::CQ1_MU:
263 case WCoef::CQ1: return 1;
264 case WCoef::CQ1_TA: return 2;
265 default: throw std::out_of_range("Coefficient is not a CQ1 lepton-specific coefficient");
266 }
267 }
268
269 static int lepton_index_from_cq2(WCoef coef) {
270 switch (coef) {
271 case WCoef::CQ2_E: return 0;
272 case WCoef::CQ2_MU:
273 case WCoef::CQ2: return 1;
274 case WCoef::CQ2_TA: return 2;
275 default: throw std::out_of_range("Coefficient is not a CQ2 lepton-specific coefficient");
276 }
277 }
278
279 static int lepton_index_from_cpq1(WCoef coef) {
280 switch (coef) {
281 case WCoef::CPQ1_E: return 0;
282 case WCoef::CPQ1_MU:
283 case WCoef::CPQ1: return 1;
284 case WCoef::CPQ1_TA: return 2;
285 default: throw std::out_of_range("Coefficient is not a CPQ1 lepton-specific coefficient");
286 }
287 }
288
289 static int lepton_index_from_cpq2(WCoef coef) {
290 switch (coef) {
291 case WCoef::CPQ2_E: return 0;
292 case WCoef::CPQ2_MU:
293 case WCoef::CPQ2: return 1;
294 case WCoef::CPQ2_TA: return 2;
295 default: throw std::out_of_range("Coefficient is not a CPQ2 lepton-specific coefficient");
296 }
297 }
298
299 static WCoef cq1_for_lepton_index(int lepton_index) {
300 switch (lepton_index) {
301 case 0: return WCoef::CQ1_E;
302 case 1: return WCoef::CQ1_MU;
303 case 2: return WCoef::CQ1_TA;
304 default: throw std::out_of_range("Invalid zero-based lepton generation index for CQ1");
305 }
306 }
307
308 static WCoef cq2_for_lepton_index(int lepton_index) {
309 switch (lepton_index) {
310 case 0: return WCoef::CQ2_E;
311 case 1: return WCoef::CQ2_MU;
312 case 2: return WCoef::CQ2_TA;
313 default: throw std::out_of_range("Invalid zero-based lepton generation index for CQ2");
314 }
315 }
316
317 static WCoef cpq1_for_lepton_index(int lepton_index) {
318 switch (lepton_index) {
319 case 0: return WCoef::CPQ1_E;
320 case 1: return WCoef::CPQ1_MU;
321 case 2: return WCoef::CPQ1_TA;
322 default: throw std::out_of_range("Invalid zero-based lepton generation index for CPQ1");
323 }
324 }
325
326 static WCoef cpq2_for_lepton_index(int lepton_index) {
327 switch (lepton_index) {
328 case 0: return WCoef::CPQ2_E;
329 case 1: return WCoef::CPQ2_MU;
330 case 2: return WCoef::CPQ2_TA;
331 default: throw std::out_of_range("Invalid zero-based lepton generation index for CPQ2");
332 }
333 }
334
335 static bool is_cpq(WCoef c) {
336 return c == WCoef::CPQ1_E || c == WCoef::CPQ1_MU || c == WCoef::CPQ1_TA
337 || c == WCoef::CPQ2_E || c == WCoef::CPQ2_MU || c == WCoef::CPQ2_TA
338 || c == WCoef::CPQ1 || c == WCoef::CPQ2;
339 }
340
342 static const std::vector<WCoef>& B_prime_group(){
343 static const std::vector<WCoef> g = {
348 }; return g;
349 }
350
352 static const std::vector<WCoef>& B_scalar_group(){
353 static const std::vector<WCoef> g = {
356 }; return g;
357 }
358
360 static const std::vector<WCoef>& b_clnu_group(){
361 static const std::vector<WCoef> g = { WCoef::C_V1_bc, WCoef::C_V2_bc, WCoef::C_S1_bc, WCoef::C_S2_bc, WCoef::C_T_bc }; return g;
362 }
363
365 static const std::vector<WCoef>& b_ulnu_group(){
366 static const std::vector<WCoef> g = { WCoef::C_V1_bu, WCoef::C_V2_bu, WCoef::C_S1_bu, WCoef::C_S2_bu, WCoef::C_T_bu }; return g;
367 }
368
370 static const std::vector<WCoef>& c_slnu_group(){
371 static const std::vector<WCoef> g = { WCoef::C_V1_cs, WCoef::C_V2_cs, WCoef::C_S1_cs, WCoef::C_S2_cs, WCoef::C_T_cs }; return g;
372 }
373
375 static const std::vector<WCoef>& c_dlnu_group(){
376 static const std::vector<WCoef> g = { WCoef::C_V1_cd, WCoef::C_V2_cd, WCoef::C_S1_cd, WCoef::C_S2_cd, WCoef::C_T_cd }; return g;
377 }
378
380 static const std::vector<WCoef>& s_ulnu_group(){
381 static const std::vector<WCoef> g = { WCoef::C_V1_su, WCoef::C_V2_su, WCoef::C_S1_su, WCoef::C_S2_su, WCoef::C_T_su }; return g;
382 }
383
385 static const std::vector<WCoef>& d_ulnu_group(){
386 static const std::vector<WCoef> g = { WCoef::C_V1_du, WCoef::C_V2_du, WCoef::C_S1_du, WCoef::C_S2_du, WCoef::C_T_du}; return g;
387 }
388
390 static const std::vector<WCoef>& k_group(){
391 static const std::vector<WCoef> g = { WCoef::CK9, WCoef::CK10, WCoef::CKQ1, WCoef::CKQ2, WCoef::CK_L, WCoef::CPK9, WCoef::CPK10, WCoef::CPKQ1, WCoef::CPKQ2}; return g;
392 }
393
407
418 static std::vector<WCoef> get_group(WGroup g){
419 switch (g){
420 case WGroup::B: return {B_group().begin(), B_group().end()};
421 case WGroup::BPrime: return {B_prime_group().begin(), B_prime_group().end()};
422 case WGroup::BScalar: return {B_scalar_group().begin(), B_scalar_group().end()};
423 case WGroup::CC_bc: return {b_clnu_group().begin(), b_clnu_group().end()};
424 case WGroup::CC_bu: return {b_ulnu_group().begin(), b_ulnu_group().end()};
425 case WGroup::CC_cs: return {c_slnu_group().begin(), c_slnu_group().end()};
426 case WGroup::CC_cd: return {c_dlnu_group().begin(), c_dlnu_group().end()};
427 case WGroup::CC_su: return {s_ulnu_group().begin(), s_ulnu_group().end()};
428 case WGroup::CC_du: return {d_ulnu_group().begin(), d_ulnu_group().end()};
429 case WGroup::K: return {k_group().begin(), k_group().end()};
430 case WGroup::MESON_MIXING: return {meson_mixing_group().begin(), meson_mixing_group().end()};
431 default: LOG_ERROR("Invalid WGroup","get_group couldn't find your group"); return {};
432 }
433 }
434
446 if (c == WCoef::CQ1 || c == WCoef::CQ2) return WGroup::BScalar;
447 if (c == WCoef::CPQ1 || c == WCoef::CPQ2) return WGroup::BPrime;
448
449 static const std::map<WCoef, WGroup> inv = []{
450 std::map<WCoef, WGroup> m;
451
452 auto add = [&](WGroup g, const std::vector<WCoef>& v){
453 for (auto e : v) {
454 // optional safety: detect duplicates across groups
455 if (m.find(e) != m.end())
456 throw std::runtime_error("WCoef appears in multiple WGroups");
457 m.emplace(e, g);
458 }
459 };
460
461 add(WGroup::B, B_group());
470 add(WGroup::K, k_group());
472
473 return m;
474 }();
475
476 auto it = inv.find(c);
477 if (it == inv.end()) throw std::out_of_range("WCoef not assigned to any WGroup");
478 return it->second;
479 }
480
484 static std::optional<WGroup> group_of_opt(WCoef c){
485 try { return group_of(c); }
486 catch (...) { return std::nullopt; }
487 }
488
494 static WGroup group_of(const WCoefId& id){
495 auto e = enum_of(id);
496 if (!e) throw std::runtime_error("Unknown WCoefId: " + id.str());
497 return group_of(*e);
498 }
499};
500
501#endif
QCDOrder
ContributionType
WCoef
WGroup
@ MESON_MIXING
Lightweight representation of LHAPDF / SLHA-style identifiers.
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
Definition Logger.h:41
const std::map< WCoef, std::pair< int, int > > & wcoef_flha_mapping()
Returns the mapping between WCoef and its FLHA (block, index) pair.
Definition Map.cpp:1170
const std::map< WCoef, std::string > & wcoef_mapping()
Returns the mapping between WCoef and its string name.
Definition Map.cpp:1142
Static mappings between enum classes and string (or FLHA) identifiers.
Generic enum↔string mapper with external keys and dynamic aliases.
static std::optional< std::pair< int, int > > external_of(const IdOf< WCoefTag > &id)
Returns the external key associated with a given identifier.
static std::optional< WCoef > enum_of(const IdOf< WCoefTag > &id)
Attempts to recover the enum value associated with an identifier.
static IdOf< WCoefTag > enum_elt(std::string_view s)
Alias for id_of(), kept for compatibility.
static std::optional< IdOf< WCoefTag > > from_external(const std::pair< int, int > &k)
Resolves an external key into an identifier.
static IdOf< WCoefTag > to_id(WCoef e)
Converts an enum value to an IdOf<Tag>.
static std::string str(const IdOf< WCoefTag > &id)
Returns the string representation of an identifier.
High-level mapper for WCoef <-> text <-> FLHA base indices.
Definition wcoef_ids.hpp:57
static const std::vector< WCoef > & s_ulnu_group()
Charged-current Wilsons for s -> u l ν.
static LhaID flha_full(const WCoefId &id, QCDOrder q, ContributionType c)
Builds a full FLHA LhaID for a given WCoefId, order and contribution.
static std::pair< int, int > flha_base(WCoef e)
Returns the base FLHA pair (a,b) for a given WCoef.
static constexpr int lepton_index_from_pdg(int pdg)
static WCoef canonical_flha_coef(WCoef e)
Builds a full FLHA LhaID for a given WCoef, order and contribution.
static const std::vector< WCoef > & c_slnu_group()
Charged-current Wilsons for c -> s l ν.
static LhaID flha_full(WCoef e, QCDOrder q, ContributionType c)
static constexpr int lepton_mass_slot_from_index(int lepton_index)
static const std::vector< WCoef > & b_ulnu_group()
Charged-current Wilsons for b -> u l ν.
static WCoef cpq1_for_lepton_index(int lepton_index)
static std::pair< int, int > flha_base(const WCoefId &id)
Returns the base FLHA pair (a,b) for a given WCoefId.
static std::optional< WGroup > group_of_opt(WCoef c)
Optional version: returns std::nullopt if not in any group.
static const std::vector< WCoef > & b_clnu_group()
Charged-current Wilsons for b -> c l ν.
static const std::vector< WCoef > & k_group()
Kaon-sector Wilsons (K group).
static int lepton_index_from_cq1(WCoef coef)
static bool is_cpq(WCoef c)
static const std::vector< WCoef > & B_scalar_group()
Scalar B-group coefficients, split by charged-lepton generation.
static WGroup group_of(const WCoefId &id)
Convenience overload for identifiers.
static WCoef cq1_for_lepton_index(int lepton_index)
static WCoef cq2_for_lepton_index(int lepton_index)
static WCoef from_flha(int a, int b)
Returns the WCoef associated with a given FLHA base key (a,b).
Definition wcoef_ids.hpp:74
static std::vector< WCoef > get_group(WGroup g)
Returns the list of Wilson coefficients belonging to a WGroup.
static WCoef cpq2_for_lepton_index(int lepton_index)
static std::optional< WCoefId > from_flha_key(int a, int b)
Registry-based lookup of WCoefId from a FLHA base key (a,b).
Definition wcoef_ids.hpp:94
static std::pair< WCoefId, std::pair< QCDOrder, ContributionType > > lha_wilson_deserialize(LhaID id)
Deserialize the id of a Wilson coefficient into (WCoefId, QCDOrder, ContributionType) using lha conve...
static int lepton_index_from_cq2(WCoef coef)
static const std::map< std::pair< int, int >, WCoef > & inverse_flha_mapping()
Returns a static inverse mapping FLHA base pair -> WCoef.
static size_t n_wilsons()
Returns the total number of Wilson coefficients in the mapping.
static const std::vector< WCoef > & B_group()
B-group (C1–C10) Wilson coefficients.
static int lepton_index_from_cpq1(WCoef coef)
static constexpr int thdm_lepton_yukawa_slot_from_index(int lepton_index)
static const std::vector< WCoef > & c_dlnu_group()
Charged-current Wilsons for c -> d l ν.
static int lepton_index_from_cpq2(WCoef coef)
static const std::vector< WCoef > & meson_mixing_group()
Wilsons relevant for neutral meson mixing (B, K, D sectors).
static WGroup group_of(WCoef c)
Returns the WGroup to which a given Wilson coefficient belongs.
static const std::vector< WCoef > & B_prime_group()
B'-group coefficients (primed + lepton-specific scalar primed).
static const std::vector< WCoef > & d_ulnu_group()
Charged-current Wilsons for d -> u l ν.
constexpr double g
Generic enum↔string (and optional external key) mappers built on DynamicRegistry.
Represents an identifier of a LHA element, possibly containing several sub-ids.
Definition LhaID.h:56
Hash functor for std::pair<int,int>.
Tag type for Wilson-coefficient identifiers.
Definition wcoef_ids.hpp:28