Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:25:34

0001 // PythiaStdlib.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 functionality pulled in from Stdlib,
0007 // plus a few useful utilities (small powers; positive square root,
0008 // convert strings to lowercase, Gamma function).
0009 
0010 #ifndef Pythia8_PythiaStdlib_H
0011 #define Pythia8_PythiaStdlib_H
0012 
0013 // Stdlib header files for mathematics.
0014 #include <cstddef>
0015 #include <cmath>
0016 #include <cstdlib>
0017 #include <algorithm>
0018 #include <memory>
0019 #include <functional>
0020 #include <limits>
0021 #include <utility>
0022 
0023 // Stdlib header files for strings and containers.
0024 #include <string>
0025 #include <vector>
0026 #include <array>
0027 #include <map>
0028 #include <unordered_map>
0029 #include <deque>
0030 #include <queue>
0031 #include <set>
0032 #include <list>
0033 #include <functional>
0034 
0035 // Stdlib header file for dynamic library loading.
0036 #include <dlfcn.h>
0037 
0038 // Stdlib header file for input and output.
0039 #include <iostream>
0040 #include <iomanip>
0041 #include <fstream>
0042 #include <sstream>
0043 
0044 // Thread header files.
0045 #include <mutex>
0046 #include <atomic>
0047 #include <thread>
0048 
0049 // Handle floating point exceptions.
0050 #include "Pythia8/PythiaFpe.h"
0051 
0052 // Define pi if not yet done.
0053 #ifndef M_PI
0054 #define M_PI 3.1415926535897932385
0055 #endif
0056 
0057 // Define the default subrun.
0058 #ifndef SUBRUNDEFAULT
0059 #define SUBRUNDEFAULT -999
0060 #endif
0061 
0062 // By this declaration you do not need to use std:: qualifier everywhere.
0063 // using namespace std;
0064 
0065 // Alternatively you can specify exactly which std:: methods will be used.
0066 // Now made default so std does not spill outside namespace Pythia8.
0067 namespace Pythia8 {
0068 
0069 // Generic utilities and mathematical functions.
0070 using std::swap;
0071 using std::max;
0072 using std::min;
0073 using std::abs;
0074 using std::sort;
0075 using std::function;
0076 using std::isnan;
0077 using std::isinf;
0078 using std::isfinite;
0079 using std::numeric_limits;
0080 
0081 // Strings and containers.
0082 using std::pair;
0083 using std::make_pair;
0084 using std::string;
0085 using std::to_string;
0086 using std::vector;
0087 using std::array;
0088 using std::map;
0089 using std::multimap;
0090 using std::unordered_map;
0091 using std::deque;
0092 using std::priority_queue;
0093 using std::set;
0094 using std::multiset;
0095 using std::list;
0096 using std::tuple;
0097 using std::function;
0098 using std::fill;
0099 using std::end;
0100 using std::begin;
0101 
0102 // Input/output streams.
0103 using std::cin;
0104 using std::cout;
0105 using std::cerr;
0106 using std::streambuf;
0107 using std::istream;
0108 using std::ostream;
0109 using std::fstream;
0110 using std::ifstream;
0111 using std::ofstream;
0112 using std::stringstream;
0113 using std::istringstream;
0114 using std::ostringstream;
0115 using std::ios;
0116 
0117 // Input/output formatting.
0118 using std::endl;
0119 using std::fixed;
0120 using std::scientific;
0121 using std::left;
0122 using std::right;
0123 using std::setw;
0124 using std::setprecision;
0125 
0126 // Pointers
0127 using std::shared_ptr;
0128 using std::weak_ptr;
0129 using std::unique_ptr;
0130 using std::dynamic_pointer_cast;
0131 using std::make_shared;
0132 
0133 // Threading.
0134 using std::queue;
0135 using std::mutex;
0136 using std::thread;
0137 using std::atomic;
0138 using std::lock_guard;
0139 
0140 } // end namespace Pythia8
0141 
0142 namespace Pythia8 {
0143 
0144 // Define conversion hbar * c = 0.2 GeV * fm = 1 and related.
0145 constexpr double HBARC     = 0.19732698;
0146 constexpr double GEV2FMINV = 1. / HBARC;
0147 constexpr double GEVINV2FM = HBARC;
0148 constexpr double FM2GEVINV = 1./HBARC;
0149 constexpr double FMINV2GEV = HBARC;
0150 
0151 // Define conversion (hbar * c)^2 = 0.4 GeV^2 * mb = 1 and related.
0152 constexpr double HBARCSQ     = 0.38937937;
0153 constexpr double GEVSQ2MBINV = 1. / HBARCSQ;
0154 constexpr double GEVSQINV2MB = HBARCSQ;
0155 constexpr double MB2GEVSQINV = 1. / HBARCSQ;
0156 constexpr double MBINV2GEVSQ = HBARCSQ;
0157 
0158 // Define conversion between fm and mm, in both directions.
0159 constexpr double FM2MM   = 1e-12;
0160 constexpr double MM2FM   = 1e12;
0161 
0162 // Define conversion between mb and pb or fb, in both directions.
0163 constexpr double MB2PB   = 1e9;
0164 constexpr double PB2MB   = 1e-9;
0165 constexpr double MB2FB   = 1e12;
0166 constexpr double FB2MB   = 1e-12;
0167 
0168 // Define conversion between fm^2 and mb, in both directions.
0169 constexpr double FMSQ2MB = 10.;
0170 constexpr double MB2FMSQ = 0.1;
0171 
0172 // Powers of small integers - for balance speed/code clarity.
0173 constexpr double pow2(const double& x) {return x*x;}
0174 constexpr double pow3(const double& x) {return x*x*x;}
0175 constexpr double pow4(const double& x) {return x*x*x*x;}
0176 constexpr double pow5(const double& x) {return x*x*x*x*x;}
0177 constexpr double pow6(const double& x) {return x*x*x*x*x*x;}
0178 constexpr double pow7(const double& x) {return x*x*x*x*x*x*x;}
0179 constexpr double pow8(const double& x) {return x*x*x*x*x*x*x*x;}
0180 
0181 // Avoid problem with negative square root argument (from roundoff).
0182 inline double sqrtpos(const double& x) {return sqrt( max( 0., x));}
0183 
0184 // Explicitly return NaN if negative square root argument, without FPE.
0185 inline double sqrtnan(const double& x) {
0186   return x > 0 ? sqrt(x) : numeric_limits<double>::quiet_NaN(); }
0187 
0188 // Restrinct value to lie in specified range.
0189 inline double clamp(const double& x, const double& xmin, const double& xmax) {
0190   return (x < xmin) ? xmin : (x > xmax) ? xmax : x; }
0191 
0192 // Convert a string to lowercase for case-insensitive comparisons.
0193 // By default remove any initial and trailing blanks or escape characters.
0194 string toLower(const string& name, bool trim = true);
0195 
0196 // Variant of above, with in-place replacement.
0197 inline void toLowerRep(string& name, bool trim = true) {
0198   name = toLower( name, trim);}
0199 
0200 // Remove any initial and trailing blanks or escape characters.
0201 string trimString(const string& name);
0202 
0203 // Variant of above, with in-place replacement.
0204 inline void trimStringRep(string& name) {
0205   name = trimString( name);}
0206 
0207 // Convert a boolean to a string.
0208 inline string toString(bool val) {return val ? "on" : "off";}
0209 
0210 // Convert an integer to a string.
0211 inline string toString(int val) {return to_string(val);}
0212 
0213 // Convert a double to a string.
0214 string toString(double val);
0215 
0216 //==========================================================================
0217 
0218 // Print a method name using the appropriate pre-processor macro.
0219 
0220 //  The following method was modified from
0221 //  boost/current_function.hpp - BOOST_CURRENT_FUNCTION
0222 //
0223 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
0224 //
0225 //  Distributed under the Boost Software License, Version 1.0.
0226 //  Boost Software License - Version 1.0 - August 17th, 2003
0227 //
0228 //  Permission is hereby granted, free of charge, to any person or
0229 //  organization obtaining a copy of the software and accompanying
0230 //  documentation covered by this license (the "Software") to use,
0231 //  reproduce, display, distribute, execute, and transmit the
0232 //  Software, and to prepare derivative works of the Software, and to
0233 //  permit third-parties to whom the Software is furnished to do so,
0234 //  all subject to the following:
0235 //
0236 //  The copyright notices in the Software and this entire statement,
0237 //  including the above license grant, this restriction and the
0238 //  following disclaimer, must be included in all copies of the
0239 //  Software, in whole or in part, and all derivative works of the
0240 //  Software, unless such copies or derivative works are solely in the
0241 //  form of machine-executable object code generated by a source
0242 //  language processor.
0243 //
0244 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0245 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0246 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
0247 //  NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
0248 //  ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR
0249 //  OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING
0250 //  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0251 //  OTHER DEALINGS IN THE SOFTWARE.
0252 //
0253 //  http://www.boost.org/libs/utility/current_function.html
0254 //
0255 //  Note that Boost Software License - Version 1.0 is fully compatible
0256 //  with GPLV2
0257 //  For more information see https://www.gnu.org/licenses/license-list.en.html
0258 
0259 #ifndef __METHOD_NAME__
0260 
0261 #ifndef PYTHIA_FUNCTION
0262 #if ( defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \
0263 || (defined(__ICC) && (__ICC >= 600)) )
0264 # define PYTHIA_FUNCTION __PRETTY_FUNCTION__
0265 #elif defined(__DMC__) && (__DMC__ >= 0x810)
0266 # define PYTHIA_FUNCTION __PRETTY_FUNCTION__
0267 #elif defined(__FUNCSIG__)
0268 # define PYTHIA_FUNCTION __FUNCSIG__
0269 #elif ( (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) \
0270 || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) )
0271 # define PYTHIA_FUNCTION __FUNCTION__
0272 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
0273 # define PYTHIA_FUNCTION __FUNC__
0274 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
0275 # define PYTHIA_FUNCTION __func__
0276 #else
0277 # define PYTHIA_FUNCTION "unknown"
0278 #endif
0279 #endif // end PYTHIA_FUNCTION
0280 
0281 inline std::string methodName(const std::string& prettyFunction, bool
0282   withNamespace=false) {
0283 
0284   // Find the beginning of the argument list.
0285   size_t end = prettyFunction.rfind(')');
0286   int bracketCount = 1;
0287   while (bracketCount > 0) {
0288     --end;
0289     if (prettyFunction[end] == ')') ++bracketCount;
0290     else if (prettyFunction[end] == '(') --bracketCount;
0291   }
0292 
0293   // Find the start of the function name.
0294   size_t begin = prettyFunction.rfind(' ', end) + 1;
0295   if (!withNamespace)
0296     begin = prettyFunction.find("::", begin) + 2;
0297 
0298   // Return the correct substring.
0299   return prettyFunction.substr(begin, end - begin);
0300 }
0301 
0302 #define __METHOD_NAME__ methodName(PYTHIA_FUNCTION)
0303 #endif // __METHOD_NAME__
0304 
0305 //==========================================================================
0306 
0307 } // end namespace Pythia8
0308 
0309 // Define the hash for a pair.
0310 namespace std {
0311   template <class T1, class T2> struct hash<pair<T1, T2> > {
0312   public:
0313     size_t operator()(const pair<T1, T2>& p) const {
0314       return hash<T1>{}(p.first) ^ hash<T2>{}(p.second);
0315     }
0316   };
0317 
0318 //==========================================================================
0319 
0320 } // end namespace std
0321 
0322 #endif // Pythia8_PythiaStdlib_H