gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
slhaea_spec_helpers.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
25 
27 #include "gambit/Utils/version.hpp"
31 
32 namespace Gambit
33 {
34 
36  void SLHAea_add_from_subspec(SLHAstruct& slha /*modify*/, const str local_info, const SubSpectrum& subspec,
37  const Par::Tags partype, const std::pair<int, int>& pdg_pair, const str& block, const str& comment,
38  const bool error_if_missing, const double rescale)
39  {
40  if(subspec.has(partype,pdg_pair))
41  {
42  SLHAea_overwrite_block(slha, block, pdg_pair.first, subspec.get(partype,pdg_pair)*rescale, (comment == "" ? "" : "# " + comment));
43  }
44  else if(error_if_missing)
45  {
46  std::ostringstream errmsg;
47  errmsg << "Error creating SLHAea output from SubSpectrum object! Required entry not found (paramtype="<<Par::toString.at(partype)
48  <<", pdg:context="<<pdg_pair.first<<":"<<pdg_pair.second<<")";
49  utils_error().raise(local_info,errmsg.str());
50  }
51  // else skip this entry
52  return;
53  }
54 
56  void SLHAea_add_from_subspec(SLHAstruct& slha /*modify*/, const str local_info, const SubSpectrum& subspec,
57  const Par::Tags partype, const str& name, const str& block, const int slha_index,
58  const str& comment, const bool error_if_missing, const double rescale)
59  {
60  if(subspec.has(partype,name))
61  {
62  SLHAea_overwrite_block(slha, block, slha_index, subspec.get(partype,name)*rescale, (comment == "" ? "" : "# " + comment));
63  }
64  else if(error_if_missing)
65  {
66  std::ostringstream errmsg;
67  errmsg << "Error creating SLHAea output from SubSpectrum object! Required entry not found (paramtype="<<Par::toString.at(partype)<<", name="<<name<<")";
68  utils_error().raise(local_info,errmsg.str());
69  }
70  // else skip this entry
71  return;
72  }
73 
75  void SLHAea_add_from_subspec(SLHAstruct& slha /*modify*/, const str local_info, const SubSpectrum& subspec,
76  const Par::Tags partype, const str& name, const int index1, const int index2, const str& block,
77  const int slha_index1, const int slha_index2, const str& comment, const bool error_if_missing, const double rescale)
78  {
79  if(subspec.has(partype,name,index1,index2))
80  {
81  SLHAea_overwrite_block(slha, block, slha_index1, slha_index2, subspec.get(partype,name,index1,index2)*rescale, (comment == "" ? "" : "# " + comment));
82  }
83  else if(error_if_missing)
84  {
85  std::ostringstream errmsg;
86  errmsg << "Error creating SLHAea output from SubSpectrum object! Required entry not found (paramtype="<<Par::toString.at(partype)<<", name="<<name<<", index1="<<index1<<", index2="<<index2;
87  utils_error().raise(local_info,errmsg.str());
88  }
89  // else skip this entry
90  return;
91  }
92 
95  const std::pair<int,int> pdg_pair)
96  {
97  if (subspec.has(Par::Pole_Mass,pdg_pair))
98  {
99  str long_name = Models::ParticleDB().long_name(pdg_pair);
100  int spinx2 = Models::ParticleDB().get_spinx2(long_name);
101  int chargex3 = Models::ParticleDB().get_chargex3(long_name);
102  int color = Models::ParticleDB().get_color(long_name);
103  bool is_anti = Models::ParticleDB().has_antiparticle(long_name);
104 
105  SLHAea::Block QNblock("QNUMBERS");
106  SLHAea::Line line1, line2, line3, line4, line5;
107  line1 << "BLOCK" << "QNUMBERS" << pdg_pair.first << "# " + long_name;
108  line2 << 1 << chargex3 << "# 3 times electric charge";
109  line3 << 2 << spinx2+1 << "# number of spin states (2S+1)";
110  line4 << 3 << color << "# colour rep (1: singlet, 3: triplet, 8: octet)";
111  line5 << 4 << is_anti << "# Particle/Antiparticle distinction (0=own anti)";
112  QNblock.push_back(line1);
113  QNblock.push_back(line2);
114  QNblock.push_back(line3);
115  QNblock.push_back(line4);
116  QNblock.push_back(line5);
117  slha.push_front(QNblock);
118 
119  }
120  }
121 
123  void add_SimpleSpec_to_SLHAea(const SubSpectrum& subspec, SLHAstruct& slha, const SubSpectrumContents& contents)
124  {
125 
126  // Pick out the parameters whose SLHA block name is not: SMINPUTS, CKMBLOCK, YUKAWA, or empty.
127  std::vector<SpectrumParameter> bsm = contents.all_BSM_parameters();
128 
129  // Then assign them to the correct part of the SLHAea object
130  for (std::vector<SpectrumParameter>::const_iterator it = bsm.begin(); it != bsm.end(); ++it)
131  {
132  // The SLHAea comment changes based on the ParType
133  std::ostringstream comment;
134 
135  // If it's a mass, we always want to write it to the MASS block. Otherwise use what's been specified explicitly.
136  str blockname = (it->tag() == Par::Pole_Mass ? "MASS" : it->blockname());
137 
138  // Masses
139  if (it->tag() == Par::Pole_Mass)
140  {
141  comment << it->name() << " mass.";
142  std::pair<int, int> pdg_pair = Models::ParticleDB().pdg_pair(it->name());
143  SLHAea_add_from_subspec(slha, LOCAL_INFO, subspec, it->tag(), pdg_pair, blockname, comment.str());
144  SLHAea_add_QNumbers_from_subspec(slha, subspec, pdg_pair);
145  }
146  // The rest
147  else
148  {
149  // Scalar case
150  if (it->shape().size()==1 and it->shape()[0]==1)
151  {
152  SLHAea_add_from_subspec(slha, LOCAL_INFO, subspec, it->tag(), it->name(), blockname, it->blockindex(), comment.str());
153  }
154  // Vector (1 index)
155  else if (it->shape().size() == 1 and it->shape()[0] > 1)
156  {
157  for (int i=1; i<it->shape()[0]+1; ++i)
158  {
159  // Increment +1 to each entry for the BLOCKNAME
160  SLHAea_add_from_subspec(slha, LOCAL_INFO, subspec, it->tag(), it->name(), blockname, it->blockindex()+i, comment.str());
161  }
162  }
163  // Matrix (2 indices) -- blockindex() should just start from 1.
164  else if (it->shape().size() == 2)
165  {
166  for (int i=1; i<it->shape()[0]+1; ++i)
167  {
168  for (int j=1; j<it->shape()[0]+1; ++j)
169  {
170  SLHAea_add_from_subspec(slha, LOCAL_INFO, subspec, it->tag(), it->name(), i, j, blockname, i, j, comment.str());
171  }
172  }
173  }
174  }
175  }
176 
177  }
178 
179 }
void SLHAea_add_QNumbers_from_subspec(SLHAstruct &slha, const SubSpectrum &subspec, const std::pair< int, int > pdg_pair)
Adds QNUMBERS entry for a particle, SLHA index given by the PDG code.
EXPORT_SYMBOLS error & utils_error()
Utility errors.
int get_spinx2(std::pair< int, int >) const
Get spin (x2) of a given particle, using the PDG code and context integer.
Definition: partmap.cpp:360
#define LOCAL_INFO
Definition: local_info.hpp:34
str long_name(str, int) const
Retrieve the long name, from the short name and index.
Definition: partmap.cpp:124
void add_SimpleSpec_to_SLHAea(const SubSpectrum &, SLHAstruct &, const SubSpectrumContents &)
Write a SimpleSpectrum to an SLHAea object.
int get_chargex3(std::pair< int, int >) const
Get charge (x3) of a given particle, using the PDG code and context integer.
Definition: partmap.cpp:432
std::pair< int, int > pdg_pair(str) const
Retrieve the PDG code and context integer, from the long name.
Definition: partmap.cpp:95
bool has_antiparticle(str) const
Check if a particle has a matching anti-particle in the database, using the long name.
Definition: partmap.cpp:277
SLHAea::Coll SLHAstruct
Less confusing name for SLHAea container class.
virtual double get(const Par::Tags, const str &, const SpecOverrideOptions=use_overrides, const SafeBool check_antiparticle=SafeBool(true)) const =0
Nicer alias for SLHAea container class, and some convenient helper functions that add or retrieve the...
std::vector< SpectrumParameter > all_BSM_parameters() const
Function to retrieve all parameters whose blockName is not SMINPUTS, YUKAWA, CKMBLOCK, or empty.
partmap & ParticleDB()
Database accessor function.
Definition: partmap.cpp:36
void SLHAea_overwrite_block(SLHAstruct &slha, const str &block, int index, T value, const str &comment)
Check if a line exists in an SLHAea block, then overwrite it if it does. Otherwise add the line...
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Abstract class for accessing general spectrum information.
Virtual base class for interacting with spectrum generator output.
Definition: subspectrum.hpp:87
SLHAea helper functions using spectrum objects.
Exception objects required for standalone compilation.
Base class for defining the required contents of a SubSpectrum object.
int get_color(std::pair< int, int >) const
Get color of a given particle, using the PDG code and context integer.
Definition: partmap.cpp:504
Version numbering.
void SLHAea_add_from_subspec(SLHAstruct &slha, const str local_info, const SubSpectrum &subspec, const Par::Tags partype, const std::pair< int, int > &pdg_pair, const str &block, const str &comment, const bool error_if_missing=true, const double rescale=1.0)
Add an entry from a subspectrum getter to an SLHAea object; SLHA index given by pdg code...
TODO: see if we can use this one:
Definition: Analysis.hpp:33
virtual bool has(const Par::Tags, const str &, const SpecOverrideOptions=use_overrides, const SafeBool check_antiparticle=SafeBool(true)) const =0
Getters/Setters etc.