Skip to content

Commit

Permalink
Refs #9475 Manual Scale Factor and related tests
Browse files Browse the repository at this point in the history
Manual scale factor override is now implemented

Tests have been ported
  • Loading branch information
keithnbrown committed May 30, 2014
1 parent 396f2ed commit 080e655
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 18 deletions.
49 changes: 35 additions & 14 deletions Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
Expand Up @@ -116,6 +116,9 @@ namespace Mantid
"Scaling either with respect to workspace 1 or workspace 2");
declareProperty(new PropertyWithValue<bool>("UseManualScaleFactor", false, Direction::Input),
"True to use a provided value for the scale factor.");
declareProperty(
new PropertyWithValue<double>("ManualScaleFactor", 1.0, Direction::Input),
"Provided value for the scale factor. Optional.");
declareProperty(
new PropertyWithValue<double>("OutScaleFactor", Mantid::EMPTY_DBL(), Direction::Output),
"The actual used value for the scaling factor.");
Expand Down Expand Up @@ -361,26 +364,44 @@ namespace Mantid

bool scaleRHS = this->getProperty("ScaleRHSWorkspace");
//manualscalefactor if

auto rhsOverlapIntegrated = integration(rebinnedRHS, startOverlap, endOverlap);
auto lhsOverlapIntegrated = integration(rebinnedLHS, startOverlap, endOverlap);

auto y1 = lhsOverlapIntegrated->readY(0);
auto y2 = rhsOverlapIntegrated->readY(0);
bool manualScaleFactor = this->getProperty("UseManualScaleFactor");
double scaleFactor = 0;
if(scaleRHS)

if (manualScaleFactor)
{
MatrixWorkspace_sptr ratio = lhsOverlapIntegrated/rhsOverlapIntegrated;
rebinnedRHS = rebinnedRHS * ratio;
scaleFactor = y1[0]/y2[0];
double manualScaleFactor = this->getProperty("ManualScaleFactor");
MatrixWorkspace_sptr manualScaleFactorWS = singleValueWS(manualScaleFactor);

if(scaleRHS)
{
rebinnedRHS = rebinnedRHS * manualScaleFactorWS;
}
else
{
rebinnedLHS = rebinnedLHS * manualScaleFactorWS;
}
scaleFactor = manualScaleFactor;
}
else
{
MatrixWorkspace_sptr ratio = rhsOverlapIntegrated/lhsOverlapIntegrated;
rebinnedLHS = rebinnedLHS * ratio;
scaleFactor = y2[0]/y1[0];
}
auto rhsOverlapIntegrated = integration(rebinnedRHS, startOverlap, endOverlap);
auto lhsOverlapIntegrated = integration(rebinnedLHS, startOverlap, endOverlap);

auto y1 = lhsOverlapIntegrated->readY(0);
auto y2 = rhsOverlapIntegrated->readY(0);
if(scaleRHS)
{
MatrixWorkspace_sptr ratio = lhsOverlapIntegrated/rhsOverlapIntegrated;
rebinnedRHS = rebinnedRHS * ratio;
scaleFactor = y1[0]/y2[0];
}
else
{
MatrixWorkspace_sptr ratio = rhsOverlapIntegrated/lhsOverlapIntegrated;
rebinnedLHS = rebinnedLHS * ratio;
scaleFactor = y2[0]/y1[0];
}
}
//manualscalefactor end if

int a1 = boost::tuples::get<0>(startEnd);
Expand Down
86 changes: 82 additions & 4 deletions Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h
Expand Up @@ -172,6 +172,28 @@ class Stitch1DTest: public CxxTest::TestSuite
return ResultType(stitched, scaleFactor);
}

ResultType do_stitch1D(MatrixWorkspace_sptr& lhs, MatrixWorkspace_sptr& rhs, bool scaleRHS, bool useManualScaleFactor,
const double& startOverlap, const double& endOverlap, const MantidVec& params, const double& manualScaleFactor)
{
Stitch1D alg;
alg.setChild(true);
alg.setRethrows(true);
alg.initialize();
alg.setProperty("LHSWorkspace", lhs);
alg.setProperty("RHSWorkspace", rhs);
alg.setProperty("ScaleRHSWorkspace", scaleRHS);
alg.setProperty("UseManualScaleFactor", useManualScaleFactor);
alg.setProperty("StartOverlap", startOverlap);
alg.setProperty("EndOverlap", endOverlap);
alg.setProperty("Params", params);
alg.setProperty("ManualScaleFactor", manualScaleFactor);
alg.setPropertyValue("OutputWorkspace", "dummy_value");
alg.execute();
MatrixWorkspace_sptr stitched = alg.getProperty("OutputWorkspace");
double scaleFactor = alg.getProperty("OutScaleFactor");
return ResultType(stitched, scaleFactor);
}

ResultType do_stitch1D(MatrixWorkspace_sptr& lhs, MatrixWorkspace_sptr& rhs,
const double& startOverlap, const double& endOverlap, const MantidVec& params, bool scaleRHS = true)
{
Expand Down Expand Up @@ -365,8 +387,6 @@ class Stitch1DTest: public CxxTest::TestSuite

void test_stitching_scale_right()
{
std::cout << "test_stitching_scale_right" << std::endl;

auto ret = do_stitch1D(this->b, this->a, -0.4, 0.4,boost::assign::list_of<double>(0.2).convert_to_container<MantidVec>());

double scale = ret.get<1>();
Expand Down Expand Up @@ -397,8 +417,6 @@ class Stitch1DTest: public CxxTest::TestSuite

void test_stitching_scale_left()
{
std::cout << "test_stitching_scale_left" << std::endl;

auto ret = do_stitch1D(this->b, this->a, -0.4, 0.4,boost::assign::list_of<double>(0.2).convert_to_container<MantidVec>(),false);

double scale = ret.get<1>();
Expand Down Expand Up @@ -426,6 +444,66 @@ class Stitch1DTest: public CxxTest::TestSuite
std::transform(xCopy.begin(),xCopy.end(),xCopy.begin(),roundSix);
TS_ASSERT(xCopy == stitched_x);
}

void test_stitching_manual_scale_factor_scale_right()
{
auto ret = do_stitch1D(this->b, this->a, true, true, -0.4, 0.4,boost::assign::list_of<double>(0.2).convert_to_container<MantidVec>(),2.0/3.0);

double scale = ret.get<1>();
// Check the scale factor
TS_ASSERT_DELTA(scale, 2.0/3.0, 0.000000001);
// Fetch the arrays from the output workspace
MantidVec stitched_y = ret.get<0>()->readY(0);
MantidVec stitched_x = ret.get<0>()->readX(0);
MantidVec stitched_e = ret.get<0>()->readE(0);
// Check that the output Y-Values are correct. Output Y Values should all be 2
for (auto itr = stitched_y.begin(); itr != stitched_y.end(); ++itr)
{
TS_ASSERT_DELTA(2, *itr, 0.000001);
}
// Check that the output E-Values are correct. Output Error values should all be zero
for (auto itr = stitched_e.begin(); itr != stitched_e.end(); ++itr)
{
double temp = *itr;
TS_ASSERT_EQUALS(temp,0);
}
// Check that the output X-Values are correct.
//truncate the input and oputput x values to 6 decimal places to eliminate insignificant error
MantidVec xCopy = this->x;
std::transform(stitched_x.begin(),stitched_x.end(),stitched_x.begin(),roundSix);
std::transform(xCopy.begin(),xCopy.end(),xCopy.begin(),roundSix);
TS_ASSERT(xCopy == stitched_x);
}

void test_stitching_manual_scale_factor_scale_left()
{
auto ret = do_stitch1D(this->b, this->a, false, true, -0.4, 0.4, boost::assign::list_of<double>(0.2).convert_to_container<MantidVec>(), 3.0/2.0);

double scale = ret.get<1>();
// Check the scale factor
TS_ASSERT_DELTA(scale, 3.0/2.0, 0.000000001);
// Fetch the arrays from the output workspace
MantidVec stitched_y = ret.get<0>()->readY(0);
MantidVec stitched_x = ret.get<0>()->readX(0);
MantidVec stitched_e = ret.get<0>()->readE(0);
// Check that the output Y-Values are correct. Output Y Values should all be 3
for (auto itr = stitched_y.begin(); itr != stitched_y.end(); ++itr)
{
TS_ASSERT_DELTA(3, *itr, 0.000001);
}
// Check that the output E-Values are correct. Output Error values should all be zero
for (auto itr = stitched_e.begin(); itr != stitched_e.end(); ++itr)
{
double temp = *itr;
TS_ASSERT_EQUALS(temp,0);
}
// Check that the output X-Values are correct.
//truncate the input and oputput x values to 6 decimal places to eliminate insignificant error
MantidVec xCopy = this->x;
std::transform(stitched_x.begin(),stitched_x.end(),stitched_x.begin(),roundSix);
std::transform(xCopy.begin(),xCopy.end(),xCopy.begin(),roundSix);
TS_ASSERT(xCopy == stitched_x);
}
};

#endif /* MANTID_ALGORITHMS_STITCH1DTEST_H_ */

0 comments on commit 080e655

Please sign in to comment.