Skip to content

Commit

Permalink
Extract a reference to the Y/E data from the loop.
Browse files Browse the repository at this point in the history
Refs #12584
  • Loading branch information
martyngigg committed Jun 25, 2015
1 parent aa38947 commit 17453fe
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/Rebin2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ void Rebin2D::rebinToOutput(const Geometry::Quadrilateral &inputQ,
en_start, en_end))
return;

const auto & inY = inputWS->readY(i);
const auto & inE = inputWS->readE(i);
// It seems to be more efficient to construct this once and clear it before each calculation
// in the loop
ConvexPolygon intersectOverlap;
Expand All @@ -192,15 +194,15 @@ void Rebin2D::rebinToOutput(const Geometry::Quadrilateral &inputQ,
const V2D ul(X[ei], vhi);
const Quadrilateral outputQ(ll, lr, ur, ul);

double yValue = inputWS->readY(i)[j];
double yValue = inY[j];
if (boost::math::isnan(yValue)) {
continue;
}
intersectOverlap.clear();
if(intersection(outputQ, inputQ, intersectOverlap)) {
const double weight = intersectOverlap.area() / inputQ.area();
yValue *= weight;
double eValue = inputWS->readE(i)[j] * weight;
double eValue = inE[j] * weight;
if (inputWS->isDistribution()) {
const double overlapWidth = intersectOverlap.maxX() - intersectOverlap.minX();
yValue *= overlapWidth;
Expand Down Expand Up @@ -238,6 +240,8 @@ void Rebin2D::rebinToFractionalOutput(const Geometry::Quadrilateral &inputQ,
en_start, en_end))
return;

const auto & inY = inputWS->readY(i);
const auto & inE = inputWS->readE(i);
// Don't do the overlap removal if already RebinnedOutput.
// This wreaks havoc on the data.
const bool removeOverlap(inputWS->isDistribution() && inputWS->id() != "RebinnedOutput");
Expand All @@ -254,15 +258,15 @@ void Rebin2D::rebinToFractionalOutput(const Geometry::Quadrilateral &inputQ,
const V2D ul(X[ei], vhi);
const Quadrilateral outputQ(ll, lr, ur, ul);

double yValue = inputWS->readY(i)[j];
double yValue = inY[j];
if (boost::math::isnan(yValue)) {
continue;
}
intersectOverlap.clear();
if(intersection(outputQ, inputQ, intersectOverlap)) {
const double weight = intersectOverlap.area() / inputQ.area();
yValue *= weight;
double eValue = inputWS->readE(i)[j] * weight;
double eValue = inE[j] * weight;
if (removeOverlap) {
const double overlapWidth = intersectOverlap.maxX() - intersectOverlap.minX();
yValue *= overlapWidth;
Expand Down

0 comments on commit 17453fe

Please sign in to comment.