1 #ifndef USEFULFUNCTIONS
2 #define USEFULFUNCTIONS
11 #include <type_traits>
14 #include <initializer_list>
17 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
18 #define __DBGMSG__ __FILENAME__ << ": " << __LINE__ << "\t"
44 if (value < std::numeric_limits<double>::epsilon())
56 std::string timeUnit(
" [ps]");
61 timeUnit = std::string(
" [ns]");
65 timeUnit = std::string(
" [ms]");
69 timeUnit = std::string(
" [fs]");
72 std::stringstream timeOutput;
73 timeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << time << timeUnit;
74 return timeOutput.str();
79 std::string sposUnit(
" [m]");
83 sposUnit = std::string(
" [mm]");
88 sposUnit = std::string(
" [um]");
91 std::stringstream positionOutput;
92 positionOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << spos << sposUnit;
93 return positionOutput.str();
98 std::string sposUnit(
" [m]");
100 for (
unsigned int i = 1; i < 3u; ++ i) {
104 std::stringstream positionOutput;
109 sposUnit = std::string(
" [mm]");
115 sposUnit = std::string(
" [um]");
118 positionOutput << std::fixed << std::setprecision(precision)
120 << std::setw(precision + 7) << spos(0) <<
" , "
121 << std::setw(precision + 7) << spos(1) <<
" , "
122 << std::setw(precision + 7) << spos(2)
124 return positionOutput.str();
129 std::string energyUnit(
" [MeV]");
130 double energy = energyInMeV;
132 if (energy > 1000.0) {
134 energyUnit = std::string(
" [GeV]");
135 }
else if (energy < 1.0) {
137 energyUnit = std::string(
" [keV]");
140 energyUnit = std::string(
" [eV]");
144 std::stringstream energyOutput;
145 energyOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << energy << energyUnit;
147 return energyOutput.str();
152 std::string chargeUnit(
" [fC]");
158 chargeUnit = std::string(
" [pC]");
163 chargeUnit = std::string(
" [nC]");
168 chargeUnit = std::string(
" [uC]");
171 std::stringstream chargeOutput;
172 chargeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << charge << chargeUnit;
174 return chargeOutput.str();
179 std::string
toUpper(
const std::string &str);
183 template <
typename T>
195 unsigned int rewindLinesSDDS(
const std::string &fileName,
double maxSPos,
bool checkForTime =
true);
197 std::string
base64_encode(
const std::string &string_to_encode);
200 template<
typename T,
typename A>
201 T*
c_data(std::vector<T,A>& v) {
return v.empty() ?
static_cast<T*
>(0) : &(v[0]); }
203 template<
typename T,
typename A>
204 T const*
c_data(std::vector<T,A>
const& v) {
return v.empty() ?
static_cast<T const*
>(0) : &(v[0]); }
208 template <
typename T>
210 static_assert(std::is_integral<T>::value,
"Util::toStringWithThousandSep: T must be of integer type");
215 powers -= powers % 3u;
217 std::ostringstream ret;
219 while (powers >= 3u) {
221 T pre = value / multiplicator;
223 ret << std::setw(3) << std::setfill(
'0') << pre << sep;
227 value -= pre * multiplicator;
234 ret << std::setw(3) << std::setfill(
'0') << value;
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
std::string combineFilePath(std::initializer_list< std::string > ilist)
std::string getChargeString(double charge, unsigned int precision=3)
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &)
double getKineticEnergy(Vector_t p, double mass)
double convertMomentumEVoverCToBetaGamma(double p, double mass)
double getBetaGamma(double Ekin, double mass)
std::string toUpper(const std::string &str)
std::string base64_decode(std::string const &encoded_string)
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 getEnergyString(double energyInMeV, unsigned int precision=3)
std::string getTimeString(double time, unsigned int precision=3)
T * c_data(std::vector< T, A > &v)
std::string getGitRevision()
std::string base64_encode(const std::string &string_to_encode)
Vector_t getBeta(Vector_t p)
double getGamma(Vector_t p)
std::string getLengthString(double spos, unsigned int precision=3)
std::string toStringWithThousandSep(T value, char sep='\'')
KahanAccumulation & operator+=(double value)