26#include "Utility/IpplInfo.h"
41 const h5_int64_t h5err = H5WriteFileAttribString(
H5file_m, attribute, value);
43 if (h5err <= H5_ERR) {
45 ss <<
"failed to write string attribute " << attribute <<
" to file " <<
fileName_m;
51 const char* attribute,
const h5_float64_t* value, h5_int64_t size) {
52 const h5_int64_t h5err = H5WriteStepAttribFloat64(
H5file_m, attribute, value,
size);
54 if (h5err <= H5_ERR) {
56 ss <<
"failed to write float64 attribute " << attribute <<
" to file " <<
fileName_m;
62 const char* attribute,
const h5_int64_t* value, h5_int64_t size) {
63 const h5_int64_t h5err = H5WriteStepAttribInt64(
H5file_m, attribute, value,
size);
65 if (h5err <= H5_ERR) {
67 ss <<
"failed to write int64 attribute " << attribute <<
" to file " <<
fileName_m;
73 const h5_int64_t h5err = H5PartWriteDataFloat64(
H5file_m, name, value);
75 if (h5err <= H5_ERR) {
77 ss <<
"failed to write float64 data " << name <<
" to file " <<
fileName_m;
83 const h5_int64_t h5err = H5PartWriteDataInt64(
H5file_m, name, value);
85 if (h5err <= H5_ERR) {
87 ss <<
"failed to write int64 data " << name <<
" to file " <<
fileName_m;
95 if (h5err <= H5_ERR) {
106 std::stringstream ss;
107 ss <<
"failed to get number of steps of file " <<
fileName_m;
113 const h5_int64_t h5err = H5PartSetNumParticles(
H5file_m, num);
115 if (h5err <= H5_ERR) {
116 std::stringstream ss;
117 ss <<
"failed to set number of particles to " << num <<
" in step " <<
H5call_m
124 H5file_m = H5OpenFile(fname, mode, props);
126 if (
H5file_m ==
static_cast<h5_file_t
>(H5_ERR)) {
127 std::stringstream ss;
134 const h5_int64_t h5err = H5CloseFile(
H5file_m);
136 if (h5err <= H5_ERR) {
137 std::stringstream ss;
146 constexpr double percentileOneSigmaNormalDist = 0.6826894921370859;
148 constexpr double percentileTwoSigmasNormalDist = 0.9544997361036416;
150 constexpr double percentileThreeSigmasNormalDist = 0.9973002039367398;
152 constexpr double percentileFourSigmasNormalDist = 0.9999366575163338;
154 int percentileParticleCount(
unsigned long nTotal,
double fraction) {
155 const double value = std::floor(
static_cast<double>(nTotal) * fraction + 0.5);
157 if (value >
static_cast<double>(std::numeric_limits<int>::max())) {
158 std::stringstream ss;
159 ss <<
"Percentile particle count " << value <<
" does not fit into int.";
164 return static_cast<int>(value);
167 using OneDPhaseSpace_t = std::array<double, 2>;
168 using OneDIterator_t = std::vector<OneDPhaseSpace_t>::iterator;
171 const std::vector<OpalParticle>& particles,
size_t startIdx,
size_t numParticles,
172 h5_float64_t* buffer, std::function<h5_float64_t(
const OpalParticle&)> select) {
174 particles.begin() + startIdx, particles.begin() + startIdx + numParticles, buffer,
179 const std::vector<OpalParticle>& particles,
size_t startIdx,
size_t numParticles,
180 h5_int64_t* buffer, std::function<h5_int64_t(
const OpalParticle&)> select) {
182 particles.begin() + startIdx, particles.begin() + startIdx + numParticles, buffer,
186 std::pair<double, OneDIterator_t> determinePercentileRange(
187 const OneDIterator_t& begin,
const OneDIterator_t& end,
188 const std::vector<int>& globalAccumulatedHistogram,
189 const std::vector<int>& localAccumulatedHistogram,
unsigned int dimension,
190 int numRequiredParticles,
double meanR) {
191 const unsigned int numBins = globalAccumulatedHistogram.size() / 3;
193 double percentile = 0.0;
194 OneDIterator_t endPercentile = end;
196 for (
unsigned int i = 1; i < numBins; ++i) {
197 const unsigned int idx = dimension * numBins + i;
199 if (globalAccumulatedHistogram[idx] > numRequiredParticles) {
200 OneDIterator_t beginBin = begin + localAccumulatedHistogram[idx - 1];
201 OneDIterator_t endBin = begin + localAccumulatedHistogram[idx];
203 int numMissingParticles =
204 numRequiredParticles - globalAccumulatedHistogram[idx - 1];
206 unsigned int shift = 2;
207 while (numMissingParticles == 0 && idx >= shift) {
208 beginBin = begin + localAccumulatedHistogram[idx - shift];
209 numMissingParticles =
210 numRequiredParticles - globalAccumulatedHistogram[idx - shift];
214 std::vector<unsigned int> numParticlesInBin(ippl::Comm->size() + 1, 0);
215 numParticlesInBin[ippl::Comm->rank() + 1] =
216 static_cast<unsigned int>(endBin - beginBin);
218 ippl::Comm->allreduce(
219 &(numParticlesInBin[1]), ippl::Comm->size(), std::plus<unsigned int>());
222 numParticlesInBin.begin(), numParticlesInBin.end(),
223 numParticlesInBin.begin());
225 std::vector<double> positions(numParticlesInBin.back(), 0.0);
228 beginBin, endBin, positions.begin() + numParticlesInBin[ippl::Comm->rank()],
229 [meanR](
const OneDPhaseSpace_t& particle) {
230 return std::abs(particle[0] - meanR);
233 if (!positions.empty()) {
234 ippl::Comm->allreduce(positions.data(), positions.size(), std::plus<double>());
236 std::sort(positions.begin(), positions.end());
238 const auto rhs =
static_cast<std::size_t
>(std::min<int>(
239 numMissingParticles,
static_cast<int>(positions.size()) - 1));
241 const auto lhs = rhs == 0 ? 0 : rhs - 1;
243 percentile = 0.5 * (positions[lhs] + positions[rhs]);
246 for (OneDIterator_t it = beginBin; it != endBin; ++it) {
247 if (std::abs((*it)[0] - meanR) > percentile) {
248 return std::make_pair(percentile, it);
252 endPercentile = endBin;
257 return std::make_pair(percentile, endPercentile);
260 double computeNormalizedEmittance(
const OneDIterator_t& begin,
const OneDIterator_t& end) {
261 double localStatistics[] = {0.0, 0.0, 0.0, 0.0};
263 localStatistics[0] =
static_cast<double>(end - begin);
265 for (OneDIterator_t it = begin; it < end; ++it) {
266 const OneDPhaseSpace_t& rp = *it;
268 localStatistics[1] += rp[0];
269 localStatistics[2] += rp[1];
270 localStatistics[3] += rp[0] * rp[1];
273 ippl::Comm->allreduce(localStatistics, 4, std::plus<double>());
275 const double numParticles = localStatistics[0];
277 if (numParticles == 0.0) {
281 const double perParticle = 1.0 / numParticles;
282 const double meanR = localStatistics[1] * perParticle;
283 const double meanP = localStatistics[2] * perParticle;
284 const double RP = localStatistics[3] * perParticle;
286 double varianceStatistics[] = {0.0, 0.0};
288 for (OneDIterator_t it = begin; it < end; ++it) {
289 const OneDPhaseSpace_t& rp = *it;
291 varianceStatistics[0] += std::pow(rp[0] - meanR, 2);
292 varianceStatistics[1] += std::pow(rp[1] - meanP, 2);
295 ippl::Comm->allreduce(varianceStatistics, 2, std::plus<double>());
297 const double stdR = std::sqrt(varianceStatistics[0] / numParticles);
298 const double stdP = std::sqrt(varianceStatistics[1] / numParticles);
300 const double sumRP = RP - meanR * meanP;
301 const double squaredEps = std::pow(stdR * stdP, 2) - std::pow(sumRP, 2);
303 return std::sqrt(std::max(squaredEps, 0.0));
306 void computeSetPercentiles(
307 const std::vector<OpalParticle>& particles,
size_t startIdx,
size_t nLoc,
313 unsigned int numBins =
static_cast<unsigned int>(
314 3.5 * std::pow(3.0, std::log10(
static_cast<double>(stat.
nTotal_m))));
316 numBins = std::max(1u, numBins);
318 std::vector<gsl_histogram*> histograms(3,
nullptr);
322 for (
unsigned int d = 0; d < 3; ++d) {
327 if (maxR(d) <= 0.0) {
335 for (
size_t k = 0; k < nLoc; ++k) {
338 for (
unsigned int d = 0; d < 3; ++d) {
343 std::vector<int> localHistogramValues(3 * (numBins + 1), 0);
344 std::vector<int> globalHistogramValues(3 * (numBins + 1), 0);
346 for (
unsigned int d = 0; d < 3; ++d) {
349 for (
unsigned int j = 0; j < numBins; ++j) {
351 localHistogramValues[d * (numBins + 1) + j + 1] = accumulated;
357 ippl::Comm->allreduce(
358 localHistogramValues.data(), globalHistogramValues.data(), 3 * (numBins + 1),
361 const int numParticles68 =
362 percentileParticleCount(stat.
nTotal_m, percentileOneSigmaNormalDist);
364 const int numParticles95 =
365 percentileParticleCount(stat.
nTotal_m, percentileTwoSigmasNormalDist);
367 const int numParticles99 =
368 percentileParticleCount(stat.
nTotal_m, percentileThreeSigmasNormalDist);
370 const int numParticles99_99 =
371 percentileParticleCount(stat.
nTotal_m, percentileFourSigmasNormalDist);
373 for (
unsigned int d = 0; d < 3; ++d) {
374 std::vector<OneDPhaseSpace_t> oneDPhaseSpace(nLoc);
376 for (
size_t k = 0; k < nLoc; ++k) {
379 oneDPhaseSpace[k][0] = particle[2 * d];
380 oneDPhaseSpace[k][1] = particle[2 * d + 1];
384 oneDPhaseSpace.begin(), oneDPhaseSpace.end(),
385 [d, &stat](
const OneDPhaseSpace_t& left,
const OneDPhaseSpace_t& right) {
386 return std::abs(left[0] - stat.rmean_m(d))
387 < std::abs(right[0] - stat.rmean_m(d));
390 OneDIterator_t endSixtyEight = oneDPhaseSpace.end();
391 OneDIterator_t endNinetyFive = oneDPhaseSpace.end();
392 OneDIterator_t endNinetyNine = oneDPhaseSpace.end();
393 OneDIterator_t endNinetyNine_NinetyNine = oneDPhaseSpace.end();
396 oneDPhaseSpace.begin(), oneDPhaseSpace.end(), globalHistogramValues,
397 localHistogramValues, d, numParticles68, stat.
rmean_m(d));
400 oneDPhaseSpace.begin(), oneDPhaseSpace.end(), globalHistogramValues,
401 localHistogramValues, d, numParticles95, stat.
rmean_m(d));
404 oneDPhaseSpace.begin(), oneDPhaseSpace.end(), globalHistogramValues,
405 localHistogramValues, d, numParticles99, stat.
rmean_m(d));
408 determinePercentileRange(
409 oneDPhaseSpace.begin(), oneDPhaseSpace.end(), globalHistogramValues,
410 localHistogramValues, d, numParticles99_99, stat.
rmean_m(d));
413 computeNormalizedEmittance(oneDPhaseSpace.begin(), endSixtyEight);
416 computeNormalizedEmittance(oneDPhaseSpace.begin(), endNinetyFive);
419 computeNormalizedEmittance(oneDPhaseSpace.begin(), endNinetyNine);
422 computeNormalizedEmittance(oneDPhaseSpace.begin(), endNinetyNine_NinetyNine);
436 meanKineticEnergy_m(0.0),
437 stdKineticEnergy_m(0.0),
458 sixtyEightPercentile_m(0.0),
459 ninetyFivePercentile_m(0.0),
460 ninetyNinePercentile_m(0.0),
461 ninetyNine_NinetyNinePercentile_m(0.0),
462 normalizedEps68Percentile_m(0.0),
463 normalizedEps95Percentile_m(0.0),
464 normalizedEps99Percentile_m(0.0),
465 normalizedEps99_99Percentile_m(0.0) {}
468 : h5hut_mode_m(hdf5Save),
472 collectionType_m(collectionType) {
479 "LossDataSink::LossDataSink",
480 "You must select an OPTION to save Loss data files\n"
481 "Please, choose 'ENABLEHDF5=TRUE' or 'ASCIIDUMP=TRUE'");
492 : h5hut_mode_m(rhs.h5hut_mode_m),
494 outputName_m(rhs.outputName_m),
495 H5call_m(rhs.H5call_m),
496 RefPartR_m(rhs.RefPartR_m),
497 RefPartP_m(rhs.RefPartP_m),
498 globalTrackStep_m(rhs.globalTrackStep_m),
499 refTime_m(rhs.refTime_m),
501 collectionType_m(rhs.collectionType_m) {
512 if (ippl::Comm !=
nullptr) {
513 ippl::Comm->barrier();
518 h5_prop_t props = H5CreateFileProp();
519 MPI_Comm comm = ippl::Comm->getCommunicator();
520 H5SetPropFileMPIOCollective(props, &comm);
527 std::stringstream OPAL_version;
528 OPAL_version << buildinfo::project_name <<
" " << buildinfo::project_version <<
" # git rev. "
587 if (ippl::Comm->rank() == 0) {
588 os_m <<
"# x (m), y (m), z (m), px ( ), py ( ), pz ( ), id";
590 os_m <<
", turn ( ), bunchNumber ( )";
592 os_m <<
", time (s)" << std::endl;
598 long long globalTrackStep) {
608 const std::optional<std::pair<int, short>>& turnBunchNumPair) {
609 if (turnBunchNumPair) {
612 "LossDataSink::addParticle",
613 "Either all particles or no particles must have turn number and bunch number");
622 "LossDataSink::addParticle",
623 "Either all particles or no particles must have turn number and bunch number");
638 namespace fs = std::filesystem;
651 for (
unsigned int i = 0; i < numSets; ++i) {
669 ippl::Comm->barrier();
689 const unsigned long long nLocal =
static_cast<unsigned long long>(
particles_m.size());
691 unsigned long long nGlobal = 0;
692 ippl::Comm->allreduce(&nLocal, &nGlobal, 1, std::plus<unsigned long long>());
700 ippl::Comm->allreduce(hasTurnInformation, 1, std::logical_or<bool>());
702 return hasTurnInformation > 0;
708 size_t endIdx = nLoc;
712 nLoc = endIdx - startIdx;
726 "LossDataSink::saveH5",
727 "Turn/bunch information is globally present, but this rank does not have "
728 "turn/bunch data for all particles in this loss set.");
735 if (setIdx <
spos_m.size()) {
826 std::vector<h5_float64_t> f64bufferStorage(std::max<size_t>(nLoc, 1));
827 std::vector<h5_int64_t> i64bufferStorage(std::max<size_t>(nLoc, 1));
829 h5_float64_t* f64buffer = f64bufferStorage.data();
830 h5_int64_t* i64buffer = i64bufferStorage.data();
833 return particle.
getId();
838 return particle.
getX();
843 return particle.
getY();
848 return particle.
getZ();
853 return particle.
getPx();
858 return particle.
getPy();
863 return particle.
getPz();
903 "LossDataSink::saveASCII",
904 "Turn/bunch information is globally present, but this rank does not have "
905 "turn/bunch data for all particles.");
908 constexpr int tagCount = 43001;
909 constexpr int tagDouble = 43002;
910 constexpr int tagInt = 43003;
912 MPI_Comm comm = ippl::Comm->getCommunicator();
914 const int rank = ippl::Comm->rank();
915 const int size = ippl::Comm->size();
918 const std::size_t nIntColumns = hasTurn ? 3 : 1;
920 auto packDoubleData = [&]() {
921 std::vector<double> data(7 * nLoc);
923 for (std::size_t i = 0; i < nLoc; ++i) {
926 data[7 * i + 0] = particle.
getX();
927 data[7 * i + 1] = particle.
getY();
928 data[7 * i + 2] = particle.
getZ();
929 data[7 * i + 3] = particle.
getPx();
930 data[7 * i + 4] = particle.
getPy();
931 data[7 * i + 5] = particle.
getPz();
932 data[7 * i + 6] = particle.
getTime();
938 auto packIntegerData = [&]() {
939 std::vector<long long> data(nIntColumns * nLoc);
941 for (std::size_t i = 0; i < nLoc; ++i) {
944 data[nIntColumns * i + 0] =
static_cast<long long>(particle.
getId());
947 data[nIntColumns * i + 1] =
static_cast<long long>(
turnNumber_m[i]);
949 data[nIntColumns * i + 2] =
static_cast<long long>(
bunchNumber_m[i]);
956 auto writeRecords = [&](
const std::vector<double>& doubleData,
957 const std::vector<long long>& integerData, std::size_t count) {
958 for (std::size_t i = 0; i < count; ++i) {
959 os_m << doubleData[7 * i + 0] <<
" ";
960 os_m << doubleData[7 * i + 1] <<
" ";
961 os_m << doubleData[7 * i + 2] <<
" ";
962 os_m << doubleData[7 * i + 3] <<
" ";
963 os_m << doubleData[7 * i + 4] <<
" ";
964 os_m << doubleData[7 * i + 5] <<
" ";
965 os_m << integerData[nIntColumns * i + 0] <<
" ";
968 os_m << integerData[nIntColumns * i + 1] <<
" ";
969 os_m << integerData[nIntColumns * i + 2] <<
" ";
972 os_m << doubleData[7 * i + 6] << std::endl;
977 std::vector<double> localDoubleData = packDoubleData();
978 std::vector<long long> localIntegerData = packIntegerData();
980 writeRecords(localDoubleData, localIntegerData, nLoc);
982 for (
int src = 1; src <
size; ++src) {
983 unsigned long long remoteCount = 0;
986 &remoteCount, 1, MPI_UNSIGNED_LONG_LONG, src, tagCount, comm,
989 std::vector<double> remoteDoubleData(7 * remoteCount);
990 std::vector<long long> remoteIntegerData(nIntColumns * remoteCount);
992 if (remoteCount > 0) {
994 remoteDoubleData.data(),
static_cast<int>(remoteDoubleData.size()),
995 MPI_DOUBLE, src, tagDouble, comm, MPI_STATUS_IGNORE);
998 remoteIntegerData.data(),
static_cast<int>(remoteIntegerData.size()),
999 MPI_LONG_LONG, src, tagInt, comm, MPI_STATUS_IGNORE);
1002 writeRecords(remoteDoubleData, remoteIntegerData, remoteCount);
1005 const unsigned long long localCount =
static_cast<unsigned long long>(nLoc);
1007 MPI_Send(&localCount, 1, MPI_UNSIGNED_LONG_LONG, 0, tagCount, comm);
1009 if (localCount > 0) {
1010 std::vector<double> localDoubleData = packDoubleData();
1011 std::vector<long long> localIntegerData = packIntegerData();
1014 localDoubleData.data(),
static_cast<int>(localDoubleData.size()), MPI_DOUBLE, 0,
1018 localIntegerData.data(),
static_cast<int>(localIntegerData.size()),
1019 MPI_LONG_LONG, 0, tagInt, comm);
1023 ippl::Comm->barrier();
1053 size_t avgNumPerSet = nLoc / numSets;
1055 std::vector<size_t> numPartsInSet(numSets, avgNumPerSet);
1056 for (
unsigned int j = 0; j < (nLoc - numSets * avgNumPerSet); ++j) {
1062 std::vector<double> data(2 * numSets, 0.0);
1063 double* meanT = data.data();
1064 double* numParticles = data.data() + numSets;
1066 std::vector<double> timeRange(numSets, 0.0);
1068 for (
unsigned int iteration = 0; iteration < 2; ++iteration) {
1069 std::fill(data.begin(), data.end(), 0.0);
1070 std::fill(timeRange.begin(), timeRange.end(), 0.0);
1075 for (
unsigned int j = 0; j < numSets; ++j) {
1076 const size_t numThisSet = numPartsInSet[j];
1078 for (
size_t k = 0; k < numThisSet && partIdx < nLoc; ++k, ++partIdx) {
1080 maxT = std::max(maxT,
particles_m[partIdx].getTime());
1083 numParticles[j] =
static_cast<double>(numThisSet);
1086 ippl::Comm->allreduce(data.data(), 2 * numSets, std::plus<double>());
1088 for (
unsigned int j = 0; j < numSets; ++j) {
1089 if (numParticles[j] > 0.0) {
1090 meanT[j] /= numParticles[j];
1094 for (
unsigned int j = 0; j < numSets - 1; ++j) {
1095 timeRange[j] = 0.5 * (meanT[j] + meanT[j + 1]);
1097 timeRange[numSets - 1] = maxT;
1099 std::fill(numPartsInSet.begin(), numPartsInSet.end(), 0);
1102 size_t idxPrior = 0;
1104 for (
size_t idx = 0; idx < nLoc && setNum + 1 < numSets; ++idx) {
1105 if (
particles_m[idx].getTime() > timeRange[setNum]) {
1106 numPartsInSet[setNum] = idx - idxPrior;
1112 numPartsInSet[numSets - 1] = nLoc - idxPrior;
1115 for (
unsigned int i = 0; i < numSets; ++i) {
1135 const unsigned int totalSize = 50;
1137 double plainData[totalSize] = {};
1140 for (
unsigned int i = 0; i < 6; ++i) {
1141 rMinMax[i] = std::numeric_limits<double>::lowest();
1149 size_t startIdx = 0;
1157 data[0].
sum =
static_cast<double>(nLoc);
1159 size_t idx = startIdx;
1161 for (
size_t k = 0; k < nLoc; ++k, ++idx) {
1164 part[0] = particle.
getX();
1165 part[1] = particle.
getPx();
1166 part[2] = particle.
getY();
1167 part[3] = particle.
getPy();
1168 part[4] = particle.
getZ();
1169 part[5] = particle.
getPz();
1171 for (
int i = 0; i < 6; ++i) {
1172 localCentroid[i] += part[i];
1173 for (
int j = 0; j <= i; ++j) {
1174 localMoments[i * 6 + j] += part[i] * part[j];
1178 for (
unsigned int d = 0; d < 3; ++d) {
1179 const double r = part[2 * d];
1181 rMinMax[2 * d] = std::max(rMinMax[2 * d], -r);
1182 rMinMax[2 * d + 1] = std::max(rMinMax[2 * d + 1], r);
1185 const double time = particle.
getTime();
1190 localOthers[0] += time;
1191 localOthers[1] += time * time;
1193 localOthers[3] += particle.
getMass();
1194 localOthers[4] += eKin;
1195 localOthers[5] += eKin * eKin;
1196 localOthers[6] += gamma;
1199 for (
int i = 0; i < 6; ++i) {
1200 for (
int j = 0; j < i; ++j) {
1201 localMoments[j * 6 + i] = localMoments[i * 6 + j];
1205 for (
unsigned int i = 0; i < totalSize; ++i) {
1206 plainData[i] = data[i].
sum;
1209 ippl::Comm->allreduce(plainData, totalSize, std::plus<double>());
1210 ippl::Comm->allreduce(rMinMax, 6, std::greater<double>());
1212 if (plainData[0] == 0.0) {
1216 double* centroid = plainData + 1;
1217 double* moments = plainData + 7;
1218 double* others = plainData + 43;
1222 if (setIdx <
spos_m.size()) {
1238 stat.
nTotal_m =
static_cast<unsigned long>(std::round(plainData[0]));
1240 for (
unsigned int i = 0; i < 3u; ++i) {
1245 moments[(2 * i) * 6 + 2 * i] - stat.
nTotal_m * std::pow(stat.
rmean_m(i), 2);
1248 moments[(2 * i + 1) * 6 + 2 * i + 1] - stat.
nTotal_m * std::pow(stat.
pmean_m(i), 2);
1252 stat.
rpsum_m(i) = moments[(2 * i) * 6 + 2 * i + 1]
1266 size_t varianceIdx = startIdx;
1267 for (
size_t k = 0; k < nLoc; ++k, ++varianceIdx) {
1273 localKineticEnergyVariance += diff * diff;
1276 double kineticEnergyVariance[] = {
static_cast<double>(localKineticEnergyVariance.
sum)};
1278 ippl::Comm->allreduce(kineticEnergyVariance, 1, std::plus<double>());
1291 for (
unsigned int i = 0; i < 3u; ++i) {
1300 stat.
fac_m(i) = tmp == 0.0 ? 0.0 : 1.0 / tmp;
1302 stat.
rmin_m(i) = -rMinMax[2 * i];
1303 stat.
rmax_m(i) = rMinMax[2 * i + 1];
1305 std::max(std::abs(stat.
rmin_m(i)), std::abs(stat.
rmax_m(i)));
1310 computeSetPercentiles(
particles_m, startIdx, nLoc, stat);
ippl::Vector< T, Dim > Vector_t
void gsl_histogram_free(gsl_histogram *h)
Free a histogram allocated by gsl_histogram_alloc.
void gsl_histogram_increment(gsl_histogram *h, double x)
Increment the bin containing x by 1.
void gsl_histogram_set_ranges_uniform(gsl_histogram *h, double xmin, double xmax)
Set uniform bin edges over .
gsl_histogram * gsl_histogram_alloc(size_t n)
Allocate a 1D histogram with n bins.
double gsl_histogram_get(const gsl_histogram *h, size_t i)
Get the bin count for index i.
std::vector< Vector_t< double, 3 > > RefPartR_m
std::vector< size_t > turnNumber_m
h5_file_t H5file_m
used to write out data in H5hut mode
~LossDataSink() noexcept(false)
void setNumParticles(h5_int64_t num)
std::vector< double > refTime_m
void writeStepAttribFloat64(const char *attribute, const h5_float64_t *value, h5_int64_t size)
CollectionType collectionType_m
void addReferenceParticle(const Vector_t< double, 3 > &x, const Vector_t< double, 3 > &p, double time, double spos, long long globalTrackStep)
void save(unsigned int numSets=1, OpalData::OpenMode openMode=OpalData::OpenMode::UNDEFINED)
h5_int64_t H5call_m
Current record, or time step, of H5 file.
void openFile(const char *fname, h5_int32_t mode, h5_prop_t props)
void addParticle(const OpalParticle &, const std::optional< std::pair< int, short int > > &turnBunchNumPair=std::nullopt)
std::vector< size_t > bunchNumber_m
void writeStepAttribInt64(const char *attribute, const h5_int64_t *value, h5_int64_t size)
void writeFileAttribString(const char *attribute, const char *value)
std::vector< double > spos_m
void openH5(h5_int32_t mode=H5_O_WRONLY)
SetStatistics computeSetStatistics(unsigned int setIdx)
void splitSets(unsigned int numSets)
std::vector< OpalParticle > particles_m
bool hasTurnInformations() const
std::vector< Vector_t< double, 3 > > RefPartP_m
void writeDataFloat64(const char *name, const h5_float64_t *value)
void saveH5(unsigned int setIdx)
void writeDataInt64(const char *name, const h5_int64_t *value)
std::vector< h5_int64_t > globalTrackStep_m
bool hasNoParticlesToDump() const
std::vector< unsigned long > startSet_m
void checkAndAddOutputFileName(const std::string &outfn)
checks the output file names of all items to avoid duplicates
OpenMode getOpenMode() const
static OpalData * getInstance()
OpenMode
Enum for writing to files.
void setOpenMode(OpenMode openMode)
double getPy() const
Get vertical momentum (no dimension).
double getPz() const
Get relative momentum error (no dimension).
const Vector_t< double, 3 > & getP() const
Get momentum.
double getY() const
Get vertical displacement in m.
double getCharge() const
Get charge in Coulomb.
double getZ() const
Get longitudinal displacement c*t in m.
double getMass() const
Get mass in GeV/c^2.
double getTime() const
Get time.
int64_t getId() const
Get the id of the particle.
double getPx() const
Get horizontal momentum (no dimension).
double getX() const
Get horizontal position in m.
bool enableHDF5
If true HDF5 files are written.
double getGamma(ippl::Vector< double, 3 > p)
double getKineticEnergy(ippl::Vector< double, 3 > p, double mass)
std::string getGitRevision()
Vector_t< double, 3 > rprms_m
Vector_t< double, 3 > normalizedEps68Percentile_m
double stdKineticEnergy_m
Vector_t< double, 3 > eps2_m
Vector_t< double, 3 > rsqsum_m
Vector_t< double, 3 > maxR_m
Vector_t< double, 3 > RefPartR_m
Vector_t< double, 3 > RefPartP_m
Vector_t< double, 3 > rrms_m
Vector_t< double, 3 > ninetyNinePercentile_m
Vector_t< double, 3 > ninetyFivePercentile_m
Vector_t< double, 3 > eps_norm_m
Vector_t< double, 3 > ninetyNine_NinetyNinePercentile_m
Vector_t< double, 3 > geomEmit_m
Vector_t< double, 3 > rmax_m
Vector_t< double, 3 > prms_m
double meanKineticEnergy_m
Vector_t< double, 3 > sixtyEightPercentile_m
Vector_t< double, 3 > pmean_m
Vector_t< double, 3 > fac_m
Vector_t< double, 3 > normalizedEps95Percentile_m
Vector_t< double, 3 > psqsum_m
Vector_t< double, 3 > rpsum_m
Vector_t< double, 3 > normalizedEps99Percentile_m
Vector_t< double, 3 > normalizedEps99_99Percentile_m
Vector_t< double, 3 > rmin_m
Vector_t< double, 3 > rmean_m