10 #ifndef Pythia8_PythiaStdlib_H 11 #define Pythia8_PythiaStdlib_H 28 #include <unordered_map> 51 #define M_PI 3.1415926535897932385 56 #define SUBRUNDEFAULT -999 62 #ifndef __ENABLE_FP_DEBUG__ 63 #define __ENABLE_FP_DEBUG__ 65 static void __attribute__((constructor)) raisefpe() {
66 feenableexcept (FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
88 using std::numeric_limits;
99 using std::unordered_map;
101 using std::priority_queue;
115 using std::streambuf;
121 using std::stringstream;
122 using std::istringstream;
123 using std::ostringstream;
129 using std::scientific;
133 using std::setprecision;
136 using std::shared_ptr;
138 using std::unique_ptr;
139 using std::dynamic_pointer_cast;
140 using std::make_shared;
147 using std::lock_guard;
154 constexpr
double HBARC = 0.19732698;
155 constexpr
double GEV2FMINV = 1. /
HBARC;
156 constexpr
double GEVINV2FM =
HBARC;
157 constexpr
double FM2GEVINV = 1./
HBARC;
158 constexpr
double FMINV2GEV =
HBARC;
162 constexpr
double GEVSQ2MBINV = 1. /
HBARCSQ;
163 constexpr
double GEVSQINV2MB =
HBARCSQ;
164 constexpr
double MB2GEVSQINV = 1. /
HBARCSQ;
165 constexpr
double MBINV2GEVSQ =
HBARCSQ;
169 constexpr
double MM2FM = 1e12;
173 constexpr
double PB2MB = 1e-9;
174 constexpr
double MB2FB = 1e12;
175 constexpr
double FB2MB = 1e-12;
179 constexpr
double MB2FMSQ = 0.1;
182 constexpr
double pow2(
const double& x) {
return x*x;}
183 constexpr
double pow3(
const double& x) {
return x*x*x;}
184 constexpr
double pow4(
const double& x) {
return x*x*x*x;}
185 constexpr
double pow5(
const double& x) {
return x*x*x*x*x;}
186 constexpr
double pow6(
const double& x) {
return x*x*x*x*x*x;}
187 constexpr
double pow7(
const double& x) {
return x*x*x*x*x*x*x;}
188 constexpr
double pow8(
const double& x) {
return x*x*x*x*x*x*x*x;}
191 inline double sqrtpos(
const double& x) {
return sqrt( max( 0., x));}
195 return x > 0 ? sqrt(x) : numeric_limits<double>::quiet_NaN(); }
198 inline double clamp(
const double& x,
const double& xmin,
const double& xmax) {
199 return (x < xmin) ? xmin : (x > xmax) ? xmax : x; }
203 string toLower(
const string& name,
bool trim =
true);
210 inline string toString(
bool val) {
return val ?
"on" :
"off";}
213 inline string toString(
int val) {
return to_string(val);}
261 #ifndef __METHOD_NAME__ 263 #ifndef PYTHIA_FUNCTION 264 #if ( defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \ 265 || (defined(__ICC) && (__ICC >= 600)) ) 266 # define PYTHIA_FUNCTION __PRETTY_FUNCTION__ 267 #elif defined(__DMC__) && (__DMC__ >= 0x810) 268 # define PYTHIA_FUNCTION __PRETTY_FUNCTION__ 269 #elif defined(__FUNCSIG__) 270 # define PYTHIA_FUNCTION __FUNCSIG__ 271 #elif ( (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) \ 272 || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) ) 273 # define PYTHIA_FUNCTION __FUNCTION__ 274 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) 275 # define PYTHIA_FUNCTION __FUNC__ 276 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) 277 # define PYTHIA_FUNCTION __func__ 279 # define PYTHIA_FUNCTION "unknown" 283 inline std::string
methodName(
const std::string& prettyFunction,
bool 284 withNamespace=
false) {
287 size_t end = prettyFunction.rfind(
')');
288 int bracketCount = 1;
289 while (bracketCount > 0) {
291 if (prettyFunction[end] ==
')') ++bracketCount;
292 else if (prettyFunction[end] ==
'(') --bracketCount;
296 size_t begin = prettyFunction.rfind(
' ', end) + 1;
298 begin = prettyFunction.find(
"::", begin) + 2;
301 return prettyFunction.substr(begin, end - begin);
304 #define __METHOD_NAME__ methodName(PYTHIA_FUNCTION) 313 template <
class T1,
class T2>
struct hash<pair<T1, T2> > {
315 size_t operator()(
const pair<T1, T2>& p)
const {
316 return hash<T1>{}(p.first) ^ hash<T2>{}(p.second);
constexpr double pow2(const double &x)
Powers of small integers - for balance speed/code clarity.
Definition: PythiaStdlib.h:182
end namespace Pythia8
Definition: PythiaStdlib.h:312
void toLowerRep(string &name, bool trim=true)
Variant of above, with in-place replacement.
Definition: PythiaStdlib.h:206
string toLower(const string &name, bool trim=true)
Definition: PythiaStdlib.cc:17
constexpr double MB2PB
Define conversion between mb and pb or fb, in both directions.
Definition: PythiaStdlib.h:172
constexpr double FM2MM
Define conversion between fm and mm, in both directions.
Definition: PythiaStdlib.h:168
constexpr double HBARC
Define conversion hbar * c = 0.2 GeV * fm = 1 and related.
Definition: PythiaStdlib.h:154
string toString(bool val)
Convert a boolean to a string.
Definition: PythiaStdlib.h:210
std::string methodName(const std::string &prettyFunction, bool withNamespace=false)
end PYTHIA_FUNCTION
Definition: PythiaStdlib.h:283
double sqrtnan(const double &x)
Explicitly return NaN if negative square root argument, without FPE.
Definition: PythiaStdlib.h:194
constexpr double FMSQ2MB
Define conversion between fm^2 and mb, in both directions.
Definition: PythiaStdlib.h:178
double clamp(const double &x, const double &xmin, const double &xmax)
Restrinct value to lie in specified range.
Definition: PythiaStdlib.h:198
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
constexpr double HBARCSQ
Define conversion (hbar * c)^2 = 0.4 GeV^2 * mb = 1 and related.
Definition: PythiaStdlib.h:161
double sqrtpos(const double &x)
Avoid problem with negative square root argument (from roundoff).
Definition: PythiaStdlib.h:191