Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:19:42

0001 // Version 1.7.0
0002 // Zhi Qiu
0003 
0004 #ifndef arsenal_h
0005 #define arsenal_h
0006 
0007 #include <cmath>
0008 #include "stdlib.h"
0009 #include <vector>
0010 #include <string>
0011 
0012 // using namespace std;
0013 using std::string;
0014 using std::vector;
0015 using std::ofstream;
0016 using std::ifstream;
0017 using std::ostream;
0018 using std::istream;
0019 using std::abs;
0020 
0021 double sixPoint2dInterp(double x, double y,
0022     double v00, double v01, double v02, double v10, double v11, double v20);
0023 
0024 double interpCubicDirect(vector<double>* x, vector<double>* y, double xx);
0025 double interpCubicMono(vector<double>* x, vector<double>* y, double xx);
0026 double interpLinearDirect(vector<double>* x, vector<double>* y, double xx);
0027 double interpLinearMono(vector<double>* x, vector<double>* y, double xx);
0028 double interpNearestDirect(vector<double>* x, vector<double>* y, double xx);
0029 double interpNearestMono(vector<double>* x, vector<double>* y, double xx);
0030 
0031 double invertFunc(double (*func)(double), double y, double xL, double xR, double dx, double x0, double relative_accuracy=1e-10);
0032 
0033 double invertTableDirect_hook(double xx);
0034 double invertTableDirect(vector<double>* x, vector<double>* y, double y0, double x0, double relative_accuracy=1e-10);
0035 
0036 double stringToDouble(string);
0037 vector<double> stringToDoubles(string);
0038 string toLower(string str);
0039 string trim(string str);
0040 
0041 vector< vector<double>* >* readBlockData(istream &stream_in);
0042 void releaseBlockData(vector< vector<double>* >* data);
0043 
0044 double adaptiveSimpsonsAux(double (*f)(double), double a, double b, double epsilon, double S, double fa, double fb, double fc, int bottom);
0045 double adaptiveSimpsons(double (*f)(double), double a, double b,  double epsilon=1e-15, int maxRecursionDepth=50);
0046 
0047 double qiu_simpsons(double (*f)(double), double a, double b, double epsilon=1e-15, int maxRecursionDepth=50);
0048 double qiu_simpsonsRel(double (*f)(double), double a, double b, double epsilon=1e-15, int maxRecursionDepth=50);
0049 long binarySearch(vector<double>* A, double value, bool skip_out_of_range=false);
0050 
0051 void formatedPrint(ostream&, int count, ...);
0052 long double gamma_function(long double x);
0053 long double log_gamma_function(long double x);
0054 double beta_function(double, double);
0055 double binomial_coefficient(double n, double k);
0056 
0057 void print_progressbar(double percentage, int length=50, string symbol="#");
0058 void display_logo(int which=1);
0059 
0060 inline long irand(long LB, long RB)
0061 // Get an interger between LB and RB (including) with uniform distribution.
0062 {
0063   return LB + (long)((RB-LB+1)*(drand48()-1e-25));
0064 }
0065 
0066 inline double drand(double LB, double RB)
0067 // Get random number with uniform distribution between LB and RB with 
0068 // boundary-protection.
0069 {
0070   double width = RB-LB;
0071   double dw = width*1e-30;
0072   return LB+dw+(width-2*dw)*drand48();
0073 }
0074 
0075 inline bool is_integer(double x, double tolerance=1e-30)
0076 // Check if a double number is close to an integer
0077 {
0078   if (abs(x-round(x))<tolerance) return true;
0079   else return false;
0080 }
0081 
0082 void GaussLegendre_getWeight(int npts,double* x,double* w, double A, double B, int opt);
0083 
0084 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
0085 
0086 #endif
0087 
0088 
0089 
0090 /*----------------------------------------------------------------------
0091  Change logs:
0092 
0093  04-26-2010:
0094  -- invertFunc, invertTable, stringToDoubles, readBlockData functions added.
0095  04-25-2011:
0096  -- interpCubic function adxed.
0097  12-17-2010:
0098  -- sixPoint2dInterp function adxed.
0099  08-05-2011:
0100  -- Ver 1.1:
0101     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].
0102  09-09-2011:
0103  -- Ver 1.2:
0104     Function toLower added. It simply convert all letters in a string to lower case.
0105     Function stringToDouble added.
0106     Function trim added.
0107  02-02-2012:
0108  -- Ver 1.2.1:
0109     Function trim now also removes tabs besides spaces.
0110  02-04-2012:
0111  -- Ver 1.5:
0112     Functions added: interpCubic, binarySearch, formatedPrint, gamma_function,
0113     interpLinearDirect, interpLinearMono, interpNearestDirect, interpNearestMono.
0114     Function interpCubic is renamed to interpCubicMono.
0115  03-14-2012:
0116  -- Ver 1.5.1:
0117     Functions added: print_progressbar.
0118  03-19-2012:
0119  -- Ver 1.6:
0120     Functions added: display_logo, drand, irand, GaussLegendre_getweight, get_bin_average_and_count.
0121     Function formatedPrint now accepts a stream argument.
0122  03-19-2012:
0123  -- Ver 1.6.1:
0124     Function get_bin_average_and_count can now average transformed data
0125     that have different number of columns than the data directly read in.
0126  04-03-2012:
0127  -- Ver 1.7.0:
0128     Functions added: is_integer, binomial_coefficient, beta_function, 
0129     log_gamma_function.
0130 -----------------------------------------------------------------------*/