![]() |
OMSim
Geant4 for IceCube optical module studies
|
A collection of helper functions for numerical operations. More...
Functions | |
std::vector< double > | arange (double p_start, double p_stop, double p_step) |
Generates a sequence of numbers. | |
TGraph * | create1dInterpolator (const std::vector< double > &p_X, const std::vector< double > &p_y, const std::string &p_name) |
Creates a TGraph interpolator from x and y data points. | |
TGraph * | create1dInterpolator (const std::string &p_filename) |
Creates a TGraph interpolator from x and y in file. | |
TH2D * | create2DHistogramFromDataFile (const std::string &p_filePath) |
Create a histogram from provided data. | |
void | ensureDirectoryExists (const std::string &p_filePath) |
Ensure that the directory of a file to be created exists. | |
std::pair< std::vector< double >, std::vector< double > > | histogram (const std::vector< double > &data, const std::variant< int, std::vector< double > > &bins, const std::optional< std::pair< double, double > > &p_range, const std::vector< double > &p_weights) |
Compute the histogram of a dataset. | |
G4String | getThreadIDStr () |
std::vector< std::vector< double > > | loadtxt (const std::string &p_filePath, bool p_unpack, size_t p_skipRows, char p_delimiter, char p_comments) |
Reads numerical data from a file and returns it as a 2D vector. Similar to numpy.loadtxt. | |
std::vector< double > | linspace (double p_start, double p_stop, int p_num, bool p_endpoint) |
Generates a linearly spaced vector. | |
std::vector< double > | logspace (double p_start, double p_stop, int p_num, double base, bool p_endpoint) |
Generates a logarithmically spaced vector. | |
void | sortVectorByReference (std::vector< G4double > &p_referenceVector, std::vector< G4double > &p_sortVector) |
Sorts two vectors (p_sortVector & p_referenceVector) based on the order of values in p_referenceVector. | |
double | median (std::vector< double > p_vec) |
double | mean (const std::vector< double > &p_vec, const std::vector< double > &p_weights={}) |
double | std (const std::vector< double > &vec, const std::vector< double > &p_weights={}) |
void | throwError (const G4String &message) |
std::vector< G4String > | splitStringByDelimiter (G4String const &p_string, char p_delim) |
std::vector< G4String > | splitStringByDelimiter (char *p_char, char p_delim) |
Variables | |
std::string | visualisationURL = "https://icecube.github.io/OMSim/md_extra_doc_2_technicalities.html#autotoc_md30" |
This namespace provides static methods for common numerical tasks such as loading data from a file, and generating linearly and logarithmically spaced sequences.
std::vector< double > Tools::arange | ( | double | p_start, |
double | p_stop, | ||
double | p_step | ||
) |
p_start | The p_start of the interval. The interval includes this value. |
p_stop | The end of the interval. The interval does not include this value. |
p_step | The spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. |
std::invalid_argument | if p_step is zero. |
TGraph * Tools::create1dInterpolator | ( | const std::string & | p_filename | ) |
p_filename |
TGraph * Tools::create1dInterpolator | ( | const std::vector< double > & | p_X, |
const std::vector< double > & | p_y, | ||
const std::string & | p_name | ||
) |
p_X | Vector of x-coordinates. |
p_y | Vector of y-coordinates. |
p_name | Optional name for the TGraph. It should be unique! |
TH2D * Tools::create2DHistogramFromDataFile | ( | const std::string & | p_filePath | ) |
Loads the data from a given path and constructs a histogram based on the data.
p_filePath | Path to the data file. |
pTH2DName | Name of the histogram. |
void Tools::ensureDirectoryExists | ( | const std::string & | p_filePath | ) |
p_filePath | The path of file. |
G4String Tools::getThreadIDStr | ( | ) |
std::pair< std::vector< double >, std::vector< double > > Tools::histogram | ( | const std::vector< double > & | data, |
const std::variant< int, std::vector< double > > & | bins, | ||
const std::optional< std::pair< double, double > > & | p_range, | ||
const std::vector< double > & | p_weights | ||
) |
data | Input data. The histogram is computed over the data. |
bins | The number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges, including the rightmost edge. |
range | The lower and upper range of the bins. If not provided, range is simply (min(data), max(data)). Values outside the range are ignored. |
std::vector< double > Tools::linspace | ( | double | p_start, |
double | p_stop, | ||
int | p_num, | ||
bool | p_endpoint | ||
) |
Creates a vector of equally spaced values between p_start
and end
.
p_start | The starting value of the sequence. |
p_stop | The end value of the sequence, unless p_endpoint is False. In that case, the sequence consists of all but the last of p_num + 1 evenly spaced samples, so that p_stop is excluded. Note that the p_step size changes when p_endpoint is False. |
p_num | The number of points to generate in the sequence. |
p_endpoint | If True (default), p_stop is the last sample. Otherwise, it is not included. |
std::invalid_argument | if p_num is less than 2. |
std::vector< std::vector< double > > Tools::loadtxt | ( | const std::string & | p_filePath, |
bool | p_unpack, | ||
size_t | p_skipRows, | ||
char | p_delimiter, | ||
char | p_comments | ||
) |
p_filePath | The path to the input file. |
p_unpack | Optional. If true, the returned data is transposed, i.e., unpacked into columns. Default is true. |
p_skipRows | Optional. The number of lines to skip at the beginning of the file. Default is 0. |
p_delimiter | The character used to separate values in each line of the input file. |
p_comments | Optional. The character used to indicate the p_start of a comment. Default is '#'. |
std::runtime_error | if the file cannot be opened. |
std::vector< double > Tools::logspace | ( | double | p_start, |
double | p_stop, | ||
int | p_num, | ||
double | base, | ||
bool | p_endpoint | ||
) |
Creates a vector of values that are logarithmically spaced. The sequence starts at base^p_start and ends at base^p_stop.
p_start | The starting value of the sequence (as a power of base). |
p_stop | The ending value of the sequence (as a power of base). |
p_num | The number of points to generate in the sequence. Default is 50. |
base | The base of the log space. Default is 10.0. |
p_endpoint | Whether to include the p_stop value in the output. Default is true. |
std::invalid_argument | if p_num is negative. |
void Tools::sortVectorByReference | ( | std::vector< G4double > & | p_referenceVector, |
std::vector< G4double > & | p_sortVector | ||
) |
p_referenceVector | The ordering of these values will determine the final order of both vectors. |
p_sortVector | The vector to be sorted according to the p_referenceVector. |
std::invalid_argument | if the vectors do not have the same size. |