PYTHIA  8.313
Settings.h
1 // Settings.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2025 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Header file for the settings database.
7 // Flag: helper class with bool flags.
8 // Mode: helper class with int modes.
9 // Parm: (short for parameter) helper class with double parameters.
10 // Word: helper class with string words.
11 // FVec: vector of Flags (bools).
12 // MVec: vector of Modes (integers).
13 // PVec: vector of Parms (doubles).
14 // WVec: vector of Words (strings).
15 // Settings: maps of flags, modes, parms and words with input/output.
16 
17 #ifndef Pythia8_Settings_H
18 #define Pythia8_Settings_H
19 
20 #include "Pythia8/Logger.h"
21 #include "Pythia8/ParticleData.h"
22 #include "Pythia8/PythiaStdlib.h"
23 
24 namespace Pythia8 {
25 
26 //==========================================================================
27 
28 // Class for bool flags.
29 
30 class Flag {
31 
32 public:
33 
34  // Constructor
35  Flag(string nameIn = " ", bool defaultIn = false) : name(nameIn),
36  valNow(defaultIn) , valDefault(defaultIn) { }
37 
38  // Data members.
39  string name;
40  bool valNow, valDefault;
41 
42 };
43 
44 //==========================================================================
45 
46 // Class for integer modes.
47 
48 class Mode {
49 
50 public:
51 
52  // Constructor
53  Mode(string nameIn = " ", int defaultIn = 0, bool hasMinIn = false,
54  bool hasMaxIn = false, int minIn = 0, int maxIn = 0,
55  bool optOnlyIn = false) : name(nameIn), valNow(defaultIn),
56  valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
57  valMin(minIn), valMax(maxIn), optOnly(optOnlyIn) { }
58 
59  // Data members.
60  string name;
61  int valNow, valDefault;
62  bool hasMin, hasMax;
63  int valMin, valMax;
64  bool optOnly;
65 
66 };
67 
68 //==========================================================================
69 
70 // Class for double parms (where parm is shorthand for parameter).
71 
72 class Parm {
73 
74 public:
75 
76  // Constructor
77  Parm(string nameIn = " ", double defaultIn = 0.,
78  bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
79  double maxIn = 0.) : name(nameIn), valNow(defaultIn),
80  valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
81  valMin(minIn), valMax(maxIn) { }
82 
83  // Data members.
84  string name;
85  double valNow, valDefault;
86  bool hasMin, hasMax;
87  double valMin, valMax;
88 
89 };
90 
91 //==========================================================================
92 
93 // Class for string words.
94 
95 class Word {
96 
97 public:
98 
99  // Constructor
100  Word(string nameIn = " ", string defaultIn = " ") : name(nameIn),
101  valNow(defaultIn) , valDefault(defaultIn) { }
102 
103  // Data members.
104  string name, valNow, valDefault;
105 
106 };
107 
108 //==========================================================================
109 
110 // Class for vector of bool flags.
111 
112 class FVec {
113 
114 public:
115 
116  // Constructor
117  FVec(string nameIn = " ", vector<bool> defaultIn = vector<bool>(1, false)) :
118  name(nameIn), valNow(defaultIn) , valDefault(defaultIn) { }
119 
120  // Data members.
121  string name;
122  vector<bool> valNow, valDefault;
123 
124 };
125 
126 //==========================================================================
127 
128 // Class for vector of integers.
129 
130 class MVec {
131 
132 public:
133 
134  // Constructor
135  MVec(string nameIn = " ", vector<int> defaultIn = vector<int>(1, 0),
136  bool hasMinIn = false, bool hasMaxIn = false, int minIn = 0,
137  int maxIn = 0) : name(nameIn), valNow(defaultIn),
138  valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
139  valMin(minIn), valMax(maxIn) { }
140 
141  // Data members.
142  string name;
143  vector<int> valNow, valDefault;
144  bool hasMin, hasMax;
145  int valMin, valMax;
146 
147 };
148 
149 //==========================================================================
150 
151 // Class for vector of doubles.
152 
153 class PVec {
154 
155 public:
156 
157  // Constructor
158  PVec(string nameIn = " ", vector<double> defaultIn = vector<double>(1, 0.),
159  bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
160  double maxIn = 0.) : name(nameIn), valNow(defaultIn),
161  valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
162  valMin(minIn), valMax(maxIn) { }
163 
164  // Data members.
165  string name;
166  vector<double> valNow, valDefault;
167  bool hasMin, hasMax;
168  double valMin, valMax;
169 
170 };
171 
172 //==========================================================================
173 
174 // Class for vector of strings.
175 
176 class WVec {
177 
178 public:
179 
180  // Constructor
181  WVec(string nameIn = " ", vector<string> defaultIn = vector<string>(1, " "))
182  : name(nameIn), valNow(defaultIn) , valDefault(defaultIn) { }
183 
184  // Data members.
185  string name;
186  vector<string> valNow, valDefault;
187 
188 };
189 
190 //==========================================================================
191 
192 // This class holds info on flags (bool), modes (int), parms (double),
193 // words (string), fvecs (vector of bool), mvecs (vector of int),
194 // pvecs (vector of double) and wvecs (vector of string).
195 
196 class Settings {
197 
198 public:
199 
200  // Constructor.
201  Settings() : loggerPtr(), isInit(false), readingFailedSave(false),
202  lineSaved(false) {}
203 
204  // Initialize pointers.
205  void initPtrs(Logger* loggerPtrIn, ParticleData* pdPtrIn = nullptr,
206  stringstream* pdbPtrIn = nullptr) {
207  loggerPtr = loggerPtrIn; pdPtr = pdPtrIn; pdbPtr = pdbPtrIn;}
208 
209  // Read in database from specific file.
210  bool init(string startFile = "../share/Pythia8/xmldoc/Index.xml",
211  bool append = false) ;
212 
213  // Read in database from stream.
214  bool init(istream& is, bool append = false) ;
215 
216  // Overwrite existing database by reading from specific file.
217  bool reInit(string startFile = "../share/Pythia8/xmldoc/Index.xml");
218 
219  // Read in one update from a single line.
220  bool readString(string line, bool warn = true, int subrun = SUBRUNDEFAULT);
221 
222  // Read in updates from a user-defined file.
223  bool readFile(string fileName, bool warn = true,
224  int subrun = SUBRUNDEFAULT);
225  bool readFile(string fileName, int subrun) {
226  return readFile(fileName, true, subrun);}
227  bool readFile(istream& is = cin, bool warn = true,
228  int subrun = SUBRUNDEFAULT);
229  bool readFile(istream& is, int subrun) {
230  return readFile(is, true, subrun);}
231 
232  // Register the settings from a plugin library.
233  bool registerPluginLibrary(string libName, string startFile = "");
234 
235  // Write updates or everything to user-defined file or to stream.
236  bool writeFile(string toFile, bool writeAll = false) ;
237  bool writeFile(ostream& os = cout, bool writeAll = false) ;
238  bool writeFileXML(ostream& os = cout) ;
239 
240  // Print out table of database, either all or only changed ones,
241  // or ones containing a given string.
242  void listAll() { list( true, false, " "); }
243  void listChanged() { list (false, false, " "); }
244  void list(string match) { list (false, true, match); }
245 
246  // Give back current value(s) as a string, whatever the type.
247  string output(string keyIn, bool fullLine = true);
248 
249  // Retrieve readString history (e.g., for inspection). Everything
250  // (subrun=-999), up to first subrun (=-1), or subrun-specific (>=0).
251  vector<string> getReadHistory(int subrun = SUBRUNDEFAULT) {
252  if (subrun == -999) return readStringHistory;
253  else if (readStringSubrun.find(subrun) != readStringSubrun.end())
254  return readStringSubrun[subrun];
255  else return vector<string>();
256  }
257 
258  // Reset all values to their defaults.
259  void resetAll() ;
260 
261  // Query existence of an entry.
262  bool isFlag(string keyIn) {
263  return (flags.find(toLower(keyIn)) != flags.end()); }
264  bool isMode(string keyIn) {
265  return (modes.find(toLower(keyIn)) != modes.end()); }
266  bool isParm(string keyIn) {
267  return (parms.find(toLower(keyIn)) != parms.end()); }
268  bool isWord(string keyIn) {
269  return (words.find(toLower(keyIn)) != words.end()); }
270  bool isFVec(string keyIn) {
271  return (fvecs.find(toLower(keyIn)) != fvecs.end()); }
272  bool isMVec(string keyIn) {
273  return (mvecs.find(toLower(keyIn)) != mvecs.end()); }
274  bool isPVec(string keyIn) {
275  return (pvecs.find(toLower(keyIn)) != pvecs.end()); }
276  bool isWVec(string keyIn) {
277  return (wvecs.find(toLower(keyIn)) != wvecs.end()); }
278 
279  // Add new entry.
280  void addFlag(string keyIn, bool defaultIn) {
281  flags[toLower(keyIn)] = Flag(keyIn, defaultIn); }
282  void addMode(string keyIn, int defaultIn, bool hasMinIn,
283  bool hasMaxIn, int minIn, int maxIn, bool optOnlyIn = false) {
284  modes[toLower(keyIn)] = Mode(keyIn, defaultIn, hasMinIn, hasMaxIn,
285  minIn, maxIn, optOnlyIn); }
286  void addParm(string keyIn, double defaultIn, bool hasMinIn,
287  bool hasMaxIn, double minIn, double maxIn) { parms[toLower(keyIn)]
288  = Parm(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
289  void addWord(string keyIn, string defaultIn) {
290  words[toLower(keyIn)] = Word(keyIn, defaultIn); }
291  void addFVec(string keyIn, vector<bool> defaultIn) {
292  fvecs[toLower(keyIn)] = FVec(keyIn, defaultIn); }
293  void addMVec(string keyIn, vector<int> defaultIn, bool hasMinIn,
294  bool hasMaxIn, int minIn, int maxIn) { mvecs[toLower(keyIn)]
295  = MVec(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
296  void addPVec(string keyIn, vector<double> defaultIn, bool hasMinIn,
297  bool hasMaxIn, double minIn, double maxIn) { pvecs[toLower(keyIn)]
298  = PVec(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
299  void addWVec(string keyIn, vector<string> defaultIn) {
300  wvecs[toLower(keyIn)] = WVec(keyIn, defaultIn); }
301 
302  // Give back current value, with check that key exists.
303  bool flag(string keyIn);
304  int mode(string keyIn);
305  double parm(string keyIn);
306  string word(string keyIn);
307  vector<bool> fvec(string keyIn);
308  vector<int> mvec(string keyIn);
309  vector<double> pvec(string keyIn);
310  vector<string> wvec(string keyIn);
311 
312  // Give back default value, with check that key exists.
313  bool flagDefault(string keyIn);
314  int modeDefault(string keyIn);
315  double parmDefault(string keyIn);
316  string wordDefault(string keyIn);
317  vector<bool> fvecDefault(string keyIn);
318  vector<int> mvecDefault(string keyIn);
319  vector<double> pvecDefault(string keyIn);
320  vector<string> wvecDefault(string keyIn);
321 
322  // Give back a map of all entries whose names match the string "match".
323  map<string, Flag> getFlagMap(string match);
324  map<string, Mode> getModeMap(string match);
325  map<string, Parm> getParmMap(string match);
326  map<string, Word> getWordMap(string match);
327  map<string, FVec> getFVecMap(string match);
328  map<string, MVec> getMVecMap(string match);
329  map<string, PVec> getPVecMap(string match);
330  map<string, WVec> getWVecMap(string match);
331 
332  // Change current value, respecting limits.
333  void flag(string keyIn, bool nowIn, bool force = false);
334  bool mode(string keyIn, int nowIn, bool force = false);
335  bool parm(string keyIn, double nowIn, bool force = false);
336  void word(string keyIn, string nowIn, bool force = false);
337  void fvec(string keyIn, vector<bool> nowIn, bool force = false);
338  bool mvec(string keyIn, vector<int> nowIn, bool force = false);
339  bool pvec(string keyIn, vector<double> nowIn, bool force = false);
340  void wvec(string keyIn, vector<string> nowIn, bool force = false);
341 
342  // Methods kept for backwards compatability with 8.223 and earlier.
343  // (To be removed in next major release.)
344  void forceMode(string keyIn, int nowIn) {mode(keyIn,nowIn,true);}
345  void forceParm(string keyIn, double nowIn) {parm(keyIn,nowIn,true);}
346  void forceMVec(string keyIn, vector<int> nowIn) {mvec(keyIn,nowIn,true);}
347  void forcePVec(string keyIn, vector<double> nowIn) {pvec(keyIn,nowIn,true);}
348 
349  // Restore current value to default.
350  void resetFlag(string keyIn);
351  void resetMode(string keyIn);
352  void resetParm(string keyIn);
353  void resetWord(string keyIn);
354  void resetFVec(string keyIn);
355  void resetMVec(string keyIn);
356  void resetPVec(string keyIn);
357  void resetWVec(string keyIn);
358 
359  // Check initialisation status.
360  bool getIsInit() {return isInit;}
361 
362  // Keep track whether any readings have failed, invalidating run setup.
363  bool readingFailed() {return readingFailedSave;}
364 
365  // Check whether input openend with { not yet closed with }.
366  bool unfinishedInput() {return lineSaved;}
367 
368  // Check whether processes other than SoftQCD/LowEnergyQCD are switched on.
369  bool hasHardProc();
370 
371  private:
372 
373  // Pointer to logger.
374  Logger* loggerPtr{};
375 
376  // Optional pointers to particle data and particle data buffer.
377  ParticleData* pdPtr{};
378  stringstream* pdbPtr{};
379 
380  // Map for bool flags.
381  map<string, Flag> flags;
382 
383  // Map for integer modes.
384  map<string, Mode> modes;
385 
386  // Map for double parms.
387  map<string, Parm> parms;
388 
389  // Map for string words.
390  map<string, Word> words;
391 
392  // Map for vectors of bool.
393  map<string, FVec> fvecs;
394 
395  // Map for vectors of int.
396  map<string, MVec> mvecs;
397 
398  // Map for vectors of double.
399  map<string, PVec> pvecs;
400 
401  // Map for vectors of string.
402  map<string, WVec> wvecs;
403 
404  // Set of loaded plugin libraries.
405  set<string> pluginLibraries;
406 
407  // Flags that initialization has been performed; whether any failures.
408  bool isInit, readingFailedSave;
409 
410  // Store temporary line when searching for continuation line.
411  bool lineSaved;
412  string savedLine;
413 
414  // Stored history of readString statements (common and by subrun).
415  vector<string> readStringHistory;
416  map<int, vector<string> > readStringSubrun;
417 
418  // Print out table of database, called from listAll and listChanged.
419  void list(bool doListAll, bool doListString, string match);
420 
421  // Master switch for program printout.
422  void printQuiet(bool quiet);
423 
424  // Initialize tunes to e+e- and pp/ppbar data.
425  void initTuneEE(int eeTune);
426  void initTunePP(int ppTune);
427  void initTuneVincia(int vinciaTune);
428 
429  // Useful functions for string handling.
430  bool boolString(string tag);
431  string attributeValue(string line, string attribute);
432  bool boolAttributeValue(string line, string attribute);
433  int intAttributeValue(string line, string attribute);
434  double doubleAttributeValue(string line, string attribute);
435  vector<bool> boolVectorAttributeValue(string line, string attribute);
436  vector<int> intVectorAttributeValue(string line, string attribute);
437  vector<double> doubleVectorAttributeValue(string line, string attribute);
438  vector<string> stringVectorAttributeValue(string line, string attribute);
439 
440  // Track the current subrun and xmlpath.
441  int subrunNow{SUBRUNDEFAULT};
442  string xmlPath{};
443 
444 };
445 
446 //==========================================================================
447 
448 } // end namespace Pythia8
449 
450 #endif // Pythia8_Settings_H
void forceMode(string keyIn, int nowIn)
Definition: Settings.h:344
string name
Data members.
Definition: Settings.h:185
Class for double parms (where parm is shorthand for parameter).
Definition: Settings.h:72
Mode(string nameIn=" ", int defaultIn=0, bool hasMinIn=false, bool hasMaxIn=false, int minIn=0, int maxIn=0, bool optOnlyIn=false)
Constructor.
Definition: Settings.h:53
FVec(string nameIn=" ", vector< bool > defaultIn=vector< bool >(1, false))
Constructor.
Definition: Settings.h:117
Word(string nameIn=" ", string defaultIn=" ")
Constructor.
Definition: Settings.h:100
PVec(string nameIn=" ", vector< double > defaultIn=vector< double >(1, 0.), bool hasMinIn=false, bool hasMaxIn=false, double minIn=0., double maxIn=0.)
Constructor.
Definition: Settings.h:158
string name
Data members.
Definition: Settings.h:165
void initPtrs(Logger *loggerPtrIn, ParticleData *pdPtrIn=nullptr, stringstream *pdbPtrIn=nullptr)
Initialize pointers.
Definition: Settings.h:205
Class for integer modes.
Definition: Settings.h:48
Class for string words.
Definition: Settings.h:95
Class for bool flags.
Definition: Settings.h:30
string name
Data members.
Definition: Settings.h:104
string toLower(const string &name, bool trim=true)
Definition: PythiaStdlib.cc:17
bool isFlag(string keyIn)
Query existence of an entry.
Definition: Settings.h:262
Definition: Logger.h:23
string name
Data members.
Definition: Settings.h:84
Class for vector of integers.
Definition: Settings.h:130
WVec(string nameIn=" ", vector< string > defaultIn=vector< string >(1," "))
Constructor.
Definition: Settings.h:181
Flag(string nameIn=" ", bool defaultIn=false)
Constructor.
Definition: Settings.h:35
bool getIsInit()
Check initialisation status.
Definition: Settings.h:360
Class for vector of doubles.
Definition: Settings.h:153
string name
Data members.
Definition: Settings.h:121
string name
Data members.
Definition: Settings.h:142
MVec(string nameIn=" ", vector< int > defaultIn=vector< int >(1, 0), bool hasMinIn=false, bool hasMaxIn=false, int minIn=0, int maxIn=0)
Constructor.
Definition: Settings.h:135
Parm(string nameIn=" ", double defaultIn=0., bool hasMinIn=false, bool hasMaxIn=false, double minIn=0., double maxIn=0.)
Constructor.
Definition: Settings.h:77
bool readingFailed()
Keep track whether any readings have failed, invalidating run setup.
Definition: Settings.h:363
Class for vector of strings.
Definition: Settings.h:176
void listAll()
Definition: Settings.h:242
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
Settings()
Constructor.
Definition: Settings.h:201
string name
Data members.
Definition: Settings.h:39
bool unfinishedInput()
Check whether input openend with { not yet closed with }.
Definition: Settings.h:366
vector< string > getReadHistory(int subrun=SUBRUNDEFAULT)
Definition: Settings.h:251
string name
Data members.
Definition: Settings.h:60
This class holds a map of all ParticleDataEntries.
Definition: ParticleData.h:422
Class for vector of bool flags.
Definition: Settings.h:112
Definition: Settings.h:196
void addFlag(string keyIn, bool defaultIn)
Add new entry.
Definition: Settings.h:280