74 if (dt * R(2) < 0.0 &&
75 dt * (R(2) + singleStep(2)) > 0.0) {
77 double frac = -R(2) / singleStep(2);
80 R + frac * singleStep,
94 const double tau = -refR(2) / driftPerTimeStep(2);
100 Vector_t dS = (tau - 0.5) * cdt * beta;
101 particle.setR(refToLocalCSTrafo.
transformTo(particle.getR()) + dS);
116 if (dt * R(2) < 0.0 &&
117 dt * (R(2) + singleStep(2)) > 0.0) {
118 double frac = -R(2) / singleStep(2);
119 double time = t + frac * dt;
130 auto stats =
lossDs_m->computeStatistics(1);
131 if (!stats.empty()) {
155 double currentPosition = endField;
157 currentPosition = bunch->
get_sPos();
163 currentPosition < startField) {
165 namespace fs = std::filesystem;
167 fs::path lossFileName = fs::path(
filename_m +
".h5");
168 if (fs::exists(lossFileName)) {
171 fs::remove(lossFileName);
190 for (
auto &stat: stats) {
218 bool hasPriorTrack = instance->hasPriorTrack();
219 bool inRestartRun = instance->inRestartRun();
222 double spos = it->first;
228 writer.
addRow(entry.second);
Quaternion getQuaternion(Vector_t u, Vector_t ref)
T euclidean_norm(const Vector< T > &)
Euclidean norm.
constexpr double c
The velocity of light in m/s.
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
Vector_t getBeta(Vector_t p)
size_t getTotalNum() const
std::string getInputBasename()
get input file name without extension
OpenMode getOpenMode() const
static OpalData * getInstance()
OpenMode
Enum for writing to files.
virtual void visitMonitor(const Monitor &)=0
Apply the algorithm to a beam position monitor.
Component(const std::string &name)
Constructor with given name.
PartBunchBase< double, 3 > * RefPartBunch_m
bool update(const AttributeSet &)
Update element.
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
std::string getOutputFN() const
Get output filename.
CoordinateSystemTrafo csTrafoGlobal2Local_m
static void writeStatistics()
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Monitor.
virtual void goOnline(const double &kineticEnergy) override
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
@ OFF
Monitor is off (inactive).
virtual ElementType getType() const override
Get element type std::string.
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
virtual void goOffline() override
std::unique_ptr< LossDataSink > lossDs_m
virtual void getDimensions(double &zBegin, double &zEnd) const override
Monitor(const std::string &name)
Constructor with given name.
static std::map< double, SetStatistics > statFileEntries_sm
virtual void finalise() override
unsigned int numPassages_m
static const double halfLength_s
virtual bool bends() const override
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
void driftToCorrectPositionAndSave(const Vector_t &R, const Vector_t &P)
Vector_t transformTo(const Vector_t &r) const
Vector_t rotateTo(const Vector_t &r) const
void addRow(const SetStatistics &set)
static Communicate * Comm
Vektor< double, 3 > Vector_t