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