Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:29

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