Commit f24a1a3e authored by frey_m's avatar frey_m

PeakFinder: do not evaluate per particle

parent 5bc2faa5
......@@ -259,12 +259,11 @@ bool Probe::checkProbe(PartBunchBase<double, 3> *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);
}
......
......@@ -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<bool>());
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<double>());
reduce(fRegisered_m, globRegister, 1, std::plus<int>());
reduce(peakRadius_m, globPeakRadius, 1, std::plus<double>());
reduce(registered_m, globRegister, 1, std::plus<int>());
} 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));
}
}
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment