gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
SUSY_extras.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
16 
19 
20 namespace Gambit
21 {
22  namespace ColliderBit
23  {
24 
25  // Get Monte Carlo event generator from SLHA file input
27 
28 
29  // Get next SLHA file path and content (for use with model ColliderBit_SLHA_file_model)
30  void getNextSLHAFileNameAndContent(pair_str_SLHAstruct& result)
31  {
32  using namespace Pipes::getNextSLHAFileNameAndContent;
33 
34  static unsigned int counter = 0;
35  static bool first = true;
36 
37  if (first)
38  {
39  if (!runOptions->hasKey("SLHA_filenames")) ColliderBit_error().raise(LOCAL_INFO,"Expected YAML file option 'SLHA_filenames' (a list of SLHA filenames) not found.");
40  first = false;
41  }
42 
43  const static std::vector<str> filenames = runOptions->getValue<std::vector<str> >("SLHA_filenames");
44 
45  if (counter >= filenames.size())
46  {
47  invalid_point().raise("No more SLHA files. My work is done.");
48  result = std::make_pair("", SLHAstruct());
49  }
50  else
51  {
52  const str& filename = filenames.at(counter);
53  result = std::make_pair(filename, read_SLHA(filename));
54  }
55 
56  counter++;
57  }
58 
59 
60  // Read a single SLHA file and update some entries for each scan point
61  // (for use with model ColliderBit_SLHA_scan_model)
63  {
64  using namespace Pipes::getAndReplaceSLHAContent;
65 
66  static unsigned int counter = 0;
67 
68  static str filename;
69  static SLHAstruct file_content;
70 
71  static YAML::Node keysNode;
72  static Options keysOptions;
73  static std::map<str,str> SLHAkey_to_parname;
74 
75  // Do the variable initialization only once
76  static bool first = true;
77  if (first)
78  {
79  if (!runOptions->hasKey("SLHA_filename")) ColliderBit_error().raise(LOCAL_INFO,"Expected YAML file option 'SLHA_filename' (a single SLHA filename) not found.");
80  if (!runOptions->hasKey("replace_SLHA_keys")) ColliderBit_error().raise(LOCAL_INFO,"Expected YAML file option 'replace_SLHA_keys' (a list of strings in the SLHAea key format, e.g. 'MASS;1000022;1') not found.");
81 
82  // Get filename of base SLHA file
83  filename = runOptions->getValue<str>("SLHA_filename");
84 
85  // Read the original SLHA file once
86  file_content = read_SLHA(filename);
87 
88  // Get the YAML options under 'replace_SLHA_keys'
89  keysNode = runOptions->getValue<YAML::Node>("replace_SLHA_keys");
90  keysOptions = Options(keysNode);
91 
92  // Construct a map from SLHA keys to scan model parameters
93  for (const str& parname : keysOptions.getNames())
94  {
95  std::vector<str> slhakeys = keysOptions.getValue<std::vector<str> >(parname);
96  for (const str& slhakey : slhakeys)
97  {
98  SLHAkey_to_parname[slhakey] = parname;
99  }
100  }
101 
102  first = false;
103  }
104 
105  // Generate new SLHA content by replacing SLHA elements with scan parameters
106  SLHAstruct new_content(file_content);
107  static int precision = 8;
108  for (const auto& key_param_pair : SLHAkey_to_parname)
109  {
110  new_content.field(key_param_pair.first) = SLHAea::to_string(*Param.at(key_param_pair.second), precision);
111  }
112 
113  // Construct a dummy name for the SLHA "file" we pass around as a SLHAea object
114  std::stringstream filename_mod_ss;
115  filename_mod_ss << filename << ".point" << counter;
116 
117  // Save result as a pair_str_SLHAstruct
118  result = std::make_pair(filename_mod_ss.str(), new_content);
119 
121 
122  counter++;
123  }
124 
125 
126 
127  // Extract SLHA file elements (for use with model ColliderBit_SLHA_file_model)
129  {
130  using namespace Pipes::getSLHAFileElements;
131 
132  // Split the required SLHAFileNameAndContent pair
133  const str& filename = Dep::SLHAFileNameAndContent->first;
134  const SLHAstruct& content = Dep::SLHAFileNameAndContent->second;
135 
136  // Should missing elements be replaced by a default value?
137  const static bool use_missing_element_value = runOptions->hasKey("value_for_missing_elements");
138  static double missing_element_value;
139 
140  static bool first = true;
141  if (first)
142  {
143  // Check that the required YAML option "SLHA_keys" is present
144  if (!runOptions->hasKey("SLHA_keys")) ColliderBit_error().raise(LOCAL_INFO,"Expected YAML file option 'SLHA_keys' (a list of strings in the SLHAea key format, e.g. 'MASS;1000022;1') not found.");
145 
146  // Read default value for missing elements;
147  if (use_missing_element_value) missing_element_value = runOptions->getValue<double>("value_for_missing_elements");
148 
149  first = false;
150  }
151 
152  // Read the list of SLHA element keys
153  const static std::vector<str> slha_element_keys = runOptions->getValue<std::vector<str> >("SLHA_keys");
154 
155  // Loop through the list of SLHA keys and grab the corresponding elements from the SLHA content
156  for(str key_str : slha_element_keys)
157  {
158 
159  // Construct a SLHAea::Key from the key string
160  const SLHAea::Key key(key_str);
161 
162  // Grab the correct entryand store in the results map
163  try
164  {
165  result[key_str] = SLHAea::to<double>( content.field(key) );
166  }
167  catch (const std::out_of_range& e)
168  {
169  std::stringstream errmsg_ss;
170  errmsg_ss << "Could not find SLHA element " << key_str << " in file " << filename;
171 
172  if (use_missing_element_value)
173  {
174  logger() << errmsg_ss.str() << EOM;
175  result[key_str] = missing_element_value;
176  }
177  else
178  {
179  ColliderBit_error().raise(LOCAL_INFO, errmsg_ss.str());
180  }
181  }
182  }
183  }
184 
185 
186  // Extract an SLHAstruct with the specturm, either from the MSSM_spectrum
187  // capability (for MSSM models), or simply from the SLHAFileNameAndContent
188  // capability (for ColliderBit_SLHA_file_model, ColliderBit_SLHA_scan_model)
189 
190  // @todo Should we perform some kind of SLHA1 vs SLHA2 check when used with the
191  // ColliderBit_SLHA_* models below? For these models we currently just trust
192  // the user to supply SLHA info in the appropriate format.
193 
194  // @todo Should we unify these two functions into a single module function that just
195  // provides a std::function instance that can be called with an
196  // int argument = 1 or 2 and returns the appropriate SLHA1 or SLHA2 struct?
197 
198  // SLHA1
200  {
201  using namespace Pipes::getSLHA1Spectrum;
202 
203  static const bool write_summary_to_log = runOptions->getValueOrDef<bool>(false, "write_summary_to_log");
204 
205  result.clear();
206 
207  if( ModelInUse("MSSM63atQ") || ModelInUse("MSSM63atMGUT")
208  || ModelInUse("MSSM63atQ_mA") || ModelInUse("MSSM63atMGUT_mA") )
209  {
210  result = Dep::MSSM_spectrum->getSLHAea(1);
211  }
212  else if (ModelInUse("ColliderBit_SLHA_file_model") || ModelInUse("ColliderBit_SLHA_scan_model"))
213  {
214  result = Dep::SLHAFileNameAndContent->second;
215  }
216  else
217  {
218  // This can only happen if the ALLOW_MODELS list in SUSY.hpp has been changed
219  // without also changing this function
220  std::stringstream errmsg_ss;
221  errmsg_ss << "Unknown model! And that makes it a bit hard to return an SLHA1 spectrum... "
222  << "Please expand the function getSLHA1Spectrum if you want to use it with for new models.!";
223  ColliderBit_error().raise(LOCAL_INFO, errmsg_ss.str());
224  }
225 
226  if(write_summary_to_log)
227  {
228  std::stringstream SLHA_log_output;
229  SLHA_log_output << "getSLHA1Spectrum:\n" << result.str() << "\n";
230  logger() << SLHA_log_output.str() << EOM;
231  }
232  }
233 
234  // SLHA2
236  {
237  using namespace Pipes::getSLHA2Spectrum;
238 
239  static const bool write_summary_to_log = runOptions->getValueOrDef<bool>(false, "write_summary_to_log");
240 
241  result.clear();
242 
243  if( ModelInUse("MSSM63atQ") || ModelInUse("MSSM63atMGUT")
244  || ModelInUse("MSSM63atQ_mA") || ModelInUse("MSSM63atMGUT_mA") )
245  {
246  result = Dep::MSSM_spectrum->getSLHAea(2);
247  }
248  else if (ModelInUse("ColliderBit_SLHA_file_model") || ModelInUse("ColliderBit_SLHA_scan_model"))
249  {
250  result = Dep::SLHAFileNameAndContent->second;
251  }
252  else
253  {
254  // This can only happen if the ALLOW_MODELS list in SUSY.hpp has been changed
255  // without also changing this function
256  std::stringstream errmsg_ss;
257  errmsg_ss << "Unknown model! And that makes it a bit hard to return an SLHA1 spectrum... "
258  << "Please expand the function getSLHA2Spectrum if you want to use it with for new models.!";
259  ColliderBit_error().raise(LOCAL_INFO, errmsg_ss.str());
260  }
261 
262  if(write_summary_to_log)
263  {
264  std::stringstream SLHA_log_output;
265  SLHA_log_output << "getSLHA2Spectrum:\n" << result.str() << "\n";
266  logger() << SLHA_log_output.str() << EOM;
267  }
268  }
269 
270 
271  // Advanced mass-cuts to aid SUSY scans
272  void calc_susy_spectrum_scan_guide(double& result)
273  {
274  using namespace Pipes::calc_susy_spectrum_scan_guide;
275  bool discard_point = false;
276 
277  result = 0.0;
278 
279  // Get masses
280  mass_es_pseudonyms psn = *(Dep::SLHA_pseudonyms);
281  const Spectrum& spec = *Dep::MSSM_spectrum;
282 
283  const double m_N1_signed = spec.get(Par::Pole_Mass,"~chi0_1");
284  const double m_N1 = abs(m_N1_signed);
285  // const double m_C1_signed = spec.get(Par::Pole_Mass,"~chi+_1");
286  // const double m_C1 = abs(m_C1_signed);
287  const double m_st1 = spec.get(Par::Pole_Mass, psn.ist1);
288 
289  // Define cuts
290  if (m_N1 < 250. && m_st1 < 750.) discard_point = true;
291  if (m_N1 > 600.) discard_point = true;
292  if (m_st1 > 1100.) discard_point = true;
293 
294  // Discard point?
295  if (discard_point) invalid_point().raise("Point discarded by susy_spectrum_scan_guide.");
296 
297  }
298 
299 
300  }
301 }
double get(const Par::Tags partype, const std::string &mass) const
Definition: spectrum.cpp:249
void getAndReplaceSLHAContent(pair_str_SLHAstruct &result)
Definition: SUSY_extras.cpp:62
std::pair< std::string, SLHAstruct > pair_str_SLHAstruct
Typedef for a str-SLHAstruct pair, to pass around SLHA filenames + content.
void getSLHA2Spectrum(SLHAstruct &result)
void getSLHA1Spectrum(SLHAstruct &result)
ColliderBit event loop functions returning collider Monte Carlo events.
#define LOCAL_INFO
Definition: local_info.hpp:34
SMslha_SLHAstruct SLHAstruct read_SLHA(str slha)
Read an SLHA file in to an SLHAea object with some error-checking.
TYPE getValue(const args &... keys) const
SLHAea::Coll SLHAstruct
Less confusing name for SLHAea container class.
void getSLHAFileElements(map_str_dbl &result)
virtual void raise(const std::string &)
Raise the exception, i.e. throw it. Exact override of base method.
Definition: exceptions.cpp:422
ColliderBit event loop functions returning collider Monte Carlo event simulators. ...
GET_SPECIFIC_PYTHIA_SLHA(getPythia_SLHA, Pythia_default,) void getNextSLHAFileNameAndContent(pair_str_SLHAstruct &result)
Definition: SUSY_extras.cpp:26
const Logging::endofmessage EOM
Explicit const instance of the end of message struct in Gambit namespace.
Definition: logger.hpp:100
EXPORT_SYMBOLS Logging::LogMaster & logger()
Function to retrieve a reference to the Gambit global log object.
Definition: logger.cpp:95
hb_ModelParameters void
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
invalid_point_exception & invalid_point()
Invalid point exceptions.
std::map< std::string, double > map_str_dbl
Shorthand for a string-to-double map.
void calc_susy_spectrum_scan_guide(double &result)
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.
"Standard Model" (low-energy) plus high-energy model container class
Definition: spectrum.hpp:110