Newer
Older
#ifndef MANTID_ALGORITHMS_STITCH1DMANYTEST_H_
#define MANTID_ALGORITHMS_STITCH1DMANYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/Axis.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidAPI/WorkspaceHistory.h"
#include "MantidAlgorithms/CreateWorkspace.h"
#include "MantidAlgorithms/GroupWorkspaces.h"
#include "MantidAlgorithms/Stitch1D.h"
#include "MantidAlgorithms/Stitch1DMany.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidHistogramData/Counts.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidHistogramData/Points.h"
#include "MantidKernel/UnitFactory.h"
#include <math.h>
using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Algorithms::Stitch1DMany;
using Mantid::Algorithms::CreateWorkspace;
using Mantid::Algorithms::GroupWorkspaces;
class Stitch1DManyTest : public CxxTest::TestSuite {
private:
/** Create a histogram workspace with two spectra and 10 bins. This can also
* be run using the CreateWorkspace algorithm which leaves the output workspace
* in the ADS as well.
* @param xstart :: the first X value (common to both spectra)
* @param deltax :: the bin width
* @param value1 :: the Y counts in the first spectrum (constant for all X)
* @param value2 :: the Y counts in the second spectrum (constant for all X)
* @param runAlg :: set true to run the CreateWorkspace algorithm
* @oaram outWSName :: output workspace name used if running CreateWorkspace
*/
MatrixWorkspace_sptr createUniformWorkspace(double xstart, double deltax,
double value1, double value2,
bool runAlg = false,
std::string outWSName = "") {
std::vector<double> xData1(nbins + 1);
std::vector<double> yData1(nbins);
std::vector<double> eData1(nbins);
std::vector<double> xData2(nbins + 1);
std::vector<double> yData2(nbins);
std::vector<double> eData2(nbins);
for (int i = 0; i < nbins; i++) {
// First spectrum
xData1[i] = xstart + i * deltax;
yData1[i] = value1;
eData1[i] = std::sqrt(value1);
xData2[i] = xstart + i * deltax;
yData2[i] = value2;
eData2[i] = std::sqrt(value2);
}
xData1[nbins] = xData1[nbins - 1] + deltax;
xData2[nbins] = xData2[nbins - 1] + deltax;
MatrixWorkspace_sptr ws;
if (!runAlg) {
ws = WorkspaceFactory::Instance().create("Workspace2D", 2, nbins + 1,
ws->dataX(0) = xData1;
ws->dataX(1) = xData2;
ws->dataY(0) = yData1;
ws->dataY(1) = yData2;
ws->dataE(0) = eData1;
ws->dataE(1) = eData2;
ws->getAxis(0)->unit() = UnitFactory::Instance().create("Wavelength");
// Concatenate data vectors into one vector
xData1.insert(xData1.end(), xData2.begin(), xData2.end());
yData1.insert(yData1.end(), yData2.begin(), yData2.end());
eData1.insert(eData1.end(), eData2.begin(), eData2.end());
CreateWorkspace cw;
cw.initialize();
cw.setProperty("DataX", xData1);
cw.setProperty("DataY", yData1);
cw.setProperty("DataE", eData1);
cw.setProperty("NSpec", 2);
cw.setProperty("UnitX", "Wavelength");
cw.setPropertyValue("OutputWorkspace", outWSName);
cw.execute();
ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
/** Groups workspaces using GroupWorkspaces algorithm. The output workpace is
* left in the ADS as well.
* @param inputWSNames :: input workspaces names
* @param outputWSName :: output workspace name
*/
WorkspaceGroup_sptr doGroupWorkspaces(std::string inputWSNames,
std::string outWSName) {
GroupWorkspaces gw;
gw.initialize();
gw.setProperty("InputWorkspaces", inputWSNames);
gw.setProperty("OutputWorkspace", outWSName);
gw.execute();
return AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
outWSName);
}
/** Obtain all algorithm histories from a workspace
* @param inputWS :: the input workspace
* @return vector of names of algorithm histories
*/
std::vector<std::string> getHistory(MatrixWorkspace_sptr inputWS) {
std::vector<std::string> histNames;
auto histories = inputWS->history().getAlgorithmHistories();
for (auto &hist : histories) {
histNames.push_back(hist->name());
}
return histNames;
}
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static Stitch1DManyTest *createSuite() { return new Stitch1DManyTest(); }
static void destroySuite(Stitch1DManyTest *suite) { delete suite; }
Stitch1DManyTest() {
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
}
void test_init() {
Stitch1DMany alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
}
void test_throws_with_too_few_workspaces() {
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1");
alg.setProperty("Params", "0.1, 0.1, 1.8");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_throws_with_wrong_number_of_start_overlaps() {
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2");
alg.setProperty("Params", "0.1");
alg.setProperty("StartOverlaps", "-0.5, -0.6");
alg.setProperty("EndOverlaps", "0.5");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_throws_with_wrong_number_of_end_overlaps() {
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2");
alg.setProperty("Params", "0.1");
alg.setProperty("StartOverlaps", "-0.5");
alg.setProperty("EndOverlaps", "0.5, 0.6");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
void test_throws_with_wrong_number_of_given_scale_factors() {
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2");
alg.setProperty("Params", "0.1");
alg.setProperty("UseManualScaleFactors", "1");
alg.setProperty("ManualScaleFactors", "0.5, 0.7");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_matrix_and_non_matrix_workspace_types_throws() {
// One matrix workspace, one table workspace
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = WorkspaceFactory::Instance().createTable();
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2");
alg.setProperty("Params", "0.1");
alg.setPropertyValue("OutputWorkspace", "outws");
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_group_and_non_group_workspace_types_throws() {
// One group workspace, one matrix workspace
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, ws1");
alg.setProperty("Params", "0.1");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_group_containing_non_matrix_workspace_types_throws() {
// One group workspace, one group workspace of non-matrix workspace types
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = WorkspaceFactory::Instance().createTable();
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws2);
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2");
alg.setProperty("Params", "0.1");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_workspace_group_size_differ_throws() {
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws3 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
group1->addWorkspace(ws2);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws3);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
void test_scale_factor_from_period_out_of_range_throws() {
// First group
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.1, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
group1->addWorkspace(ws2);
// Second group
auto ws3 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws4 = createUniformWorkspace(0.8, 0.1, 1.6, 2.6);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws3);
group2->addWorkspace(ws4);
// Third group
auto ws5 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
auto ws6 = createUniformWorkspace(1.6, 0.1, 1.6, 3.0);
WorkspaceGroup_sptr group3 = boost::make_shared<WorkspaceGroup>();
group3->addWorkspace(ws5);
group3->addWorkspace(ws6);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
AnalysisDataService::Instance().addOrReplace("group3", group3);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2, group3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setProperty("ScaleFactorFromPeriod", 4);
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
void test_two_workspaces() {
// Two matrix workspaces with two spectra each
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2");
alg.setProperty("Params", "0.1, 0.1, 1.8");
alg.setProperty("StartOverlaps", "0.8");
alg.setProperty("EndOverlaps", "1.1");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(outws);
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 17);
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 1.24316, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 1.79063, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 1);
// Only scale factor for first spectrum is returned
TS_ASSERT_DELTA(scales.front(), 0.90909, 0.00001);
// If scale factor for second spectrum was returned it should be 0.952381
// Cross-check that the result of using Stitch1DMany with two workspaces
// is the same as using Stitch1D
Mantid::Algorithms::Stitch1D alg2;
alg2.setChild(true);
alg2.initialize();
alg2.setProperty("LHSWorkspace", ws1);
alg2.setProperty("RHSWorkspace", ws2);
alg2.setProperty("Params", "0.1, 0.1, 1.8");
alg2.setProperty("StartOverlap", "0.8");
alg2.setProperty("EndOverlap", "1.1");
alg2.setPropertyValue("OutputWorkspace", "outws");
alg2.execute();
MatrixWorkspace_sptr stitched2 = alg2.getProperty("OutputWorkspace");
TS_ASSERT_EQUALS(stitched->x(0).rawData(), stitched2->x(0).rawData());
TS_ASSERT_EQUALS(stitched->y(0).rawData(), stitched2->y(0).rawData());
TS_ASSERT_EQUALS(stitched->e(0).rawData(), stitched2->e(0).rawData());
// Remove workspaces from ADS
AnalysisDataService::Instance().remove("ws1");
AnalysisDataService::Instance().remove("ws2");
}
void test_three_workspaces() {
// Three matrix workspaces with two spectra each
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws3 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
AnalysisDataService::Instance().addOrReplace("ws3", ws3);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2, ws3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setProperty("StartOverlaps", "0.8, 1.6");
alg.setProperty("EndOverlaps", "1.1, 1.8");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(outws);
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[24], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[24], 2, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.90865, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[24], 1.33144, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 1.33430, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[24], 2.00079, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
TS_ASSERT_DELTA(scales.front(), 0.9090, 0.0001);
TS_ASSERT_DELTA(scales.back(), 0.6666, 0.0001);
// Remove workspaces from ADS
AnalysisDataService::Instance().remove("ws1");
AnalysisDataService::Instance().remove("ws2");
AnalysisDataService::Instance().remove("ws3");
}
void test_stitches_three_no_overlaps_specified_should_still_work() {
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws3 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
AnalysisDataService::Instance().addOrReplace("ws3", ws3);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2, ws3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS_NOTHING(alg.execute());
void test_three_workspaces_single_scale_factor_given() {
// Three matrix workspaces with two spectra each
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws3 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
AnalysisDataService::Instance().addOrReplace("ws3", ws3);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2, ws3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setProperty("StartOverlaps", "0.8, 1.6");
alg.setProperty("EndOverlaps", "1.1, 1.8");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.setProperty("UseManualScaleFactors", "1");
alg.setProperty("ManualScaleFactors", "0.5");
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(outws);
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[10], 0.55000, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[18], 0.75000, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[10], 1.05000, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[18], 1.25000, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1.00000, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[10], 0.52440, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[18], 0.61237, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[10], 0.72457, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[18], 0.79057, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
TS_ASSERT_EQUALS(scales[0], 0.5);
TS_ASSERT_EQUALS(scales[1], 0.5);
// Remove workspaces from ADS
AnalysisDataService::Instance().remove("ws1");
AnalysisDataService::Instance().remove("ws2");
AnalysisDataService::Instance().remove("ws3");
}
void test_three_workspaces_multiple_scale_factors_given() {
// Three matrix workspaces with two spectra each
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws3 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("ws1", ws1);
AnalysisDataService::Instance().addOrReplace("ws2", ws2);
AnalysisDataService::Instance().addOrReplace("ws3", ws3);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2, ws3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setProperty("StartOverlaps", "0.8, 1.6");
alg.setProperty("EndOverlaps", "1.1, 1.8");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.setProperty("UseManualScaleFactors", "1");
alg.setProperty("ManualScaleFactors", "0.5, 0.7");
alg.execute();
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
auto stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(outws);
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[10], 0.55, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[18], 1.05, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[10], 1.05, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[18], 1.75, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[10], 0.5244, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[18], 0.85732, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[10], 0.72457, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[18], 1.1068, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
TS_ASSERT_EQUALS(scales[0], 0.5);
TS_ASSERT_EQUALS(scales[1], 0.7);
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
// Remove workspaces from ADS
AnalysisDataService::Instance().remove("ws1");
AnalysisDataService::Instance().remove("ws2");
AnalysisDataService::Instance().remove("ws3");
}
void test_one_group_two_workspaces() {
// One group with two workspaces
// Wrong: this algorithm can't stitch workspaces within a group
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
WorkspaceGroup_sptr group = boost::make_shared<WorkspaceGroup>();
group->addWorkspace(ws1);
group->addWorkspace(ws2);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1");
alg.setProperty("Params", "0.1");
alg.setProperty("StartOverlaps", "0.8");
alg.setProperty("EndOverlaps", "1.1");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
AnalysisDataService::Instance().clear();
}
void test_groups_with_single_workspace() {
// Three groups with a single matrix workspace each. Each matrix workspace
// has two spectra.
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws3 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws2);
WorkspaceGroup_sptr group3 = boost::make_shared<WorkspaceGroup>();
group3->addWorkspace(ws3);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
AnalysisDataService::Instance().addOrReplace("group3", group3);
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2, group3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setProperty("StartOverlaps", "0.8, 1.6");
alg.setProperty("EndOverlaps", "1.1, 1.8");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// The above is equivalent to what we've done in test_three_workspaces()
// so we should get the same values in the output workspace
// the only difference is that output will be a group
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(outws);
TS_ASSERT_EQUALS(group->getNumberOfEntries(), 1);
auto stitched =
boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(0));
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[24], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[24], 2, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.90865, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[24], 1.33144, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 1.33430, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[24], 2.00079, 0.00001);
// Test out scale factors
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
TS_ASSERT_DELTA(scales.front(), 0.9090, 0.0001);
TS_ASSERT_DELTA(scales.back(), 0.6666, 0.0001);
// Clear the ADS
AnalysisDataService::Instance().clear();
}
void test_two_groups_with_two_workspaces_each() {
// Two groups with two matrix workspaces each.
// Each matrix workspace has two spectra.
// First group
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.1, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
group1->addWorkspace(ws2);
// Second group
auto ws3 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws4 = createUniformWorkspace(0.8, 0.1, 1.6, 2.6);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws3);
group2->addWorkspace(ws4);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
// ws1 will be stitched with ws3
// ws2 will be stitched with ws4
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2");
alg.setProperty("Params", "0.1");
alg.setProperty("StartOverlaps", "0.8");
alg.setProperty("EndOverlaps", "1.1");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(outws);
TS_ASSERT_EQUALS(group->getNumberOfEntries(), 2);
// First item in the output group
auto stitched =
boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(0));
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 17);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 1.24316, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 1.79063, 0.00001);
// Second item in the output group
stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(1));
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 17);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1.22474, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.95883, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 1.54110, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.58114, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 1.24263, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 2.00959, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
TS_ASSERT_DELTA(scales.front(), 0.9090, 0.0001); // 1.0/1.1
TS_ASSERT_DELTA(scales.back(), 0.9375, 0.0001); // 1.5/1.6
AnalysisDataService::Instance().clear();
}
void test_two_groups_with_two_workspaces_single_scale_factor_given() {
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
// Two groups with two matrix workspaces each.
// Each matrix workspace has two spectra.
// First group
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.1, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
group1->addWorkspace(ws2);
// Second group
auto ws3 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws4 = createUniformWorkspace(0.8, 0.1, 1.6, 2.6);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws3);
group2->addWorkspace(ws4);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
// ws1 will be stitched with ws3
// ws2 will be stitched with ws4
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2");
alg.setProperty("Params", "0.1");
alg.setProperty("StartOverlaps", "0.8");
alg.setProperty("EndOverlaps", "1.1");
alg.setProperty("UseManualScaleFactors", "1");
alg.setProperty("ManualScaleFactors", "0.5");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// The above is equivalent to what we've done in test_three_workspaces()
// so we should get the same values in the output workspace
// the only difference is that output will be a group
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(outws);
TS_ASSERT_EQUALS(group->getNumberOfEntries(), 2);
// First item in the output group
auto stitched =
boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(0));
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 17);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 0.64705, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 0.55000, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 1.24752, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 1.05000, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.46442, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.52440, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 0.64485, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 0.72456, 0.00001);
// Second item in the output group
stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(1));
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 17);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 0.94736, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 0.8, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[0], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 1.54762, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 1.3, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[0], 1.22474, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.56195, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.63245, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[0], 1.58114, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 0.71824, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 0.80622, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
TS_ASSERT_DELTA(scales.front(), 0.5000, 0.0001);
TS_ASSERT_DELTA(scales.back(), 0.5000, 0.0001);
// Clear the ADS
AnalysisDataService::Instance().clear();
}
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
void test_two_groups_with_three_workspaces_multiple_scale_factors_given() {
// Three groups with two matrix workspaces each.
// Each matrix workspace has two spectra.
// First group
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.1, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
group1->addWorkspace(ws2);
// Second group
auto ws3 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws4 = createUniformWorkspace(0.8, 0.1, 1.6, 2.6);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws3);
group2->addWorkspace(ws4);
// Third group
auto ws5 = createUniformWorkspace(1.6, 0.1, 1.5, 2.5);
auto ws6 = createUniformWorkspace(1.6, 0.1, 1.6, 3.0);
WorkspaceGroup_sptr group3 = boost::make_shared<WorkspaceGroup>();
group3->addWorkspace(ws5);
group3->addWorkspace(ws6);
// The algorithm needs the workspaces to be in the ADS
AnalysisDataService::Instance().addOrReplace("group1", group1);
AnalysisDataService::Instance().addOrReplace("group2", group2);
AnalysisDataService::Instance().addOrReplace("group3", group3);
// ws1 will be stitched with ws3 and ws5
// ws2 will be stitched with ws4 and ws6
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "group1, group2, group3");
alg.setProperty("Params", "0.1, 0.1, 2.6");
alg.setProperty("StartOverlaps", "0.8, 1.6");
alg.setProperty("EndOverlaps", "1.1, 1.9");
alg.setProperty("UseManualScaleFactors", "1");
alg.setProperty("ManualScaleFactors", "0.5, 0.7");
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// Test output ws
Workspace_sptr outws = alg.getProperty("OutputWorkspace");
auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(outws);
TS_ASSERT_EQUALS(group->getNumberOfEntries(), 2);
// First item in the output group
auto stitched =
boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(0));
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 0.64706, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 0.68614, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[24], 1.05, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 1.24752, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 1.26, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[24], 1.75, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.46442, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.44735, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[24], 0.85732, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->e(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 0.64486, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 0.60622, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[24], 1.1068, 0.00001);
// Second item in the output group
stitched = boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(1));
TS_ASSERT_EQUALS(stitched->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(stitched->blocksize(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 0.94737, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 0.90811, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[24], 1.12, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->y(1)[0], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 1.54762, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 1.54528, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[24], 2.1, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->e(0)[0], 1.22474, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.56195, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.51465, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[24], 0.88544, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->e(1)[0], 1.58114, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[9], 0.71824, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[16], 0.67135, 0.00001);
TS_ASSERT_DELTA(stitched->e(1)[24], 1.21244, 0.00001);
// Test out scale factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 4);
TS_ASSERT_DELTA(scales[0], 0.5, 0.0001);
TS_ASSERT_DELTA(scales[1], 0.7, 0.0001);
TS_ASSERT_DELTA(scales[2], 0.5, 0.0001);
TS_ASSERT_DELTA(scales[3], 0.7, 0.0001);
// Clear the ADS
AnalysisDataService::Instance().clear();
}
void test_two_groups_with_three_workspaces_scale_factor_from_period() {
// Three groups with two matrix workspaces each.
// Each matrix workspace has two spectra.
// First group
auto ws1 = createUniformWorkspace(0.1, 0.1, 1., 2.);
auto ws2 = createUniformWorkspace(0.1, 0.1, 1.5, 2.5);
WorkspaceGroup_sptr group1 = boost::make_shared<WorkspaceGroup>();
group1->addWorkspace(ws1);
group1->addWorkspace(ws2);
// Second group
auto ws3 = createUniformWorkspace(0.8, 0.1, 1.1, 2.1);
auto ws4 = createUniformWorkspace(0.8, 0.1, 1.6, 2.6);
WorkspaceGroup_sptr group2 = boost::make_shared<WorkspaceGroup>();
group2->addWorkspace(ws3);
group2->addWorkspace(ws4);