27#include <initializer_list>
35#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
36#define __DBGMSG__ __FILENAME__ << ": " << __LINE__ << "\t"
44 inline double getGamma(ippl::Vector<double, 3> p) {
46 for (
unsigned i = 0; i < 3; i++)
48 return std::sqrt(dotP + 1.0);
51 inline ippl::Vector<double, 3>
getBeta(ippl::Vector<double, 3> p) {
return p /
getGamma(p); }
58 double value = std::sqrt(std::pow(Ekin / mass + 1.0, 2) - 1.0);
59 if (value < std::numeric_limits<double>::epsilon()) value = std::sqrt(2 * Ekin / mass);
65 inline std::string
getTimeString(
double time,
unsigned int precision = 3) {
66 std::string timeUnit(
" [ps]");
69 if (std::abs(time) > 1000) {
71 timeUnit = std::string(
" [ns]");
73 if (std::abs(time) > 1000) {
75 timeUnit = std::string(
" [ms]");
77 }
else if (std::abs(time) < 1.0) {
79 timeUnit = std::string(
" [fs]");
82 std::stringstream timeOutput;
83 timeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << time
85 return timeOutput.str();
89 std::string sposUnit(
" [m]");
91 if (std::abs(spos) < 1.0) {
93 sposUnit = std::string(
" [mm]");
96 if (std::abs(spos) < 1.0) {
98 sposUnit = std::string(
" [um]");
101 std::stringstream positionOutput;
102 positionOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision)
104 return positionOutput.str();
107 inline std::string
getLengthString(ippl::Vector<double, 3> spos,
unsigned int precision = 3) {
108 std::string sposUnit(
" [m]");
109 double maxPos = std::abs(spos(0));
110 for (
unsigned int i = 1; i < 3u; ++i) {
111 maxPos = std::max(maxPos, std::abs(spos(i)));
114 std::stringstream positionOutput;
118 spos = spos * 1000.0;
119 sposUnit = std::string(
" [mm]");
124 spos = spos * 1000.0;
125 sposUnit = std::string(
" [um]");
128 positionOutput << std::fixed << std::setprecision(precision) <<
"( "
129 << std::setw(precision + 7) << spos(0) <<
" , " << std::setw(precision + 7)
130 << spos(1) <<
" , " << std::setw(precision + 7) << spos(2) <<
" )"
132 return positionOutput.str();
136 std::string energyUnit(
" [MeV]");
137 double energy = energyInMeV;
139 if (energy > 1000.0) {
141 energyUnit = std::string(
" [GeV]");
142 }
else if (energy < 1.0) {
144 energyUnit = std::string(
" [keV]");
147 energyUnit = std::string(
" [eV]");
151 std::stringstream energyOutput;
152 energyOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision)
153 << energy << energyUnit;
155 return energyOutput.str();
159 std::string chargeUnit(
" [fC]");
163 if (std::abs(charge) > 1000.0) {
165 chargeUnit = std::string(
" [pC]");
168 if (std::abs(charge) > 1000.0) {
170 chargeUnit = std::string(
" [nC]");
173 if (std::abs(charge) > 1000.0) {
175 chargeUnit = std::string(
" [uC]");
178 std::stringstream chargeOutput;
179 chargeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision)
180 << charge << chargeUnit;
182 return chargeOutput.str();
186 Quaternion rotation,
const std::string& elementName =
"");
188 std::string
toUpper(
const std::string& str);
198 template <
class IteratorIn,
class IteratorOut>
199 void toString(IteratorIn first, IteratorIn last, IteratorOut out);
201 template <
typename T>
213 const std::string& fileName,
double maxSPos,
bool checkForTime =
true);
216 const std::string& string_to_encode);
219 template <
typename T,
typename A>
221 return v.empty() ?
static_cast<T*
>(0) : &(v[0]);
224 template <
typename T,
typename A>
226 return v.empty() ?
static_cast<T const*
>(0) : &(v[0]);
233 std::is_integral<T>::value,
"Util::toStringWithThousandSep: T must be of integer type");
235 unsigned int powers =
236 std::floor(std::max(0.0, std::log(std::abs((
double)value)) / std::log(10.0)));
237 powers -= powers % 3u;
239 std::ostringstream ret;
241 while (powers >= 3u) {
242 T multiplicator = std::pow(
T(10), powers);
243 T pre = value / multiplicator;
245 ret << std::setw(3) << std::setfill(
'0') << pre << sep;
249 value -= pre * multiplicator;
256 ret << std::setw(3) << std::setfill(
'0') << value;
264template <
class IteratorIn,
class IteratorOut>
266 std::transform(first, last, out, [](
auto d) {
267 std::ostringstream stm;
Quaternion storage and rotation algebra used by OPALX geometry code.
std::string combineFilePath(std::initializer_list< std::string > ilist)
std::string doubleVectorToString(const std::vector< double > &v)
std::string getChargeString(double charge, unsigned int precision=3)
std::string boolVectorToUpperString(const std::vector< bool > &b)
void toString(IteratorIn first, IteratorIn last, IteratorOut out)
double convertMomentumEVoverCToBetaGamma(double p, double mass)
double getBetaGamma(double Ekin, double mass)
double getGamma(ippl::Vector< double, 3 > p)
std::string toUpper(const std::string &str)
T * c_data(std::vector< T, A > &v)
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
double getKineticEnergy(ippl::Vector< double, 3 > p, double mass)
std::string getEnergyString(double energyInMeV, unsigned int precision=3)
std::string getTimeString(double time, unsigned int precision=3)
std::string getGitRevision()
std::string base64_encode(const std::string &string_to_encode)
ippl::Vector< double, 3 > getBeta(ippl::Vector< double, 3 > p)
std::string boolToUpperString(const bool &b)
std::string getLengthString(double spos, unsigned int precision=3)
std::string toStringWithThousandSep(T value, char sep='\'')
Vector_t< double, 3 > getTaitBryantAngles(Quaternion rotation, const std::string &)
KahanAccumulation & operator+=(double value)