Newer
Older
#ifndef MANTID_ALGORITHMS_STITCH1DMANYTEST_H_
#define MANTID_ALGORITHMS_STITCH1DMANYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAlgorithms/Stitch1D.h"
#include "MantidAlgorithms/Stitch1DMany.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/Axis.h"
#include "MantidAPI/ITableWorkspace.h"
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
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidKernel/UnitFactory.h"
#include <math.h>
using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Algorithms::Stitch1DMany;
class Stitch1DManyTest : public CxxTest::TestSuite {
private:
/** Create a histogram workspace with two spectra and 10 bins
* @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)
*/
MatrixWorkspace_sptr createUniformWorkspace(double xstart, double deltax,
double value1, double value2) {
const int nbins = 10;
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);
// Second spectrum
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 =
WorkspaceFactory::Instance().create("Workspace2D", 2, nbins + 1, nbins);
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");
return ws;
}
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; }
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.setProperty("StartOverlaps", "0.8");
alg.setProperty("EndOverlaps", "1.1");
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_if_no_params() {
Stitch1DMany alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("InputWorkspaces", "ws1, ws2");
alg.setProperty("StartOverlaps", "-0.5, -0.6");
alg.setProperty("EndOverlaps", "0.5, 0.6");
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().add("ws1", ws1);
AnalysisDataService::Instance().add("ws2", ws2);
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, 0.6");
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.setProperty("StartOverlaps", "0.8, 1.6");
alg.setProperty("EndOverlaps", "1.1, 1.8");
alg.setPropertyValue("OutputWorkspace", "outws");
TS_ASSERT_THROWS(alg.execute(), std::runtime_error);
}
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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->readY(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 1.24316, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[16], 1.79063, 0.00001);
// Test out sclae 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->readX(0), stitched2->readX(0));
TS_ASSERT_EQUALS(stitched->readY(0), stitched2->readY(0));
TS_ASSERT_EQUALS(stitched->readE(0), stitched2->readE(0));
227
228
229
230
231
232
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// 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->readY(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[24], 1, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[24], 2, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 0.90865, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[24], 1.33144, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[16], 1.33430, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[24], 2.00079, 0.00001);
// Test out sclae 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());
}
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
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
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
549
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
591
592
593
594
595
596
597
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
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
void test_three_workspaces_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("UseManualScaleFactor", "1");
alg.setProperty("ManualScaleFactor", 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->readY(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[10], 0.55000, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[18], 0.75000, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[10], 1.05000, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[18], 1.25000, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1.00000, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[10], 0.52440, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[18], 0.61237, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[10], 0.72457, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[18], 0.79057, 0.00001);
// Test out sclae factors
std::vector<double> scales = alg.getProperty("OutScaleFactors");
TS_ASSERT_EQUALS(scales.size(), 2);
TS_ASSERT_EQUALS(scales.front(), 0.5);
TS_ASSERT_EQUALS(scales.back(), 0.5);
// 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");
auto results = alg.validateInputs();
TS_ASSERT_EQUALS(results["InputWorkspaces"],
"At least 2 input workspaces required.")
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->readY(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[24], 1, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[24], 2, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 0.90865, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[24], 1.33144, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[16], 1.33430, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[24], 2.00079, 0.00001);
// Test out sclae 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);
// 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->readY(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 1, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 2, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.77919, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 1.24316, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 1.10982, 0.00001);
TS_ASSERT_DELTA(stitched->readE(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->readY(0)[0], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 1.5, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 2.5, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1.22474, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.95883, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 1.54110, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.58114, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 1.24263, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[16], 2.00959, 0.00001);
// Test out sclae 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
// Clear the ADS
AnalysisDataService::Instance().clear();
}
void test_two_groups_with_two_workspaces_scale_factor_given() {
// 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("UseManualScaleFactor", "1");
alg.setProperty("ManualScaleFactor", 0.5);
alg.setPropertyValue("OutputWorkspace", "outws");
alg.execute();
// The above is equivalent to what we've don 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->readY(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 0.64705, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 0.55000, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 1.24752, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 1.05000, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.46442, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 0.52440, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.41421, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 0.64485, 0.00001);
TS_ASSERT_DELTA(stitched->readE(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->readY(0)[0], 1.5, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[9], 0.94736, 0.00001);
TS_ASSERT_DELTA(stitched->readY(0)[16], 0.8, 0.00001);
// Second spectrum, Y values
TS_ASSERT_DELTA(stitched->readY(1)[0], 2.5, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[9], 1.54762, 0.00001);
TS_ASSERT_DELTA(stitched->readY(1)[16], 1.3, 0.00001);
// First spectrum, E values
TS_ASSERT_DELTA(stitched->readE(0)[0], 1.22474, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[9], 0.56195, 0.00001);
TS_ASSERT_DELTA(stitched->readE(0)[16], 0.63245, 0.00001);
// Second spectrum, E values
TS_ASSERT_DELTA(stitched->readE(1)[0], 1.58114, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[9], 0.71824, 0.00001);
TS_ASSERT_DELTA(stitched->readE(1)[16], 0.80622, 0.00001);
// Test out sclae 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();
}
};
#endif /* MANTID_ALGORITHMS_STITCH1DMANYTEST_H_ */