1 #ifndef USEFULFUNCTIONS
2 #define USEFULFUNCTIONS
10 #include <type_traits>
14 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
15 #define __DBGMSG__ __FILENAME__ << ": " << __LINE__ << "\t"
34 double getP(
double E,
double mass) {
35 double gamma = E / mass + 1;
41 std::string timeUnit(
" [ps]");
46 timeUnit = std::string(
" [ns]");
50 timeUnit = std::string(
" [ms]");
54 timeUnit = std::string(
" [fs]");
57 std::stringstream timeOutput;
58 timeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << time << timeUnit;
59 return timeOutput.str();
64 std::string sposUnit(
" [m]");
68 sposUnit = std::string(
" [mm]");
73 sposUnit = std::string(
" [um]");
76 std::stringstream positionOutput;
77 positionOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << spos << sposUnit;
78 return positionOutput.str();
83 std::string sposUnit(
" [m]");
85 for (
unsigned int i = 1; i < 3u; ++ i) {
89 std::stringstream positionOutput;
94 sposUnit = std::string(
" [mm]");
100 sposUnit = std::string(
" [um]");
103 positionOutput << std::fixed << std::setprecision(precision)
105 << std::setw(precision + 7) << spos(0) <<
" , "
106 << std::setw(precision + 7) << spos(1) <<
" , "
107 << std::setw(precision + 7) << spos(2)
109 return positionOutput.str();
114 std::string energyUnit(
" [MeV]");
115 double energy = energyInMeV;
117 if (energy > 1000.0) {
119 energyUnit = std::string(
" [GeV]");
120 }
else if (energy < 1.0) {
122 energyUnit = std::string(
" [keV]");
125 energyUnit = std::string(
" [eV]");
129 std::stringstream energyOutput;
130 energyOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << energy << energyUnit;
132 return energyOutput.str();
137 std::string chargeUnit(
" [fC]");
143 chargeUnit = std::string(
" [pC]");
148 chargeUnit = std::string(
" [nC]");
153 chargeUnit = std::string(
" [uC]");
156 std::stringstream chargeOutput;
157 chargeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << charge << chargeUnit;
159 return chargeOutput.str();
164 std::string
toUpper(
const std::string &str);
166 template <
typename T>
178 unsigned int rewindLinesSDDS(
const std::string &fileName,
double maxSPos,
bool checkForTime =
true);
180 std::string
base64_encode(
const std::string &string_to_encode);
184 template <
typename T>
186 static_assert(std::is_integral<T>::value,
"Util::toStringWithThousandSep: T must be of integer type");
191 powers -= powers % 3u;
193 std::ostringstream ret;
195 while (powers >= 3u) {
197 T pre = value / multiplicator;
199 ret << std::setw(3) << std::setfill(
'0') << pre << sep;
203 value -= pre * multiplicator;
210 ret << std::setw(3) << std::setfill(
'0') << value;
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
std::string toStringWithThousandSep(T value, char sep= '\'')
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &elementName)
double getP(double E, double mass)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
std::string toUpper(const std::string &str)
std::string getLengthString(double spos, unsigned int precision=3)
Tps< T > log(const Tps< T > &x)
Natural logarithm.
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
std::string getChargeString(double charge, unsigned int precision=3)
double getGamma(Vector_t p)
KahanAccumulation & operator+=(double value)
std::string getTimeString(double time, unsigned int precision=3)
std::string base64_encode(const std::string &string_to_encode)
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
std::string getGitRevision()
double getEnergy(Vector_t p, double mass)
unsigned int rewindLinesSDDS(const std::string &fileName, double maxSPos, bool checkForTime)
rewind the SDDS file such that the spos of the last step is less or equal to maxSPos ...
std::string base64_decode(std::string const &encoded_string)
std::string getEnergyString(double energyInMeV, unsigned int precision=3)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)