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) 2018 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 
18 // Stdlib header files for strings and containers.
19 #include <string>
20 #include <vector>
21 #include <map>
22 #include <deque>
23 #include <set>
24 #include <list>
25 
26 // Stdlib header file for dynamic library loading.
27 #define dlsym __
28 #include <dlfcn.h>
29 #undef dlsym
30 
31 // Redefine dlsym to suppress compiler warnings.
32 extern "C" void *(*dlsym(void *handle, const char *symbol))();
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 // By this declaration you do not need to use std:: qualifier everywhere.
46 //using namespace std;
47 
48 // Alternatively you can specify exactly which std:: methods will be used.
49 // Now made default so std does not spill outside namespace Pythia8.
50 namespace Pythia8 {
51 
52 // Generic utilities and mathematical functions.
53 using std::swap;
54 using std::max;
55 using std::min;
56 using std::abs;
57 using std::sort;
58 
59 // Strings and containers.
60 using std::pair;
61 using std::make_pair;
62 using std::string;
63 using std::vector;
64 using std::map;
65 using std::multimap;
66 using std::deque;
67 using std::set;
68 using std::multiset;
69 using std::list;
70 
71 // Input/output streams.
72 using std::cin;
73 using std::cout;
74 using std::cerr;
75 using std::istream;
76 using std::ostream;
77 using std::fstream;
78 using std::ifstream;
79 using std::ofstream;
80 using std::stringstream;
81 using std::istringstream;
82 using std::ostringstream;
83 using std::ios;
84 
85 // Input/output formatting.
86 using std::endl;
87 using std::fixed;
88 using std::scientific;
89 using std::left;
90 using std::right;
91 using std::setw;
92 using std::setprecision;
93 
94 } // end namespace Pythia8
95 
96 namespace Pythia8 {
97 
98 // Define conversion hbar * c = 0.2 GeV * fm = 1.
99 #ifndef HBARC
100 #define HBARC 0.19732698
101 #endif
102 
103 // Define conversion between fm and mm, in both directions.
104 #ifndef FM2MM
105 #define FM2MM 1e-12
106 #endif
107 #ifndef MM2FM
108 #define MM2FM 1e12
109 #endif
110 
111 // Powers of small integers - for balance speed/code clarity.
112 inline double pow2(const double& x) {return x*x;}
113 inline double pow3(const double& x) {return x*x*x;}
114 inline double pow4(const double& x) {return x*x*x*x;}
115 inline double pow5(const double& x) {return x*x*x*x*x;}
116 inline double pow6(const double& x) {return x*x*x*x*x*x;}
117 inline double pow7(const double& x) {return x*x*x*x*x*x*x;}
118 inline double pow8(const double& x) {return x*x*x*x*x*x*x*x;}
119 
120 // Avoid problem with negative square root argument (from roundoff).
121 inline double sqrtpos(const double& x) {return sqrt( max( 0., x));}
122 
123 // Convert a string to lowercase for case-insensitive comparisons.
124 // By default remove any initial and trailing blanks or escape characters.
125 string toLower(const string& name, bool trim = true);
126 
127 // Variant of above, with in-place replacement.
128 inline void toLowerRep(string& name, bool trim = true) {
129  name = toLower( name, trim);}
130 
131 // The Gamma function for real argument.
132 double GammaReal(double x);
133 
134 // Modified Bessel functions of the first and second kinds.
135 double besselI0(double x);
136 double besselI1(double x);
137 double besselK0(double x);
138 double besselK1(double x);
139 
140 // Base class to encapsulate a (double) function of an arbitrary number
141 // of (double) arguments (to avoid using function pointers).
143 public:
145  virtual ~FunctionEncapsulator() { };
146  virtual double f(vector<double> args);
147  // Integrate over function argument iArg, using Gaussian quadrature.
148  bool integrateGauss(double& result, int iArg, double xLo, double xHi,
149  vector<double> args, double tol=1e-6);
150  // Solve f(args) = target for argument iArg, using Brent's method
151  bool brent(double& solution, double target, int iArg, double xLo, double xHi,
152  vector<double> argsIn, double tol=1e-6, int maxIter=10000);
153 };
154 
155 } // end namespace Pythia8
156 
157 #endif // Pythia8_PythiaStdlib_H