Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#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_*/