gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
Py8Collider.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
18 
19 #pragma once
20 
21 #include <ostream>
22 #include <stdexcept>
26 #include "SLHAea/slhaea.h"
27 
28 namespace Gambit
29 {
30 
31  namespace ColliderBit
32  {
33 
35  template <typename PythiaT, typename EventT, typename hepmc_writerT>
36  class Py8Collider : public BaseCollider
37  {
38 
39  protected:
40 
41  PythiaT* _pythiaInstance;
42  PythiaT* _pythiaBase;
43  std::vector<std::string> _pythiaSettings;
44 
45 
46  public:
47 
49  const PythiaT* pythia() const { return _pythiaInstance; }
50 
51  // Setting up the CombineMatchingInput UserHook
53  {
55  Hook.SetupHook(_pythiaInstance);
56  return true;
57  }
58 
61 
63  class InitializationError : public std::exception
64  {
65  virtual const char* what() const throw()
66  {
67  return "Pythia could not initialize.";
68  }
69  };
71  class EventGenerationError : public std::exception
72  {
73  virtual const char* what() const throw()
74  {
75  return "Pythia could not make the next event.";
76  }
77  };
78 
80 
81 
84 
85  Py8Collider() : _pythiaInstance(nullptr), _pythiaBase(nullptr) {}
86 
88  {
89  _pythiaSettings.clear();
90  if (_pythiaInstance) delete _pythiaInstance;
91  if (_pythiaBase) delete _pythiaBase;
92  }
93 
94  void clear()
95  {
96  _pythiaSettings.clear();
97  if (_pythiaInstance)
98  {
99  delete _pythiaInstance;
100  _pythiaInstance=nullptr;
101  }
102  }
103 
105 
106 
109 
111  void addToSettings(const std::string& command) { _pythiaSettings.push_back(command); }
113  void banner(const std::string pythiaDocPath) { PythiaT myPythia(pythiaDocPath); }
115  void init() { std::cout<<"No settings given to Pythia!\n\n"; throw InitializationError(); }
116 
120  void init(const std::vector<std::string>& externalSettings)
121  {
122  std::string docPath = externalSettings.back();
123  std::vector<std::string> settings(externalSettings);
124  settings.pop_back();
125  init(docPath, settings);
126  }
127 
130  void init(const std::string pythiaDocPath,
131  const std::vector<std::string>& externalSettings,
132  const SLHAea::Coll* slhaea=nullptr, std::ostream& os=std::cout)
133  {
134  // Settings acquired externally (ex from a gambit yaml file)
135  for(const auto command : externalSettings) _pythiaSettings.push_back(command);
136 
137  if (!_pythiaBase)
138  {
139  _pythiaBase = new PythiaT(pythiaDocPath, false);
140  }
141 
142  // Pass all settings to _pythiaBase
143  for(const auto command : _pythiaSettings) _pythiaBase->readString(command);
144 
145  // Create new _pythiaInstance from _pythiaBase
146  if (_pythiaInstance) delete _pythiaInstance;
147  _pythiaInstance = new PythiaT(_pythiaBase->particleData, _pythiaBase->settings);
148 
149  // Send along the SLHAea::Coll pointer, if it exists
150  if (slhaea) _pythiaInstance->slhaInterface.slha.setSLHAea(slhaea);
151 
152  // Read command again to get SM decay table change from yaml file
153  for(const auto command : _pythiaSettings)
154  {
155  _pythiaInstance->readString(command);
156  }
157 
158  if (!_pythiaInstance->init(os)) throw InitializationError();
159  }
160 
164  void init_user_model(const std::string pythiaDocPath,
165  const std::vector<std::string>& externalSettings,
166  const SLHAea::Coll* slhaea=nullptr, std::ostream& os=std::cout)
167  {
168  // Settings acquired externally (for example, from a gambit yaml file)
169  for(const auto command : externalSettings) _pythiaSettings.push_back(command);
170 
171  if (!_pythiaBase)
172  {
173  _pythiaBase = new PythiaT(pythiaDocPath, false);
174  }
175 
176  // Pass all settings to _pythiaBase
177  for(const auto command : _pythiaSettings) _pythiaBase->readString(command);
178 
179  // Create new _pythiaInstance from _pythiaBase
180  if (_pythiaInstance) delete _pythiaInstance;
181  _pythiaInstance = new PythiaT(_pythiaBase->particleData, _pythiaBase->settings);
182 
183  // Send along the SLHAea::Coll pointer, if it exists
184  if (slhaea) _pythiaInstance->slhaInterface.slha.setSLHAea(slhaea);
185 
186  if (!_pythiaInstance->init(os)) throw InitializationError();
187  }
188 
190  void init(const std::string pythiaDocPath,
191  const std::vector<std::string>& externalSettings, std::ostream& os)
192  {
193  init(pythiaDocPath, externalSettings, nullptr, os);
194  }
195 
197  void init_user_model(const std::string pythiaDocPath,
198  const std::vector<std::string>& externalSettings, std::ostream& os)
199  {
200  init_user_model(pythiaDocPath, externalSettings, nullptr, os);
201  }
202 
204 
205 
208 
210  void nextEvent(EventT& event) const
211  {
212  // Try to make and populate an event
213  bool accepted_event = _pythiaInstance->next();
214  event = _pythiaInstance->event;
215  if (!accepted_event)
216  {
217  throw EventGenerationError();
218  }
219  }
220 
222  double xsec_fb() const { return _pythiaInstance->info.sigmaGen() * 1e12; }
223  double xsec_fb(int process_code) const { return _pythiaInstance->info.sigmaGen(process_code) * 1e12; }
224  double xsec_pb() const { return _pythiaInstance->info.sigmaGen() * 1e9; }
225  double xsec_pb(int process_code) const { return _pythiaInstance->info.sigmaGen(process_code) * 1e9; }
226 
228  double xsecErr_fb() const { return _pythiaInstance->info.sigmaErr() * 1e12; }
229  double xsecErr_fb(int process_code) const { return _pythiaInstance->info.sigmaErr(process_code) * 1e12; }
230  double xsecErr_pb() const { return _pythiaInstance->info.sigmaErr() * 1e9; }
231  double xsecErr_pb(int process_code) const { return _pythiaInstance->info.sigmaErr(process_code) * 1e9; }
232 
234  int process_code() const { return _pythiaInstance->info.code(); }
235 
237  std::vector<int> all_active_process_codes() const { return _pythiaInstance->info.codesHard(); }
238 
240 
241  };
242 
243  }
244 }
double xsec_fb() const
Report the total or process-specific cross section (in fb or pb).
The SetHooks.
double xsecErr_pb(int process_code) const
Types used internally, returned and/or read in by more than one backend, model or module...
void clear()
Reset this instance for reuse, avoiding the need for "new" or "delete".
Definition: Py8Collider.hpp:94
void init_user_model(const std::string pythiaDocPath, const std::vector< std::string > &externalSettings, std::ostream &os)
Initialize from some external settings, assuming no given SLHAea instance.
void nextEvent(EventT &event) const
Event generation for any Pythia interface to Gambit.
double xsecErr_fb() const
Report the uncertainty in the total or process-specific cross section (in fb or pb).
void banner(const std::string pythiaDocPath)
Create a useless Pythia instance just to print the banner.
void init(const std::string pythiaDocPath, const std::vector< std::string > &externalSettings, std::ostream &os)
Initialize from some external settings, assuming no given SLHAea instance.
An exception for when Pythia fails to initialize.
Definition: Py8Collider.hpp:63
void init()
Initialize with no settings (error): override version.
double xsec_fb(int process_code) const
void init(const std::string pythiaDocPath, const std::vector< std::string > &externalSettings, const SLHAea::Coll *slhaea=nullptr, std::ostream &os=std::cout)
Initialize from some external settings.
void init_user_model(const std::string pythiaDocPath, const std::vector< std::string > &externalSettings, const SLHAea::Coll *slhaea=nullptr, std::ostream &os=std::cout)
Initialize from some external settings.
A templated class specific for the UserHooks.
The BaseCollider class.
An exception for when Pythia fails to generate events.
Definition: Py8Collider.hpp:71
int process_code() const
Report an integer process code for the last generated event.
const PythiaT * pythia() const
Get the Pythia instance.
Definition: Py8Collider.hpp:49
double xsecErr_fb(int process_code) const
A specializable, recyclable class interfacing ColliderBit and Pythia.
Definition: Py8Collider.hpp:36
std::vector< std::string > _pythiaSettings
Definition: Py8Collider.hpp:43
void addToSettings(const std::string &command)
Add a command to the list of settings used by "init".
An abstract base class for collider simulators within ColliderBit.
void init(const std::vector< std::string > &externalSettings)
Initialize from some external settings: override version.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
double xsec_pb(int process_code) const
std::vector< int > all_active_process_codes() const
Report the list of all active process codes.