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 "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();
WorkspaceGroup_sptr ws =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(outWSName);
return ws;
}
/** 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 = WorkspaceFactory::Instance().createTable();
auto ws2 = WorkspaceFactory::Instance().createTable();
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_workspace_types_differ_throws() {
// One table workspace, one matrix 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");
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);
}
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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());
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// 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");
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)[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);
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
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");
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);
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
// 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);
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
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() {
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
// 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();
}
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
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));
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();
}
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
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);
// 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("ScaleFactorFromPeriod", 2);
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// By keeping ManualScaleFactors empty (default value) it allows workspaces
// in other periods to be scaled by scale factors from a specific period.
// Periods 0 and 2 workspaces will be scaled by scale factors from period 1.
// 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(), 25);
// First spectrum, Y values
TS_ASSERT_DELTA(stitched->y(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[9], 1.01589, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[16], 0.97288, 0.00001);
TS_ASSERT_DELTA(stitched->y(0)[24], 0.9375, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->y(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[9], 1.98375, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[16], 1.70307, 0.00001);
TS_ASSERT_DELTA(stitched->y(1)[24], 1.56250, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->e(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[9], 0.70111, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[16], 0.60401, 0.00001);
TS_ASSERT_DELTA(stitched->e(0)[24], 0.76547, 0.00001);