Utils.h

Generally useful functions and constants.

These are not specific to one usage, and may be used in multiple files.

Functions

int countLines(ifstream &inFile)

Count the number of lines in a file.

vector<double> add(vector<double> u, vector<double> v)

Elementwise vector addition.

vector<double> mult(vector<double> u, vector<double> v)

Elementwise vector multiplication.

double sum(vector<double> v)

Sum the elements in a vector.

double stddev(vector<double> v)

Sample standard deviation of a vector. DOF = n-1.

double max(vector<double> v)

Maximum element of a vector.

double mean(vector<double> v)

Mean of a vector.

double min(double *v, int n)

Minimum element of an array of length n.

double max(double *v, int n)

Maximum element of an array of length n.

double mean(double *v, int n)

Mean of an array of length n.

double stddev(double *v, int n)

Sample standard deviation of an array of length n.

double square(double x)

Alias for x * x.

double atanh(double x)

Hyperbolic arctangent.

See
Wolfram Mathworld, Equation (1).

double min(double a, double b)

Minimum of two numbers, a and b.

double max(double a, double b)

Maximum of two numbers, a and b.

bool isLess(int a, int b)

Is a < b?

bool isIn(int x, vector<int> v)

Is x in v?

bool isIn(string str, string substr)

Is substr a substring of str?

bool file_exists(const char *pathname)

Check whether a file exists and is not a directory.

bool dir_exists(const char *pathname)

Check whether a directory exists.

int roundUp(int numToRound, int multiple)

Round up to nearest multiple of a number.

double solveLinear(TH1D *hist, int bin1, int bin2, double yc)

Given a TH1D and a two bin numbers, draw a line between the points and solve for the \(x \) value where \(y=y_c \) (yc stands for y_cutoff).

void stripTrailingSlash(char *strippedPath, const char *path)

Remove the trailing forward slash from path if it is there.

void joinPath(char *path, const char *prefix, const char *suffix)

Join two paths by a forward slash (using stripTrailingSlash)

Variables

const double PI = 3.141592653589793
const double NANO_DENS_TO_MACRO = 1.0/0.60221409

Multiply \(\mathrm{amu}/\mathrm{\mathring{A}}^3\) by this number to get \(\mathrm{g}/\mathrm{cm}^3 \).