Skip to content

Commit

Permalink
refs #5626. Perform division.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jul 19, 2012
1 parent fe0e71e commit 1b2f900
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 9 additions & 3 deletions Code/Mantid/Framework/Algorithms/src/NormaliseByDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ namespace Mantid
const Geometry::ParameterMap& paramMap = inWS->instrumentParameters();

IAlgorithm_sptr cloneAlg = this->createSubAlgorithm("CloneWorkspace", 0.0, 1.0, true);
cloneAlg->setRethrows(true);
cloneAlg->setProperty("InputWorkspace", inWS);
cloneAlg->setPropertyValue("OutputWorkspace", "temp");
cloneAlg->executeAsSubAlg();
Workspace_sptr temp = cloneAlg->getProperty("OutputWorkspace");
MatrixWorkspace_sptr outputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);
MatrixWorkspace_sptr denominatorWS = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);

for(size_t wsIndex = 0; wsIndex < inWS->getNumberHistograms(); ++wsIndex)
{
Expand Down Expand Up @@ -162,9 +161,16 @@ namespace Mantid
{
outIntensity[i] = values[i];
}
outputWS->dataY(wsIndex) = outIntensity;
denominatorWS->dataY(wsIndex) = outIntensity;
}

// Perform the normalisation.
IAlgorithm_sptr divideAlg = this->createSubAlgorithm("Divide", 0.0, 1.0, true);
divideAlg->setRethrows(true);
divideAlg->setProperty("LHSWorkspace", inWS);
divideAlg->setProperty("RHSWorkspace", denominatorWS);
divideAlg->executeAsSubAlg();
MatrixWorkspace_sptr outputWS = divideAlg->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", outputWS);
}

Expand Down
12 changes: 8 additions & 4 deletions Code/Mantid/Framework/Algorithms/test/NormaliseByDetectorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class NormaliseByDetectorTest : public CxxTest::TestSuite
TSM_ASSERT_THROWS_NOTHING("Instrument wide, fitting function applied. Should not throw.", alg.execute());
}

void test_applies_instrument_function_to_child_detectors_calculates_correctly()
void test_workspace_with_instrument_only_fitting_functions()
{
const std::string outWSName = "normalised_ws";
// Linear function 2*x + 1 applied to each x-value. INSTRUMENT LEVEL FIT FUNCTION ONLY.
Expand All @@ -237,16 +237,18 @@ class NormaliseByDetectorTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(3, eValues.size());
TS_ASSERT_EQUALS(4, xValues.size());

const MantidVec& yInputValues = inputWS->readY(wsIndex);

for(size_t binIndex = 0; binIndex < (xValues.size() - 1); ++binIndex)
{
const double wavelength = (xValues[binIndex] + xValues[binIndex+1])/2;
const double expectedValue = (2*wavelength) + 1; // According to the equation written into the instrument parameter file for the instrument component link.
const double expectedValue = yInputValues[binIndex] / ( (2*wavelength) + 1 ); // According to the equation written into the instrument parameter file for the instrument component link.
TS_ASSERT_EQUALS(expectedValue, yValues[binIndex]);
}
}
}

void test_distribute_function_parameters_accross_object_hierachy()
void test_workspace_with_detector_level_only_fit_functions()
{
const std::string outWSName = "normalised_ws";
// Linear function 1*x + N applied to each x-value, where N is the workspace index. DETECTOR LEVEL FIT FUNCTIONS ONLY.
Expand All @@ -272,10 +274,12 @@ class NormaliseByDetectorTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(3, eValues.size());
TS_ASSERT_EQUALS(4, xValues.size());

const MantidVec& yInputValues = inputWS->readY(wsIndex);

for(size_t binIndex = 0; binIndex < (xValues.size() - 1); ++binIndex)
{
const double wavelength = (xValues[binIndex] + xValues[binIndex+1])/2;
const double expectedValue = (1*wavelength) + wsIndex; // According to the equation written into the instrument parameter file for the detector component link.
const double expectedValue = yInputValues[binIndex] / ( (1*wavelength) + wsIndex ); // According to the equation written into the instrument parameter file for the detector component link.
TS_ASSERT_EQUALS(expectedValue, yValues[binIndex]);
}
}
Expand Down

0 comments on commit 1b2f900

Please sign in to comment.