OMSim
Geant4 for IceCube optical module studies
OMSimTools.hh
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "OMSimLogger.hh"
9 #include "globals.hh"
10 #include <TGraph.h>
11 #include <TH2D.h>
12 #include <variant>
13 #include <optional>
24 namespace Tools
25 {
26  std::vector<double> arange(double start, double stop, double step);
27  TGraph* create1dInterpolator(const std::vector<double>& pX, const std::vector<double>& pY, const std::string& pName);
28  TGraph* create1dInterpolator(const std::string& pFileName);
29  TH2D *create2DHistogramFromDataFile(const std::string &pFilePath);
30 
31  void ensureDirectoryExists(const std::string &filepath);
32  std::pair<std::vector<double>, std::vector<double>> histogram(
33  const std::vector<double> &data,
34  const std::variant<int, std::vector<double>> &bins = 10,
35  const std::optional<std::pair<double, double>> &range = std::nullopt,
36  const std::vector<double> &weights = std::vector<double>());
37 
38  G4String getThreadIDStr();
39  std::vector<std::vector<double>> loadtxt(const std::string &pFilePath,
40  bool pUnpack = true,
41  size_t pSkipRows = 0,
42  char pDelimiter = ' ',
43  char pComments = '#');
44  std::vector<double> linspace(double start, double end, int num_points, bool endpoint = true);
45  std::vector<double> logspace(double start, double end, int num_points, double base = 10.0, bool endpoint = true);
46  void sortVectorByReference(std::vector<G4double> &referenceVector, std::vector<G4double> &sortVector);
47  double median(std::vector<double> p_vec);
48  double mean(const std::vector<double> &p_vec, const std::vector<double> &p_weights = {});
49  double std(const std::vector<double>& vec, const std::vector<double> &p_weights = {});
50 
51  void throwError(const G4String& message);
52  std::vector<G4String> splitStringByDelimiter(G4String const &p_string, char p_delim);
53  std::vector<G4String> splitStringByDelimiter(char *p_char, char p_delim);
54  extern std::string visualisationURL;
55 };
56 
A collection of helper functions for numerical operations.
std::vector< double > linspace(double start, double end, int num_points, bool endpoint=true)
Generates a linearly spaced vector.
Definition: OMSimTools.cc:330
void sortVectorByReference(std::vector< G4double > &referenceVector, std::vector< G4double > &sortVector)
Sorts two vectors (p_sortVector & p_referenceVector) based on the order of values in p_referenceVecto...
Definition: OMSimTools.cc:401
std::pair< std::vector< double >, std::vector< double > > histogram(const std::vector< double > &data, const std::variant< int, std::vector< double >> &bins=10, const std::optional< std::pair< double, double >> &range=std::nullopt, const std::vector< double > &weights=std::vector< double >())
Compute the histogram of a dataset.
Definition: OMSimTools.cc:161
TGraph * create1dInterpolator(const std::vector< double > &pX, const std::vector< double > &pY, const std::string &pName)
Creates a TGraph interpolator from x and y data points.
Definition: OMSimTools.cc:68
void ensureDirectoryExists(const std::string &filepath)
Ensure that the directory of a file to be created exists.
Definition: OMSimTools.cc:451
TH2D * create2DHistogramFromDataFile(const std::string &pFilePath)
Create a histogram from provided data.
Definition: OMSimTools.cc:101
std::vector< double > logspace(double start, double end, int num_points, double base=10.0, bool endpoint=true)
Generates a logarithmically spaced vector.
Definition: OMSimTools.cc:364
G4String getThreadIDStr()
Definition: OMSimTools.cc:439
std::vector< std::vector< double > > loadtxt(const std::string &pFilePath, bool pUnpack=true, size_t pSkipRows=0, char pDelimiter=' ', char pComments='#')
Reads numerical data from a file and returns it as a 2D vector. Similar to numpy.loadtxt.
Definition: OMSimTools.cc:264
std::vector< double > arange(double start, double stop, double step)
Generates a sequence of numbers.
Definition: OMSimTools.cc:22