Skip to content
Snippets Groups Projects
Commit f3f5afce authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #8761 add test to check convolution results

parent b5adcb44
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,8 @@ set ( SRC_FILES ...@@ -17,8 +17,8 @@ set ( SRC_FILES
src/ComptonProfile.cpp src/ComptonProfile.cpp
src/ComptonScatteringCountRate.cpp src/ComptonScatteringCountRate.cpp
src/ConvertToYSpace.cpp src/ConvertToYSpace.cpp
src/ConvolveWorkspaces.cpp
src/Convolution.cpp src/Convolution.cpp
src/ConvolveWorkspaces.cpp
src/CostFuncFitting.cpp src/CostFuncFitting.cpp
src/CostFuncLeastSquares.cpp src/CostFuncLeastSquares.cpp
src/CostFuncRwp.cpp src/CostFuncRwp.cpp
...@@ -220,6 +220,7 @@ set ( TEST_FILES ...@@ -220,6 +220,7 @@ set ( TEST_FILES
ComptonScatteringCountRateTest.h ComptonScatteringCountRateTest.h
ConvertToYSpaceTest.h ConvertToYSpaceTest.h
ConvolutionTest.h ConvolutionTest.h
ConvolveWorkspacesTest.h
CubicSplineTest.h CubicSplineTest.h
DampingMinimizerTest.h DampingMinimizerTest.h
DeltaFunctionTest.h DeltaFunctionTest.h
......
...@@ -65,21 +65,14 @@ void ConvolveWorkspaces::exec() ...@@ -65,21 +65,14 @@ void ConvolveWorkspaces::exec()
// Cache a few things for later use // Cache a few things for later use
const size_t numHists = ws1->getNumberHistograms(); const size_t numHists = ws1->getNumberHistograms();
const size_t numBins = ws1->blocksize(); const size_t numBins = ws1->blocksize();
const bool histogram = ws1->isHistogramData();
Workspace2D_sptr outputWS = boost::dynamic_pointer_cast<Workspace2D>(WorkspaceFactory::Instance().create("Workspace2D",numHists,numBins,numBins-1)); Workspace2D_sptr outputWS = boost::dynamic_pointer_cast<Workspace2D>(WorkspaceFactory::Instance().create("Workspace2D",numHists,numBins,numBins-1));
WorkspaceFactory::Instance().initializeFromParent(ws1, outputWS, true); WorkspaceFactory::Instance().initializeFromParent(ws1, outputWS, true);
// First check that the workspace are the same size // First check that the workspace are the same size
if ( numHists != ws2->getNumberHistograms() || numBins != ws2->blocksize() ) if ( numHists != ws2->getNumberHistograms() )
{ {
throw std::runtime_error("Size mismatch"); throw std::runtime_error("Size mismatch");
} }
// Check that both are either histograms or point-like data
if ( histogram != ws2->isHistogramData() )
{
throw std::runtime_error("Histogram/point-like mismatch");
}
prog = new Progress(this, 0.0, 1.0, numHists); prog = new Progress(this, 0.0, 1.0, numHists);
// Now check the data itself // Now check the data itself
...@@ -111,7 +104,7 @@ void ConvolveWorkspaces::exec() ...@@ -111,7 +104,7 @@ void ConvolveWorkspaces::exec()
for(size_t i=0;i<N;i++) for(size_t i=0;i<N;i++)
{ {
Yout[i] = out.getCalculated(i) * static_cast<double>(N); Yout[i] = out.getCalculated(i);
} }
PARALLEL_END_INTERUPT_REGION PARALLEL_END_INTERUPT_REGION
......
#ifndef ConvolveWorkspacesTEST_H_
#define ConvolveWorkspacesTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidCurveFitting/ConvolveWorkspaces.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/IPeakFunction.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/FakeObjects.h"
#include "MantidCurveFitting/Gaussian.h"
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::CurveFitting;
class ConvolveWorkspacesTest : public CxxTest::TestSuite
{
public:
//Functor to generate spline values
struct SplineFunc1
{
double operator()(double x, int)
{
double sig = 0.1;
return exp(-pow(x,2)/(2*pow(sig,2)))/(sqrt(2*M_PI)*sig);
}
};
//Functor to generate spline values
struct SplineFunc2
{
double operator()(double x, int)
{
double sig = sqrt(0.1*0.1+0.1*0.1);
return exp(-pow(x,2)/(2*pow(sig,2)))/(sqrt(2*M_PI)*sig);
}
};
void testFunction()
{
ConvolveWorkspaces alg;
//Convolution of normalized Gaussians should have sigma = sqrt(sig1^2+sig2^2)
MatrixWorkspace_sptr ws1 = WorkspaceCreationHelper::Create2DWorkspaceFromFunction(SplineFunc1(), 1, -2.0, 2.0, 0.01, false);
MatrixWorkspace_sptr ws2 = WorkspaceCreationHelper::Create2DWorkspaceFromFunction(SplineFunc2(), 1, -2.0, 2.0, 0.01, false);
alg.initialize();
alg.isInitialized();
alg.setChild(true);
alg.setPropertyValue("OutputWorkspace", "Conv");
alg.setProperty("Workspace1", ws1);
alg.setProperty("Workspace2", ws1);
TS_ASSERT_THROWS_NOTHING( alg.execute() );
TS_ASSERT( alg.isExecuted() );
Workspace2D_const_sptr ows = alg.getProperty("OutputWorkspace");
for (size_t i = 0; i < ows->getNumberHistograms(); ++i)
{
const auto & xs2 = ws2->readX(i);
const auto & xs = ows->readX(i);
const auto & ys2 = ws2->readY(i);
const auto & ys = ows->readY(i);
//check output for consistency
for(size_t j = 0; j < ys.size(); ++j)
{
TS_ASSERT_DELTA(xs[j], xs2[j], 1e-15);
TS_ASSERT_DELTA(ys[j], ys2[j], 1e-8);
}
}
}
};
#endif /*ConvolveWorkspacesTEST_H_*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment