Back to home page

EIC code displayed by LXR

 
 

    


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

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