diff --git a/src/Classic/AbsBeamline/Probe.cpp b/src/Classic/AbsBeamline/Probe.cpp index b3b1d7a68921c26e7785e9c9bf8a31f439eb888d..598db90a30a6ec22648e5352b48558eab8cf8e0b 100644 --- a/src/Classic/AbsBeamline/Probe.cpp +++ b/src/Classic/AbsBeamline/Probe.cpp @@ -259,12 +259,11 @@ bool Probe::checkProbe(PartBunchBase *bunch, const int turnnumber, co probepoint = bunch->R[i] + dist2 * 1000.0 * bunch->P[i] / euclidean_norm(bunch->P[i]); lossDs_m->addParticle(probepoint, bunch->P[i], bunch->ID[i], t+dt, turnnumber); - peakfinder_m->addParticle(probepoint, turnnumber); + peakfinder_m->addParticle(probepoint); flagprobed = true; } - - if ( bunch->getTotalNum() > 0) - peakfinder_m->evaluate(tempnum); + + peakfinder_m->evaluate(turnnumber); } diff --git a/src/Classic/Structure/PeakFinder.cpp b/src/Classic/Structure/PeakFinder.cpp index e37530f6ff1d25a7f9f9706f1302c06cad144053..e7be6f2f70515d9a27d801c4dd5ece4a2ff05d01 100644 --- a/src/Classic/Structure/PeakFinder.cpp +++ b/src/Classic/Structure/PeakFinder.cpp @@ -19,8 +19,6 @@ PeakFinder::PeakFinder(std::string elem, double min, , singlemode_m(singlemode) , first_m(true) , finished_m(false) - , fPeakRadius_m(0.0) - , fRegisered_m(0) { if (min_m > max_m) { std::swap(min_m, max_m); @@ -30,11 +28,18 @@ PeakFinder::PeakFinder(std::string elem, double min, } -void PeakFinder::addParticle(const Vector_t& R, const int& turn) { +void PeakFinder::addParticle(const Vector_t& R) { double radius = std::hypot(R(0),R(1)); radius_m.push_back(radius); + peakRadius_m += radius; + ++registered_m; +} + + +void PeakFinder::evaluate(const int& turn) { + if ( first_m ) { turn_m = turn; first_m = false; @@ -42,38 +47,24 @@ void PeakFinder::addParticle(const Vector_t& R, const int& turn) { if ( turn_m != turn ) { finished_m = true; - turn_m = turn; - fPeakRadius_m = peakRadius_m; - fRegisered_m = registered_m; - - peakRadius_m = 0.0; - registered_m = 0; } - peakRadius_m += radius; - ++registered_m; -} - - -void PeakFinder::evaluate(const unsigned int& localnum) { - bool globFinished = false; - // a core might have no particles, thus, never set finished_m = true - if ( localnum == 0 ) - finished_m = true; - if ( !singlemode_m ) allreduce(finished_m, globFinished, 1, std::logical_and()); else globFinished = finished_m; if ( globFinished ) { + this->computeCentroid_m(); + turn_m = turn; + // reset - fPeakRadius_m = 0.0; - fRegisered_m = 0; + peakRadius_m = 0.0; + registered_m = 0; finished_m = false; } } @@ -84,8 +75,6 @@ void PeakFinder::save() { createHistogram_m(); // last turn is not yet computed - fPeakRadius_m = peakRadius_m; - fRegisered_m = registered_m; this->computeCentroid_m(); if ( !peaks_m.empty() ) { @@ -118,15 +107,16 @@ void PeakFinder::computeCentroid_m() { //FIXME inefficient if ( !singlemode_m ) { - reduce(fPeakRadius_m, globPeakRadius, 1, std::plus()); - reduce(fRegisered_m, globRegister, 1, std::plus()); + reduce(peakRadius_m, globPeakRadius, 1, std::plus()); + reduce(registered_m, globRegister, 1, std::plus()); } else { - globPeakRadius = fPeakRadius_m; - globRegister = fRegisered_m; + globPeakRadius = peakRadius_m; + globRegister = registered_m; } if ( Ippl::myNode() == 0 ) { - peaks_m.push_back(globPeakRadius / double(globRegister)); + if ( globRegister > 0 ) + peaks_m.push_back(globPeakRadius / double(globRegister)); } } diff --git a/src/Classic/Structure/PeakFinder.h b/src/Classic/Structure/PeakFinder.h index 7098b1e0e8b358aef31eed7a121b9f796a20c1e5..a616cdb5a0c96799698ba48f33a2f0362b4075e2 100644 --- a/src/Classic/Structure/PeakFinder.h +++ b/src/Classic/Structure/PeakFinder.h @@ -37,12 +37,12 @@ public: * Append the particle coordinates to the container * @param R is a particle position (x, y, z) */ - void addParticle(const Vector_t& R, const int& turn); + void addParticle(const Vector_t& R); /*! * Evaluate the centroid of a turn. */ - void evaluate(const unsigned int& localnum); + void evaluate(const int& turn); void save(); @@ -101,8 +101,6 @@ private: bool first_m; bool finished_m; - double fPeakRadius_m; - int fRegisered_m; }; #endif