Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 08:47:00

0001 // Settings.h is a part of the PYTHIA event generator.
0002 // Copyright (C) 2025 Torbjorn Sjostrand.
0003 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
0004 // Please respect the MCnet Guidelines, see GUIDELINES for details.
0005 
0006 // Header file for the settings database.
0007 // Flag: helper class with bool flags.
0008 // Mode: helper class with int modes.
0009 // Parm: (short for parameter) helper class with double parameters.
0010 // Word: helper class with string words.
0011 // FVec: vector of Flags (bools).
0012 // MVec: vector of Modes (integers).
0013 // PVec: vector of Parms (doubles).
0014 // WVec: vector of Words (strings).
0015 // Settings: maps of flags, modes, parms and words with input/output.
0016 
0017 #ifndef Pythia8_Settings_H
0018 #define Pythia8_Settings_H
0019 
0020 #include "Pythia8/Logger.h"
0021 #include "Pythia8/ParticleData.h"
0022 #include "Pythia8/PythiaStdlib.h"
0023 
0024 namespace Pythia8 {
0025 
0026 //==========================================================================
0027 
0028 // Class for bool flags.
0029 
0030 class Flag {
0031 
0032 public:
0033 
0034   // Constructor
0035   Flag(string nameIn = " ", bool defaultIn = false) : name(nameIn),
0036     valNow(defaultIn) , valDefault(defaultIn) { }
0037 
0038   // Data members.
0039   string name;
0040   bool   valNow, valDefault;
0041 
0042 };
0043 
0044 //==========================================================================
0045 
0046 // Class for integer modes.
0047 
0048 class Mode {
0049 
0050 public:
0051 
0052   // Constructor
0053   Mode(string nameIn = " ", int defaultIn = 0, bool hasMinIn = false,
0054     bool hasMaxIn = false, int minIn = 0,  int maxIn = 0,
0055     bool optOnlyIn = false) :  name(nameIn), valNow(defaultIn),
0056     valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
0057     valMin(minIn), valMax(maxIn), optOnly(optOnlyIn)  { }
0058 
0059   // Data members.
0060   string name;
0061   int    valNow, valDefault;
0062   bool   hasMin, hasMax;
0063   int    valMin, valMax;
0064   bool   optOnly;
0065 
0066 };
0067 
0068 //==========================================================================
0069 
0070 // Class for double parms (where parm is shorthand for parameter).
0071 
0072 class Parm {
0073 
0074 public:
0075 
0076   // Constructor
0077   Parm(string nameIn = " ", double defaultIn = 0.,
0078     bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
0079     double maxIn = 0.) :  name(nameIn), valNow(defaultIn),
0080     valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
0081     valMin(minIn), valMax(maxIn) { }
0082 
0083   // Data members.
0084   string name;
0085   double valNow, valDefault;
0086   bool   hasMin, hasMax;
0087   double valMin, valMax;
0088 
0089 };
0090 
0091 //==========================================================================
0092 
0093 // Class for string words.
0094 
0095 class Word {
0096 
0097 public:
0098 
0099   // Constructor
0100   Word(string nameIn = " ", string defaultIn = " ") : name(nameIn),
0101     valNow(defaultIn) , valDefault(defaultIn) { }
0102 
0103   // Data members.
0104   string name, valNow, valDefault;
0105 
0106 };
0107 
0108 //==========================================================================
0109 
0110 // Class for vector of bool flags.
0111 
0112 class FVec {
0113 
0114 public:
0115 
0116   // Constructor
0117   FVec(string nameIn = " ", vector<bool> defaultIn = vector<bool>(1, false)) :
0118     name(nameIn), valNow(defaultIn) , valDefault(defaultIn) { }
0119 
0120   // Data members.
0121   string name;
0122   vector<bool> valNow, valDefault;
0123 
0124 };
0125 
0126 //==========================================================================
0127 
0128 // Class for vector of integers.
0129 
0130 class MVec {
0131 
0132 public:
0133 
0134   // Constructor
0135   MVec(string nameIn = " ", vector<int> defaultIn = vector<int>(1, 0),
0136     bool hasMinIn = false, bool hasMaxIn = false, int minIn = 0,
0137     int maxIn = 0) :  name(nameIn), valNow(defaultIn),
0138     valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
0139     valMin(minIn), valMax(maxIn) { }
0140 
0141   // Data members.
0142   string name;
0143   vector<int> valNow, valDefault;
0144   bool   hasMin, hasMax;
0145   int    valMin, valMax;
0146 
0147 };
0148 
0149 //==========================================================================
0150 
0151 // Class for vector of doubles.
0152 
0153 class PVec {
0154 
0155 public:
0156 
0157   // Constructor
0158   PVec(string nameIn = " ", vector<double> defaultIn = vector<double>(1, 0.),
0159     bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
0160     double maxIn = 0.) :  name(nameIn), valNow(defaultIn),
0161     valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
0162     valMin(minIn), valMax(maxIn) { }
0163 
0164   // Data members.
0165   string name;
0166   vector<double> valNow, valDefault;
0167   bool   hasMin, hasMax;
0168   double valMin, valMax;
0169 
0170 };
0171 
0172 //==========================================================================
0173 
0174 // Class for vector of strings.
0175 
0176 class WVec {
0177 
0178 public:
0179 
0180   // Constructor
0181   WVec(string nameIn = " ", vector<string> defaultIn = vector<string>(1, " "))
0182     : name(nameIn), valNow(defaultIn) , valDefault(defaultIn) { }
0183 
0184   // Data members.
0185   string name;
0186   vector<string> valNow, valDefault;
0187 
0188 };
0189 
0190 //==========================================================================
0191 
0192 // This class holds info on flags (bool), modes (int), parms (double),
0193 // words (string), fvecs (vector of bool), mvecs (vector of int),
0194 // pvecs (vector of double) and wvecs (vector of string).
0195 
0196 class Settings {
0197 
0198 public:
0199 
0200   // Constructor.
0201   Settings() : loggerPtr(), isInit(false), readingFailedSave(false),
0202     lineSaved(false) {}
0203 
0204   // Initialize pointers.
0205   void initPtrs(Logger* loggerPtrIn, ParticleData* pdPtrIn = nullptr,
0206     stringstream* pdbPtrIn = nullptr) {
0207     loggerPtr = loggerPtrIn; pdPtr = pdPtrIn; pdbPtr = pdbPtrIn;}
0208 
0209   // Read in database from specific file.
0210   bool init(string startFile = "../share/Pythia8/xmldoc/Index.xml",
0211     bool append = false) ;
0212 
0213   // Read in database from stream.
0214   bool init(istream& is, bool append = false) ;
0215 
0216   // Overwrite existing database by reading from specific file.
0217   bool reInit(string startFile = "../share/Pythia8/xmldoc/Index.xml");
0218 
0219   // Read in one update from a single line.
0220   bool readString(string line, bool warn = true, int subrun = SUBRUNDEFAULT);
0221 
0222   // Read in updates from a user-defined file.
0223   bool readFile(string fileName, bool warn = true,
0224     int subrun = SUBRUNDEFAULT);
0225   bool readFile(string fileName, int subrun) {
0226     return readFile(fileName, true, subrun);}
0227   bool readFile(istream& is = cin, bool warn = true,
0228     int subrun = SUBRUNDEFAULT);
0229   bool readFile(istream& is, int subrun) {
0230     return readFile(is, true, subrun);}
0231 
0232   // Register the settings from a plugin library.
0233   bool registerPluginLibrary(string libName, string startFile = "");
0234 
0235   // Write updates or everything to user-defined file or to stream.
0236   bool writeFile(string toFile, bool writeAll = false) ;
0237   bool writeFile(ostream& os = cout, bool writeAll = false) ;
0238   bool writeFileXML(ostream& os = cout) ;
0239 
0240   // Print out table of database, either all or only changed ones,
0241   // or ones containing a given string.
0242   void listAll() { list( true, false, " "); }
0243   void listChanged() { list (false, false, " "); }
0244   void list(string match) { list (false, true, match); }
0245 
0246   // Give back current value(s) as a string, whatever the type.
0247   string output(string keyIn, bool fullLine = true);
0248 
0249   // Retrieve readString history (e.g., for inspection). Everything
0250   // (subrun=-999), up to first subrun (=-1), or subrun-specific (>=0).
0251   vector<string> getReadHistory(int subrun = SUBRUNDEFAULT) {
0252     if (subrun == -999) return readStringHistory;
0253     else if (readStringSubrun.find(subrun) != readStringSubrun.end())
0254       return readStringSubrun[subrun];
0255     else return vector<string>();
0256   }
0257 
0258   // Reset all values to their defaults.
0259   void resetAll() ;
0260 
0261   // Query existence of an entry.
0262   bool isFlag(string keyIn) {
0263     return (flags.find(toLower(keyIn)) != flags.end()); }
0264   bool isMode(string keyIn) {
0265     return (modes.find(toLower(keyIn)) != modes.end()); }
0266   bool isParm(string keyIn) {
0267     return (parms.find(toLower(keyIn)) != parms.end()); }
0268   bool isWord(string keyIn) {
0269     return (words.find(toLower(keyIn)) != words.end()); }
0270   bool isFVec(string keyIn) {
0271     return (fvecs.find(toLower(keyIn)) != fvecs.end()); }
0272   bool isMVec(string keyIn) {
0273     return (mvecs.find(toLower(keyIn)) != mvecs.end()); }
0274   bool isPVec(string keyIn) {
0275     return (pvecs.find(toLower(keyIn)) != pvecs.end()); }
0276   bool isWVec(string keyIn) {
0277     return (wvecs.find(toLower(keyIn)) != wvecs.end()); }
0278 
0279   // Add new entry.
0280   void addFlag(string keyIn, bool defaultIn) {
0281     flags[toLower(keyIn)] = Flag(keyIn, defaultIn); }
0282   void addMode(string keyIn, int defaultIn, bool hasMinIn,
0283     bool hasMaxIn, int minIn, int maxIn, bool optOnlyIn = false) {
0284     modes[toLower(keyIn)] = Mode(keyIn, defaultIn, hasMinIn, hasMaxIn,
0285     minIn, maxIn, optOnlyIn); }
0286   void addParm(string keyIn, double defaultIn, bool hasMinIn,
0287     bool hasMaxIn, double minIn, double maxIn) { parms[toLower(keyIn)]
0288     = Parm(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
0289   void addWord(string keyIn, string defaultIn) {
0290     words[toLower(keyIn)] = Word(keyIn, defaultIn); }
0291   void addFVec(string keyIn, vector<bool> defaultIn) {
0292     fvecs[toLower(keyIn)] = FVec(keyIn, defaultIn); }
0293   void addMVec(string keyIn, vector<int> defaultIn, bool hasMinIn,
0294     bool hasMaxIn, int minIn, int maxIn) { mvecs[toLower(keyIn)]
0295     = MVec(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
0296    void addPVec(string keyIn, vector<double> defaultIn, bool hasMinIn,
0297     bool hasMaxIn, double minIn, double maxIn) { pvecs[toLower(keyIn)]
0298     = PVec(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
0299   void addWVec(string keyIn, vector<string> defaultIn) {
0300     wvecs[toLower(keyIn)] = WVec(keyIn, defaultIn); }
0301 
0302   // Give back current value, with check that key exists.
0303   bool   flag(string keyIn);
0304   int    mode(string keyIn);
0305   double parm(string keyIn);
0306   string word(string keyIn);
0307   vector<bool>   fvec(string keyIn);
0308   vector<int>    mvec(string keyIn);
0309   vector<double> pvec(string keyIn);
0310   vector<string> wvec(string keyIn);
0311 
0312   // Give back default value, with check that key exists.
0313   bool   flagDefault(string keyIn);
0314   int    modeDefault(string keyIn);
0315   double parmDefault(string keyIn);
0316   string wordDefault(string keyIn);
0317   vector<bool>   fvecDefault(string keyIn);
0318   vector<int>    mvecDefault(string keyIn);
0319   vector<double> pvecDefault(string keyIn);
0320   vector<string> wvecDefault(string keyIn);
0321 
0322   // Give back a map of all entries whose names match the string "match".
0323   map<string, Flag> getFlagMap(string match);
0324   map<string, Mode> getModeMap(string match);
0325   map<string, Parm> getParmMap(string match);
0326   map<string, Word> getWordMap(string match);
0327   map<string, FVec> getFVecMap(string match);
0328   map<string, MVec> getMVecMap(string match);
0329   map<string, PVec> getPVecMap(string match);
0330   map<string, WVec> getWVecMap(string match);
0331 
0332   // Change current value, respecting limits.
0333   void flag(string keyIn, bool nowIn, bool force = false);
0334   bool mode(string keyIn, int nowIn, bool force = false,
0335             int subrun = SUBRUNDEFAULT);
0336   bool parm(string keyIn, double nowIn, bool force = false);
0337   void word(string keyIn, string nowIn, bool force = false);
0338   void fvec(string keyIn, vector<bool> nowIn, bool force = false);
0339   bool mvec(string keyIn, vector<int> nowIn, bool force = false);
0340   bool pvec(string keyIn, vector<double> nowIn, bool force = false);
0341   void wvec(string keyIn, vector<string> nowIn, bool force = false);
0342 
0343   // Methods kept for backwards compatability with 8.223 and earlier.
0344   // (To be removed in next major release.)
0345   void forceMode(string keyIn, int nowIn) {mode(keyIn,nowIn,true);}
0346   void forceParm(string keyIn, double nowIn) {parm(keyIn,nowIn,true);}
0347   void forceMVec(string keyIn, vector<int> nowIn) {mvec(keyIn,nowIn,true);}
0348   void forcePVec(string keyIn, vector<double> nowIn) {pvec(keyIn,nowIn,true);}
0349 
0350   // Restore current value to default.
0351   void resetFlag(string keyIn);
0352   void resetMode(string keyIn);
0353   void resetParm(string keyIn);
0354   void resetWord(string keyIn);
0355   void resetFVec(string keyIn);
0356   void resetMVec(string keyIn);
0357   void resetPVec(string keyIn);
0358   void resetWVec(string keyIn);
0359 
0360   // Check initialisation status.
0361   bool getIsInit() {return isInit;}
0362 
0363   // Keep track whether any readings have failed, invalidating run setup.
0364   bool readingFailed() {return readingFailedSave;}
0365 
0366   // Check whether input openend with { not yet closed with }.
0367   bool unfinishedInput() {return lineSaved;}
0368 
0369   // Check whether processes other than SoftQCD/LowEnergyQCD are switched on.
0370   bool hasHardProc();
0371 
0372  private:
0373 
0374   // Pointer to logger.
0375   Logger* loggerPtr{};
0376 
0377   // Optional pointers to particle data and particle data buffer.
0378   ParticleData* pdPtr{};
0379   stringstream* pdbPtr{};
0380 
0381   // Map for bool flags.
0382   map<string, Flag> flags;
0383 
0384   // Map for integer modes.
0385   map<string, Mode> modes;
0386 
0387   // Map for double parms.
0388   map<string, Parm> parms;
0389 
0390   // Map for string words.
0391   map<string, Word> words;
0392 
0393   // Map for vectors of bool.
0394   map<string, FVec> fvecs;
0395 
0396   // Map for vectors of int.
0397   map<string, MVec> mvecs;
0398 
0399   // Map for vectors of double.
0400   map<string, PVec> pvecs;
0401 
0402   // Map for vectors of string.
0403   map<string, WVec> wvecs;
0404 
0405   // Set of loaded plugin libraries.
0406   set<string> pluginLibraries;
0407 
0408   // Flags that initialization has been performed; whether any failures.
0409   bool isInit, readingFailedSave;
0410 
0411   // Store temporary line when searching for continuation line.
0412   bool   lineSaved;
0413   string savedLine;
0414 
0415   // Stored history of readString statements (common and by subrun).
0416   vector<string> readStringHistory;
0417   map<int, vector<string> > readStringSubrun;
0418 
0419   // Print out table of database, called from listAll and listChanged.
0420   void list(bool doListAll, bool doListString, string match);
0421 
0422   // Master switch for program printout.
0423   void printQuiet(bool quiet);
0424 
0425   // Initialize tunes to e+e- and pp/ppbar data.
0426   void initTuneEE(int eeTune, int subrun = SUBRUNDEFAULT);
0427   void initTunePP(int ppTune, int subrun = SUBRUNDEFAULT);
0428   void initTuneVincia(int vinciaTune, int subrun = SUBRUNDEFAULT);
0429 
0430   // Useful functions for string handling.
0431   bool   boolString(string tag);
0432   string attributeValue(string line, string attribute);
0433   bool   boolAttributeValue(string line, string attribute);
0434   int    intAttributeValue(string line, string attribute);
0435   double doubleAttributeValue(string line, string attribute);
0436   vector<bool>   boolVectorAttributeValue(string line, string attribute);
0437   vector<int>    intVectorAttributeValue(string line, string attribute);
0438   vector<double> doubleVectorAttributeValue(string line, string attribute);
0439   vector<string> stringVectorAttributeValue(string line, string attribute);
0440 
0441   // Track the current subrun and xmlpath.
0442   int subrunNow{SUBRUNDEFAULT};
0443   string xmlPath{};
0444 
0445 };
0446 
0447 //==========================================================================
0448 
0449 } // end namespace Pythia8
0450 
0451 #endif // Pythia8_Settings_H