Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
arsenal.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file arsenal.h
1 // Version 1.7.0
2 // Zhi Qiu
3 
4 #ifndef arsenal_h
5 #define arsenal_h
6 
7 #include <cmath>
8 #include "stdlib.h"
9 #include <vector>
10 #include <string>
11 
12 // using namespace std;
13 using std::string;
14 using std::vector;
15 using std::ofstream;
16 using std::ifstream;
17 using std::ostream;
18 using std::istream;
19 using std::abs;
20 
21 double sixPoint2dInterp(double x, double y,
22  double v00, double v01, double v02, double v10, double v11, double v20);
23 
24 double interpCubicDirect(vector<double>* x, vector<double>* y, double xx);
25 double interpCubicMono(vector<double>* x, vector<double>* y, double xx);
26 double interpLinearDirect(vector<double>* x, vector<double>* y, double xx);
27 double interpLinearMono(vector<double>* x, vector<double>* y, double xx);
28 double interpNearestDirect(vector<double>* x, vector<double>* y, double xx);
29 double interpNearestMono(vector<double>* x, vector<double>* y, double xx);
30 
31 double invertFunc(double (*func)(double), double y, double xL, double xR, double dx, double x0, double relative_accuracy=1e-10);
32 
33 double invertTableDirect_hook(double xx);
34 double invertTableDirect(vector<double>* x, vector<double>* y, double y0, double x0, double relative_accuracy=1e-10);
35 
36 double stringToDouble(string);
37 vector<double> stringToDoubles(string);
38 string toLower(string str);
39 string trim(string str);
40 
41 vector< vector<double>* >* readBlockData(istream &stream_in);
42 void releaseBlockData(vector< vector<double>* >* data);
43 
44 double adaptiveSimpsonsAux(double (*f)(double), double a, double b, double epsilon, double S, double fa, double fb, double fc, int bottom);
45 double adaptiveSimpsons(double (*f)(double), double a, double b, double epsilon=1e-15, int maxRecursionDepth=50);
46 
47 double qiu_simpsons(double (*f)(double), double a, double b, double epsilon=1e-15, int maxRecursionDepth=50);
48 double qiu_simpsonsRel(double (*f)(double), double a, double b, double epsilon=1e-15, int maxRecursionDepth=50);
49 long binarySearch(vector<double>* A, double value, bool skip_out_of_range=false);
50 
51 void formatedPrint(ostream&, int count, ...);
52 long double gamma_function(long double x);
53 long double log_gamma_function(long double x);
54 double beta_function(double, double);
55 double binomial_coefficient(double n, double k);
56 
57 void print_progressbar(double percentage, int length=50, string symbol="#");
58 void display_logo(int which=1);
59 
60 inline long irand(long LB, long RB)
61 // Get an interger between LB and RB (including) with uniform distribution.
62 {
63  return LB + (long)((RB-LB+1)*(drand48()-1e-25));
64 }
65 
66 inline double drand(double LB, double RB)
67 // Get random number with uniform distribution between LB and RB with
68 // boundary-protection.
69 {
70  double width = RB-LB;
71  double dw = width*1e-30;
72  return LB+dw+(width-2*dw)*drand48();
73 }
74 
75 inline bool is_integer(double x, double tolerance=1e-30)
76 // Check if a double number is close to an integer
77 {
78  if (abs(x-round(x))<tolerance) return true;
79  else return false;
80 }
81 
82 void GaussLegendre_getWeight(int npts,double* x,double* w, double A, double B, int opt);
83 
84 void get_bin_average_and_count(istream& is, ostream& os, vector<double>* bins, long col_to_bin=0, void (*func)(vector<double>*)=NULL, long wanted_data_columns=-1, bool silence=false); // Note that col_to_bin starts with 1, and bins is assumed to be monotonically increasing
85 
86 #endif
87 
88 
89 
90 /*----------------------------------------------------------------------
91  Change logs:
92 
93  04-26-2010:
94  -- invertFunc, invertTable, stringToDoubles, readBlockData functions added.
95  04-25-2011:
96  -- interpCubic function adxed.
97  12-17-2010:
98  -- sixPoint2dInterp function adxed.
99  08-05-2011:
100  -- Ver 1.1:
101  Functions adaptiveSimpsons and qiu_simpsons added. The qiu_simpsons function, when using 20 recursions, is 4 times faster than adaptiveSimpsons. The function used to test this is sin(2000*x), integrated on [0,1].
102  09-09-2011:
103  -- Ver 1.2:
104  Function toLower added. It simply convert all letters in a string to lower case.
105  Function stringToDouble added.
106  Function trim added.
107  02-02-2012:
108  -- Ver 1.2.1:
109  Function trim now also removes tabs besides spaces.
110  02-04-2012:
111  -- Ver 1.5:
112  Functions added: interpCubic, binarySearch, formatedPrint, gamma_function,
113  interpLinearDirect, interpLinearMono, interpNearestDirect, interpNearestMono.
114  Function interpCubic is renamed to interpCubicMono.
115  03-14-2012:
116  -- Ver 1.5.1:
117  Functions added: print_progressbar.
118  03-19-2012:
119  -- Ver 1.6:
120  Functions added: display_logo, drand, irand, GaussLegendre_getweight, get_bin_average_and_count.
121  Function formatedPrint now accepts a stream argument.
122  03-19-2012:
123  -- Ver 1.6.1:
124  Function get_bin_average_and_count can now average transformed data
125  that have different number of columns than the data directly read in.
126  04-03-2012:
127  -- Ver 1.7.0:
128  Functions added: is_integer, binomial_coefficient, beta_function,
129  log_gamma_function.
130 -----------------------------------------------------------------------*/