StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PythiaStdlib.h
1 // PythiaStdlib.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Header file for functionality pulled in from Stdlib,
7 // plus a few useful utilities (small powers; positive square root,
8 // convert strings to lowercase, Gamma function).
9 
10 #ifndef Pythia8_PythiaStdlib_H
11 #define Pythia8_PythiaStdlib_H
12 
13 // Stdlib header files for mathematics.
14 #include <cmath>
15 #include <cstdlib>
16 #include <algorithm>
17 #include <memory>
18 #include <functional>
19 
20 // Stdlib header files for strings and containers.
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include <unordered_map>
25 #include <deque>
26 #include <queue>
27 #include <set>
28 #include <list>
29 #include <functional>
30 
31 // Stdlib header file for dynamic library loading.
32 #include <dlfcn.h>
33 
34 // Stdlib header file for input and output.
35 #include <iostream>
36 #include <iomanip>
37 #include <fstream>
38 #include <sstream>
39 
40 // Define pi if not yet done.
41 #ifndef M_PI
42 #define M_PI 3.1415926535897932385
43 #endif
44 
45 // Set floating point exceptions from the gcc compiler for debug
46 // purposes. Use the compilation flag -DGCCFPDEBUG to enable.
47 #ifdef GCCFPDEBUG
48 #ifndef __ENABLE_FP_DEBUG__
49 #define __ENABLE_FP_DEBUG__
50 #include <fenv.h>
51 static void __attribute__((constructor)) raisefpe() {
52  feenableexcept (FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
53 }
54 #endif
55 #endif
56 
57 // By this declaration you do not need to use std:: qualifier everywhere.
58 //using namespace std;
59 
60 // Alternatively you can specify exactly which std:: methods will be used.
61 // Now made default so std does not spill outside namespace Pythia8.
62 namespace Pythia8 {
63 
64 // Generic utilities and mathematical functions.
65 using std::swap;
66 using std::max;
67 using std::min;
68 using std::abs;
69 using std::sort;
70 using std::function;
71 using std::isnan;
72 using std::isinf;
73 using std::isfinite;
74 
75 // Strings and containers.
76 using std::pair;
77 using std::make_pair;
78 using std::string;
79 using std::to_string;
80 using std::vector;
81 using std::map;
82 using std::multimap;
83 using std::unordered_map;
84 using std::deque;
85 using std::priority_queue;
86 using std::set;
87 using std::multiset;
88 using std::list;
89 using std::function;
90 
91 // Input/output streams.
92 using std::cin;
93 using std::cout;
94 using std::cerr;
95 using std::istream;
96 using std::ostream;
97 using std::fstream;
98 using std::ifstream;
99 using std::ofstream;
100 using std::stringstream;
101 using std::istringstream;
102 using std::ostringstream;
103 using std::ios;
104 
105 // Input/output formatting.
106 using std::endl;
107 using std::fixed;
108 using std::scientific;
109 using std::left;
110 using std::right;
111 using std::setw;
112 using std::setprecision;
113 
114 // Pointers
115 using std::shared_ptr;
116 using std::weak_ptr;
117 using std::dynamic_pointer_cast;
118 using std::make_shared;
119 
120 } // end namespace Pythia8
121 
122 namespace Pythia8 {
123 
124 // Define conversion hbar * c = 0.2 GeV * fm = 1 and related.
125 constexpr double HBARC = 0.19732698;
126 constexpr double GEV2FMINV = 1. / HBARC;
127 constexpr double GEVINV2FM = HBARC;
128 constexpr double FM2GEVINV = 1./HBARC;
129 constexpr double FMINV2GEV = HBARC;
130 
131 // Define conversion (hbar * c)^2 = 0.4 GeV^2 * mb = 1 and related.
132 constexpr double HBARCSQ = 0.38937937;
133 constexpr double GEVSQ2MBINV = 1. / HBARCSQ;
134 constexpr double GEVSQINV2MB = HBARCSQ;
135 constexpr double MB2GEVSQINV = 1. / HBARCSQ;
136 constexpr double MBINV2GEVSQ = HBARCSQ;
137 
138 // Define conversion between fm and mm, in both directions.
139 constexpr double FM2MM = 1e-12;
140 constexpr double MM2FM = 1e12;
141 
142 // Define conversion between mb and pb or fb, in both directions.
143 constexpr double MB2PB = 1e9;
144 constexpr double PB2MB = 1e-9;
145 constexpr double MB2FB = 1e12;
146 constexpr double FB2MB = 1e-12;
147 
148 // Define conversion between fm^2 and mb, in both directions.
149 constexpr double FMSQ2MB = 10.;
150 constexpr double MB2FMSQ = 0.1;
151 
152 // Powers of small integers - for balance speed/code clarity.
153 constexpr double pow2(const double& x) {return x*x;}
154 constexpr double pow3(const double& x) {return x*x*x;}
155 constexpr double pow4(const double& x) {return x*x*x*x;}
156 constexpr double pow5(const double& x) {return x*x*x*x*x;}
157 constexpr double pow6(const double& x) {return x*x*x*x*x*x;}
158 constexpr double pow7(const double& x) {return x*x*x*x*x*x*x;}
159 constexpr double pow8(const double& x) {return x*x*x*x*x*x*x*x;}
160 
161 // Avoid problem with negative square root argument (from roundoff).
162 inline double sqrtpos(const double& x) {return sqrt( max( 0., x));}
163 
164 // Restrinct value to lie in specified range.
165 inline double clamp(const double& x, const double& xmin, const double& xmax) {
166  return (x < xmin) ? xmin : (x > xmax) ? xmax : x; }
167 
168 // Convert a string to lowercase for case-insensitive comparisons.
169 // By default remove any initial and trailing blanks or escape characters.
170 string toLower(const string& name, bool trim = true);
171 
172 // Variant of above, with in-place replacement.
173 inline void toLowerRep(string& name, bool trim = true) {
174  name = toLower( name, trim);}
175 
176 } // end namespace Pythia8
177 
178 #endif // Pythia8_PythiaStdlib_H