ReflectometryReductionOneAuto2Test.h 66.4 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10

#include <cxxtest/TestSuite.h>

11
#include "MantidReflectometry/ReflectometryReductionOneAuto2.h"
12
13

#include "MantidAPI/AnalysisDataService.h"
14
#include "MantidAPI/Axis.h"
15
#include "MantidAPI/FrameworkManager.h"
16
#include "MantidAPI/MatrixWorkspace.h"
17
#include "MantidAPI/Run.h"
18
#include "MantidAPI/WorkspaceGroup.h"
Samuel Jones's avatar
Samuel Jones committed
19
#include "MantidAlgorithms/GroupWorkspaces.h"
20
#include "MantidGeometry/Instrument.h"
21
#include "MantidTestHelpers/ReflectometryHelper.h"
22
23
#include "MantidTestHelpers/WorkspaceCreationHelper.h"

24
using namespace Mantid::Algorithms;
25
using namespace Mantid::API;
26
27
28
29
using namespace Mantid::DataHandling;
using namespace Mantid::DataObjects;
using namespace Mantid::HistogramData;
using namespace Mantid::Kernel;
30
using namespace Mantid::TestHelpers;
31
using namespace Mantid::Reflectometry;
32
using namespace WorkspaceCreationHelper;
33
34
35
36
37

class ReflectometryReductionOneAuto2Test : public CxxTest::TestSuite {
private:
  MatrixWorkspace_sptr m_notTOF;
  MatrixWorkspace_sptr m_TOF;
Roman Tolchenov's avatar
Roman Tolchenov committed
38
  AnalysisDataServiceImpl &ADS = AnalysisDataService::Instance();
39
40
41
42
43
44
45
46
47
48
49

  MatrixWorkspace_sptr loadRun(const std::string &run) {

    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
    lAlg->setChild(true);
    lAlg->initialize();
    lAlg->setProperty("Filename", run);
    lAlg->setPropertyValue("OutputWorkspace", "demo_ws");
    lAlg->execute();
    Workspace_sptr temp = lAlg->getProperty("OutputWorkspace");
    MatrixWorkspace_sptr matrixWS =
50
        std::dynamic_pointer_cast<MatrixWorkspace>(temp);
51
52
53
    if (matrixWS)
      return matrixWS;

54
    WorkspaceGroup_sptr group = std::dynamic_pointer_cast<WorkspaceGroup>(temp);
55
56
57
    if (group) {
      Workspace_sptr temp = group->getItem(0);
      MatrixWorkspace_sptr matrixWS =
58
          std::dynamic_pointer_cast<MatrixWorkspace>(temp);
59
60
61
62
63
64
65
      if (matrixWS)
        return matrixWS;
    }

    return MatrixWorkspace_sptr();
  };

Samuel Jones's avatar
Samuel Jones committed
66
67
68
  void momentumTransferHelper(ReflectometryReductionOneAuto2 &alg,
                              MatrixWorkspace_sptr &inter,
                              const double &theta) {
69
70
71
72
    alg.setChild(true);
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
73
    alg.setProperty("ProcessingInstructions", "4");
74
75
76
    alg.setProperty("Debug", false);
  }

77
public:
78
  void setUp() override {
Srikanth Ravipati's avatar
Srikanth Ravipati committed
79
80
    Mantid::Kernel::ConfigService::Instance().setString("default.facility",
                                                        "ISIS");
81
82
83
  }

  void tearDown() override {
Srikanth Ravipati's avatar
Srikanth Ravipati committed
84
    Mantid::Kernel::ConfigService::Instance().setString("default.facility",
85
                                                        " ");
86
87
  }

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static ReflectometryReductionOneAuto2Test *createSuite() {
    return new ReflectometryReductionOneAuto2Test();
  }
  static void destroySuite(ReflectometryReductionOneAuto2Test *suite) {
    delete suite;
  }

  ReflectometryReductionOneAuto2Test() {
    FrameworkManager::Instance();

    m_notTOF =
        WorkspaceCreationHelper::create2DWorkspaceWithRectangularInstrument(
            1, 10, 10);
    m_TOF = WorkspaceCreationHelper::
        create2DWorkspaceWithReflectometryInstrumentMultiDetector();
  }

  ~ReflectometryReductionOneAuto2Test() override {}

  void test_init() {
    ReflectometryReductionOneAuto2 alg;
    TS_ASSERT_THROWS_NOTHING(alg.initialize());
    TS_ASSERT(alg.isInitialized());
  }

  void test_bad_input_workspace_units() {
    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_notTOF);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
122
    alg.setProperty("ProcessingInstructions", "1");
123
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
124
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
125
126
127
128
129
130
131
132
133
134
135
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    TS_ASSERT_THROWS_ANYTHING(alg.execute());
  }

  void test_bad_wavelength_range() {
    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 15.0);
    alg.setProperty("WavelengthMax", 1.0);
136
    alg.setProperty("ProcessingInstructions", "1");
137
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
138
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
139
140
141
142
143
144
145
146
147
148
149
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    TS_ASSERT_THROWS_ANYTHING(alg.execute());
  }

  void test_bad_monitor_background_range() {
    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
150
    alg.setProperty("ProcessingInstructions", "1");
151
152
153
    alg.setProperty("MonitorBackgroundWavelengthMin", 3.0);
    alg.setProperty("MonitorBackgroundWavelengthMax", 0.5);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
154
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
155
156
157
158
159
160
161
162
163
164
165
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    TS_ASSERT_THROWS_ANYTHING(alg.execute());
  }

  void test_bad_monitor_integration_range() {
    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
166
    alg.setProperty("ProcessingInstructions", "1");
167
168
169
    alg.setProperty("MonitorIntegrationWavelengthMin", 15.0);
    alg.setProperty("MonitorIntegrationWavelengthMax", 1.5);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
170
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
171
172
173
174
175
176
177
178
179
180
181
182
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    TS_ASSERT_THROWS_ANYTHING(alg.execute());
  }

  void test_bad_first_transmission_run_units() {
    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("FirstTransmissionRun", m_notTOF);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
183
    alg.setProperty("ProcessingInstructions", "1");
184
185
186
    alg.setProperty("MonitorIntegrationWavelengthMin", 1.0);
    alg.setProperty("MonitorIntegrationWavelengthMax", 15.0);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
187
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    TS_ASSERT_THROWS_ANYTHING(alg.execute());
  }

  void test_bad_second_transmission_run_units() {
    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("FirstTransmissionRun", m_TOF);
    TS_ASSERT_THROWS_ANYTHING(
        alg.setProperty("SecondTransmissionRun", m_notTOF));
  }

  void test_bad_first_transmission_group_size() {
    MatrixWorkspace_sptr first = m_TOF->clone();
    MatrixWorkspace_sptr second = m_TOF->clone();
    MatrixWorkspace_sptr third = m_TOF->clone();
    MatrixWorkspace_sptr fourth = m_TOF->clone();

208
    WorkspaceGroup_sptr inputWSGroup = std::make_shared<WorkspaceGroup>();
209
210
    inputWSGroup->addWorkspace(first);
    inputWSGroup->addWorkspace(second);
211
    WorkspaceGroup_sptr transWSGroup = std::make_shared<WorkspaceGroup>();
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
    transWSGroup->addWorkspace(first);
    transWSGroup->addWorkspace(second);
    transWSGroup->addWorkspace(third);
    transWSGroup->addWorkspace(fourth);
    AnalysisDataService::Instance().addOrReplace("input", inputWSGroup);
    AnalysisDataService::Instance().addOrReplace("trans", transWSGroup);

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", "input");
    alg.setPropertyValue("FirstTransmissionRun", "trans");
    alg.setPropertyValue("PolarizationAnalysis", "None");
    auto results = alg.validateInputs();
    TS_ASSERT(results.count("FirstTransmissionRun"));

Raquel Alvarez's avatar
Raquel Alvarez committed
227
228
229
230
231
232
    AnalysisDataService::Instance().remove("input");
    AnalysisDataService::Instance().remove("input_1");
    AnalysisDataService::Instance().remove("input_2");
    AnalysisDataService::Instance().remove("trans");
    AnalysisDataService::Instance().remove("trans_3");
    AnalysisDataService::Instance().remove("trans_4");
233
234
235
236
237
238
239
240
  }

  void test_bad_second_transmission_group_size() {
    MatrixWorkspace_sptr first = m_TOF->clone();
    MatrixWorkspace_sptr second = m_TOF->clone();
    MatrixWorkspace_sptr third = m_TOF->clone();
    MatrixWorkspace_sptr fourth = m_TOF->clone();

241
    WorkspaceGroup_sptr inputWSGroup = std::make_shared<WorkspaceGroup>();
242
    inputWSGroup->addWorkspace(first);
243
    WorkspaceGroup_sptr firstWSGroup = std::make_shared<WorkspaceGroup>();
244
    firstWSGroup->addWorkspace(second);
245
    WorkspaceGroup_sptr secondWSGroup = std::make_shared<WorkspaceGroup>();
246
247
248
249
250
251
252
253
254
255
256
257
    secondWSGroup->addWorkspace(third);
    secondWSGroup->addWorkspace(fourth);
    AnalysisDataService::Instance().addOrReplace("input", inputWSGroup);
    AnalysisDataService::Instance().addOrReplace("first_trans", firstWSGroup);
    AnalysisDataService::Instance().addOrReplace("second_trans", secondWSGroup);

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", "input");
    alg.setPropertyValue("FirstTransmissionRun", "first_trans");
    alg.setPropertyValue("SecondTransmissionRun", "second_trans");
    alg.setPropertyValue("PolarizationAnalysis", "None");
258
    const auto results = alg.validateInputs();
259
260
261
    TS_ASSERT(!results.count("FirstTransmissionRun"));
    TS_ASSERT(results.count("SecondTransmissionRun"));

Raquel Alvarez's avatar
Raquel Alvarez committed
262
263
264
265
266
267
268
    AnalysisDataService::Instance().remove("input");
    AnalysisDataService::Instance().remove("input_1");
    AnalysisDataService::Instance().remove("first_trans");
    AnalysisDataService::Instance().remove("first_trans_1");
    AnalysisDataService::Instance().remove("second_trans");
    AnalysisDataService::Instance().remove("second_trans_1");
    AnalysisDataService::Instance().remove("second_trans_2");
269
270
271
272
  }

  void test_correct_detector_position_INTER() {
    auto inter = loadRun("INTER00013460.nxs");
273
    const double theta = 0.7;
274

275
    // Use the default correction type, which is a vertical shift
276
277
278
279
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setProperty("InputWorkspace", inter);
280
    alg.setProperty("ThetaIn", theta);
281
282
    alg.setProperty("CorrectionAlgorithm", "None");
    alg.setProperty("OutputWorkspace", "IvsQ");
283
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
284
    alg.setProperty("OutputWorkspaceWavelength", "IvsLam");
285
    alg.setProperty("ProcessingInstructions", "4");
286
    alg.execute();
287
    MatrixWorkspace_sptr out = alg.getProperty("OutputWorkspaceBinned");
288

289
290
291
292
293
294
295
296
    // Check default rebin params
    const double qStep = alg.getProperty("MomentumTransferStep");
    const double qMin = alg.getProperty("MomentumTransferMin");
    const double qMax = alg.getProperty("MomentumTransferMax");
    TS_ASSERT_DELTA(qStep, 0.034028, 1e-6);
    TS_ASSERT_DELTA(qMin, out->x(0).front(), 1e-6);
    TS_ASSERT_DELTA(qMax, out->x(0).back(), 1e-6);

297
298
299
300
301
302
303
304
305
306
307
308
309
310
    // Compare instrument components before and after
    auto instIn = inter->getInstrument();
    auto instOut = out->getInstrument();

    // The following components should not have been moved
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor1")->getPos(),
                     instOut->getComponentByName("monitor1")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor2")->getPos(),
                     instOut->getComponentByName("monitor2")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor3")->getPos(),
                     instOut->getComponentByName("monitor3")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("linear-detector")->getPos(),
                     instOut->getComponentByName("linear-detector")->getPos());

311
    // Only 'point-detector' should have been moved vertically (along Y)
312
313
314
315
316
317
318
319
320

    auto point1In = instIn->getComponentByName("point-detector")->getPos();
    auto point1Out = instOut->getComponentByName("point-detector")->getPos();

    TS_ASSERT_EQUALS(point1In.X(), point1Out.X());
    TS_ASSERT_EQUALS(point1In.Z(), point1Out.Z());
    TS_ASSERT_DIFFERS(point1In.Y(), point1Out.Y());
    TS_ASSERT_DELTA(point1Out.Y() /
                        (point1Out.Z() - instOut->getSample()->getPos().Z()),
321
                    std::tan(theta * 2 * M_PI / 180), 1e-4);
322
323
  }

324
  void test_correct_detector_position_rotation_POLREF() {
325
326
327
    // Histograms in this run correspond to 'OSMOND' component
    auto polref = loadRun("POLREF00014966.raw");

328
    // Correct by rotating detectors around the sample
329
330
331
332
333
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setProperty("InputWorkspace", polref);
    alg.setProperty("ThetaIn", 1.5);
334
    alg.setProperty("DetectorCorrectionType", "RotateAroundSample");
335
336
    alg.setProperty("AnalysisMode", "MultiDetectorAnalysis");
    alg.setProperty("CorrectionAlgorithm", "None");
337
    alg.setProperty("MomentumTransferStep", 0.01);
338
    alg.setProperty("OutputWorkspace", "IvsQ");
339
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
    alg.setProperty("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr out = alg.getProperty("OutputWorkspace");

    // Compare instrument components before and after
    auto instIn = polref->getInstrument();
    auto instOut = out->getInstrument();

    // The following components should not have been moved
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor1")->getPos(),
                     instOut->getComponentByName("monitor1")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor2")->getPos(),
                     instOut->getComponentByName("monitor2")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor3")->getPos(),
                     instOut->getComponentByName("monitor3")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("point-detector")->getPos(),
                     instOut->getComponentByName("point-detector")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("lineardetector")->getPos(),
                     instOut->getComponentByName("lineardetector")->getPos());

360
361
    // Only 'OSMOND' should have been moved both vertically and in the beam
    // direction (along X and Z)
362
363
364
365

    auto detectorIn = instIn->getComponentByName("OSMOND")->getPos();
    auto detectorOut = instOut->getComponentByName("OSMOND")->getPos();

366
    TS_ASSERT_DELTA(detectorOut.X(), 25.99589, 1e-5);
367
    TS_ASSERT_EQUALS(detectorIn.Y(), detectorOut.Y());
368
    TS_ASSERT_DELTA(detectorOut.Z(), 0.1570, 1e-5);
369
370
  }

371
  void test_correct_detector_position_vertical_CRISP() {
372
373
374
    // Histogram in this run corresponds to 'point-detector' component
    auto polref = loadRun("CSP79590.raw");

375
    // Correct by shifting detectors vertically
376
    // Also explicitly pass CorrectDetectors=1
377
378
379
380
381
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setProperty("InputWorkspace", polref);
    alg.setProperty("ThetaIn", 0.25);
382
    alg.setProperty("CorrectDetectors", "1");
383
    alg.setProperty("DetectorCorrectionType", "VerticalShift");
384
    alg.setProperty("CorrectionAlgorithm", "None");
385
    alg.setProperty("MomentumTransferStep", 0.01);
386
    alg.setProperty("OutputWorkspace", "IvsQ");
387
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
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
    alg.setProperty("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr out = alg.getProperty("OutputWorkspace");

    // Compare instrument components before and after
    auto instIn = polref->getInstrument();
    auto instOut = out->getInstrument();

    // The following components should not have been moved
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor1")->getPos(),
                     instOut->getComponentByName("monitor1")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor2")->getPos(),
                     instOut->getComponentByName("monitor2")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("linear-detector")->getPos(),
                     instOut->getComponentByName("linear-detector")->getPos());

    // Only 'point-detector' should have been moved vertically (along Y)

    auto detectorIn = instIn->getComponentByName("point-detector")->getPos();
    auto detectorOut = instOut->getComponentByName("point-detector")->getPos();

    TS_ASSERT_EQUALS(detectorIn.X(), detectorOut.X());
    TS_ASSERT_EQUALS(detectorIn.Z(), detectorOut.Z());
    TS_ASSERT_DELTA(detectorOut.Y() /
                        (detectorOut.Z() - instOut->getSample()->getPos().Z()),
                    std::tan(0.25 * 2 * M_PI / 180), 1e-4);
  }

416
417
418
419
420
421
422
423
424
  void test_correct_detector_position_from_logs() {
    auto inter = loadRun("INTER00013460.nxs");
    double theta = 0.7;

    // Use theta from the logs to correct detector positions
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setProperty("InputWorkspace", inter);
425
    alg.setProperty("ThetaLogName", "theta");
Gemma Guest's avatar
Gemma Guest committed
426
    alg.setProperty("CorrectDetectors", "1");
427
428
429
430
    alg.setProperty("CorrectionAlgorithm", "None");
    alg.setProperty("OutputWorkspace", "IvsQ");
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setProperty("OutputWorkspaceWavelength", "IvsLam");
431
    alg.setProperty("ProcessingInstructions", "4");
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
    alg.execute();
    MatrixWorkspace_sptr corrected = alg.getProperty("OutputWorkspace");

    // Compare instrument components before and after
    auto instIn = inter->getInstrument();
    auto instOut = corrected->getInstrument();

    // The following components should not have been moved
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor1")->getPos(),
                     instOut->getComponentByName("monitor1")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor2")->getPos(),
                     instOut->getComponentByName("monitor2")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("monitor3")->getPos(),
                     instOut->getComponentByName("monitor3")->getPos());
    TS_ASSERT_EQUALS(instIn->getComponentByName("linear-detector")->getPos(),
                     instOut->getComponentByName("linear-detector")->getPos());

449
    // Only 'point-detector' should have been moved
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
    // vertically (along Y)

    auto point1In = instIn->getComponentByName("point-detector")->getPos();
    auto point1Out = instOut->getComponentByName("point-detector")->getPos();

    TS_ASSERT_EQUALS(point1In.X(), point1Out.X());
    TS_ASSERT_EQUALS(point1In.Z(), point1Out.Z());
    TS_ASSERT_DIFFERS(point1In.Y(), point1Out.Y());
    TS_ASSERT_DELTA(point1Out.Y() /
                        (point1Out.Z() - instOut->getSample()->getPos().Z()),
                    std::tan(theta * 2 * M_PI / 180), 1e-4);
  }

  void test_override_ThetaIn_without_correcting_detectors() {
    auto inter = loadRun("INTER00013460.nxs");

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", 10.0);
Gemma Guest's avatar
Gemma Guest committed
471
    alg.setProperty("CorrectDetectors", "0");
472
473
474
475
    alg.setProperty("CorrectionAlgorithm", "None");
    alg.setProperty("OutputWorkspace", "IvsQ");
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setProperty("OutputWorkspaceWavelength", "IvsLam");
476
    alg.setProperty("ProcessingInstructions", "4");
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
    alg.execute();
    MatrixWorkspace_sptr corrected = alg.getProperty("OutputWorkspace");

    // Compare instrument components before and after
    auto instIn = inter->getInstrument();
    auto instOut = corrected->getInstrument();

    // the detectors should not have been moved

    auto point1In = instIn->getComponentByName("point-detector")->getPos();
    auto point1Out = instOut->getComponentByName("point-detector")->getPos();

    TS_ASSERT_EQUALS(point1In, point1Out);
  }

492
493
494
495
496
497
498
499
  void test_IvsQ_linear_binning() {

    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.5);
    alg.setProperty("WavelengthMax", 15.0);
500
    alg.setProperty("ProcessingInstructions", "2");
501
502
503
504
505
506
507
508
509
    alg.setProperty("MomentumTransferMin", 1.0);
    alg.setProperty("MomentumTransferMax", 10.0);
    alg.setProperty("MomentumTransferStep", -0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr outQbinned = alg.getProperty("OutputWorkspaceBinned");

510
511
512
513
514
515
516
517
    // Check the rebin params have not changed
    const double qStep = alg.getProperty("MomentumTransferStep");
    const double qMin = alg.getProperty("MomentumTransferMin");
    const double qMax = alg.getProperty("MomentumTransferMax");
    TS_ASSERT_EQUALS(qStep, -0.04);
    TS_ASSERT_EQUALS(qMin, 1.0);
    TS_ASSERT_EQUALS(qMax, 10.0);

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
    TS_ASSERT_EQUALS(outQbinned->getNumberHistograms(), 1);
    // blocksize = (10.0 - 1.0) / 0.04
    TS_ASSERT_EQUALS(outQbinned->blocksize(), 225);
    TS_ASSERT_DELTA(outQbinned->x(0)[1] - outQbinned->x(0)[0], 0.04, 1e-6);
    TS_ASSERT_DELTA(outQbinned->x(0)[2] - outQbinned->x(0)[1], 0.04, 1e-6);
  }

  void test_IvsQ_logarithmic_binning() {

    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.5);
    alg.setProperty("WavelengthMax", 15.0);
533
    alg.setProperty("ProcessingInstructions", "2");
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    alg.setProperty("MomentumTransferMin", 1.0);
    alg.setProperty("MomentumTransferMax", 10.0);
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr outQbinned = alg.getProperty("OutputWorkspaceBinned");

    TS_ASSERT_EQUALS(outQbinned->getNumberHistograms(), 1);
    TS_ASSERT_DIFFERS(outQbinned->blocksize(), 8);
    TS_ASSERT_DELTA(outQbinned->x(0)[1] - outQbinned->x(0)[0], 0.04, 1e-6);
    TS_ASSERT(outQbinned->x(0)[7] - outQbinned->x(0)[6] > 0.05);
  }

549
  void test_IvsLam_range() {
550
551
552
553
554
555
556

    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.5);
    alg.setProperty("WavelengthMax", 15.0);
557
    alg.setProperty("ProcessingInstructions", "3");
558
559
560
561
562
563
564
565
566
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr outQ = alg.getProperty("OutputWorkspace");
    MatrixWorkspace_sptr outLam = alg.getProperty("OutputWorkspaceWavelength");

    TS_ASSERT_EQUALS(outQ->getNumberHistograms(), 1);
567
    TS_ASSERT_EQUALS(outQ->binEdges(0).size(), 15);
568
    // X range in outLam
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
    TS_ASSERT_DELTA(outLam->binEdges(0)[0], 1.7924, 0.0001);
    TS_ASSERT_DELTA(outLam->binEdges(0)[1], 2.6886, 0.0001);
    TS_ASSERT_DELTA(outLam->binEdges(0)[7], 8.0658, 0.0001);
    TS_ASSERT_DELTA(outLam->binEdges(0)[13], 13.4431, 0.0001);
    TS_ASSERT_DELTA(outLam->binEdges(0)[14], 14.3393, 0.0001);
  }

  void test_IvsQ_range() {

    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.5);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("ProcessingInstructions", "3");
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr outQ = alg.getProperty("OutputWorkspace");
    MatrixWorkspace_sptr outLam = alg.getProperty("OutputWorkspaceWavelength");

    TS_ASSERT_EQUALS(outQ->getNumberHistograms(), 1);
    TS_ASSERT_EQUALS(outQ->binEdges(0).size(), 15);
    // X range in outLam
    TS_ASSERT_DELTA(outLam->binEdges(0)[0], 1.7924, 0.0001);
    TS_ASSERT_DELTA(outLam->binEdges(0)[7], 8.0658, 0.0001);
598
    // X range in outQ
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
    TS_ASSERT_DELTA(outQ->binEdges(0)[0], 0.3353, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[1], 0.3577, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[6], 0.5366, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[7], 0.5962, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[12], 1.3415, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[13], 1.7886, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[14], 2.6830, 0.0001);
  }

  void test_IvsQ_range_cropped() {

    ReflectometryReductionOneAuto2 alg;
    alg.setChild(true);
    alg.initialize();
    alg.setProperty("InputWorkspace", m_TOF);
    alg.setProperty("WavelengthMin", 1.5);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("MomentumTransferMin", 0.5);
    alg.setProperty("MomentumTransferMax", 1.5);
    alg.setProperty("ProcessingInstructions", "3");
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
    MatrixWorkspace_sptr outQ = alg.getProperty("OutputWorkspace");
    MatrixWorkspace_sptr outLam = alg.getProperty("OutputWorkspaceWavelength");

    TS_ASSERT_EQUALS(outQ->getNumberHistograms(), 1);
    // X range in outQ is cropped to momentum transfer limits
    TS_ASSERT_EQUALS(outQ->binEdges(0).size(), 7);
    TS_ASSERT_DELTA(outQ->binEdges(0)[0], 0.5366, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[1], 0.5962, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[5], 1.0732, 0.0001);
    TS_ASSERT_DELTA(outQ->binEdges(0)[6], 1.3414, 0.0001);
634
  }
635
636
637
638
639

  void test_optional_outputs() {
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

640
641
642
643
644
645
    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
646
    alg.setProperty("ProcessingInstructions", "4");
647
648
649
650
651
652
653
654
655
656
657
658
659
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned_13460"));
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_13460"));
    TS_ASSERT(!AnalysisDataService::Instance().doesExist("IvsLam_13460"));

    AnalysisDataService::Instance().clear();
  }

  void test_optional_outputs_binned() {
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

660
661
662
663
664
665
    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
666
    alg.setProperty("ProcessingInstructions", "4");
667
668
669
670
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned"));
671
672
673
    TS_ASSERT(!AnalysisDataService::Instance().doesExist("IvsQ_binned_13460"));
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_13460"));
    TS_ASSERT(!AnalysisDataService::Instance().doesExist("IvsLam_13460"));
674
675
676
677

    AnalysisDataService::Instance().clear();
  }

678
679
680
681
682
683
684
685
686
687
  void test_optional_outputs_set() {
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
688
    alg.setProperty("ProcessingInstructions", "4");
689
690
691
692
693
694
    alg.setProperty("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setProperty("OutputWorkspace", "IvsQ");
    alg.setProperty("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned"));
695
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ"));
696
    TS_ASSERT(!AnalysisDataService::Instance().doesExist("IvsLam"));
697
698
699
700

    AnalysisDataService::Instance().clear();
  }

701
  void test_default_outputs_debug() {
702
703
704
705
706
707
708
709
710
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
711
    alg.setProperty("ProcessingInstructions", "4");
712
713
714
715
716
717
718
719
720
721
    alg.setProperty("Debug", true);
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned_13460"));
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_13460"));
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsLam_13460"));

    AnalysisDataService::Instance().clear();
  }

722
723
724
725
726
727
728
729
730
731
  void test_default_outputs_no_debug() {
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
732
    alg.setProperty("ProcessingInstructions", "4");
733
734
735
736
    alg.setProperty("Debug", false);
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned_13460"));
737
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_13460"));
738
739
740
741
742
    TS_ASSERT(!AnalysisDataService::Instance().doesExist("IvsLam_13460"));

    AnalysisDataService::Instance().clear();
  }

743
744
745
746
747
748
749
750
751
752
753
  void test_default_outputs_no_run_number() {
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;
    inter->mutableRun().removeProperty("run_number");

    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
754
    alg.setProperty("ProcessingInstructions", "4");
755
756
757
758
759
760
761
762
763
    alg.setProperty("Debug", true);
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned"));
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ"));
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsLam"));

    AnalysisDataService::Instance().clear();
  }
764
765
766
767
768
769
770
771
772
773
774
775

  void test_default_outputs_no_run_number_no_debug() {
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;
    inter->mutableRun().removeProperty("run_number");

    // Use the default correction type, which is a vertical shift
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setProperty("InputWorkspace", inter);
    alg.setProperty("ThetaIn", theta);
    alg.setProperty("CorrectionAlgorithm", "None");
776
    alg.setProperty("ProcessingInstructions", "4");
777
778
779
780
    alg.setProperty("Debug", false);
    alg.execute();

    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_binned"));
781
    TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ"));
782
783
784
785
    TS_ASSERT(!AnalysisDataService::Instance().doesExist("IvsLam"));

    AnalysisDataService::Instance().clear();
  }
786

Roman Tolchenov's avatar
Roman Tolchenov committed
787
788
789
  void test_polarization_correction_PA() {
    std::string const name = "input";
    prepareInputGroup(name);
790
    applyPolarizationEfficiencies(name);
791

Roman Tolchenov's avatar
Roman Tolchenov committed
792
793
794
795
796
797
    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", name);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("ThetaIn", 10.0);
798
    alg.setProperty("ProcessingInstructions", "2");
Roman Tolchenov's avatar
Roman Tolchenov committed
799
800
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setProperty("PolarizationAnalysis", "PA");
801
802
803
804
    alg.setProperty("CPp", "0.9,0,0");
    alg.setProperty("CAp", "0.8,0,0");
    alg.setProperty("CRho", "0.7778,0,0");
    alg.setProperty("CAlpha", "0.75,0");
Roman Tolchenov's avatar
Roman Tolchenov committed
805
806
807
808
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
809

Roman Tolchenov's avatar
Roman Tolchenov committed
810
811
    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");
812

Roman Tolchenov's avatar
Roman Tolchenov committed
813
814
815
816
817
818
819
820
    TS_ASSERT_EQUALS(outQGroup.size(), 4);
    TS_ASSERT_EQUALS(outLamGroup.size(), 4);

    TS_ASSERT_EQUALS(outLamGroup[0]->blocksize(), 9);
    // X range in outLam
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).front(), 2.0729661466, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).back(), 14.2963182408, 0.0001);

821
822
823
824
    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.9, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[1]->y(0)[0], 0.8, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[2]->y(0)[0], 0.7, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[3]->y(0)[0], 0.6, 0.0001);
Roman Tolchenov's avatar
Roman Tolchenov committed
825
826
827

    TS_ASSERT_EQUALS(outQGroup[0]->blocksize(), 9);

828
829
830
831
    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 0.9, 0.0001);
    TS_ASSERT_DELTA(outQGroup[1]->y(0)[0], 0.8, 0.0001);
    TS_ASSERT_DELTA(outQGroup[2]->y(0)[0], 0.7, 0.0001);
    TS_ASSERT_DELTA(outQGroup[3]->y(0)[0], 0.6, 0.0001);
Roman Tolchenov's avatar
Roman Tolchenov committed
832
833
834
835
836
837
838

    ADS.clear();
  }

  void test_polarization_correction_PNR_wrong_input() {
    std::string const name = "input";
    prepareInputGroup(name);
839
840
841

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
Roman Tolchenov's avatar
Roman Tolchenov committed
842
    alg.setPropertyValue("InputWorkspace", name);
843
    alg.setProperty("WavelengthMin", 1.0);
844
    alg.setProperty("WavelengthMax", 15.0);
845
    alg.setProperty("ThetaIn", 10.0);
846
    alg.setProperty("ProcessingInstructions", "2");
847
    alg.setProperty("MomentumTransferStep", 0.04);
Roman Tolchenov's avatar
Roman Tolchenov committed
848
    alg.setProperty("PolarizationAnalysis", "PNR");
849
850
851
852
    alg.setProperty("CPp", "1,1,2");
    alg.setProperty("CAp", "1,1,2");
    alg.setProperty("CRho", "1,1");
    alg.setProperty("CAlpha", "1");
853
854
855
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
Roman Tolchenov's avatar
Roman Tolchenov committed
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
    TS_ASSERT_THROWS_EQUALS(
        alg.execute(), std::invalid_argument & e, std::string(e.what()),
        "For PNR analysis, input group must have 2 periods.");
  }

  void test_polarization_correction_PNR() {
    std::string const name = "input";
    prepareInputGroup(name, "", 2);

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", name);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("ThetaIn", 10.0);
871
    alg.setProperty("ProcessingInstructions", "2");
Roman Tolchenov's avatar
Roman Tolchenov committed
872
873
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setProperty("PolarizationAnalysis", "PNR");
874
875
    alg.setProperty("CPp", "1,1,2");
    alg.setProperty("CRho", "1,1");
Roman Tolchenov's avatar
Roman Tolchenov committed
876
877
878
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
879
880
    alg.execute();

Roman Tolchenov's avatar
Roman Tolchenov committed
881
882
883
884
885
886
887
    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");

    TS_ASSERT_EQUALS(outQGroup.size(), 2);
    TS_ASSERT_EQUALS(outLamGroup.size(), 2);

    TS_ASSERT_EQUALS(outLamGroup[0]->blocksize(), 9);
888
    // X range in outLam
Roman Tolchenov's avatar
Roman Tolchenov committed
889
890
891
892
893
894
895
896
897
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).front(), 2.0729661466, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).back(), 14.2963182408, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.8800698581, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[1]->y(0)[0], 0.8778429658, 0.0001);

    TS_ASSERT_EQUALS(outQGroup[0]->blocksize(), 9);
    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 0.8936134321, 0.0001);
    TS_ASSERT_DELTA(outQGroup[1]->y(0)[0], 0.8935802109, 0.0001);
898
899

    ADS.clear();
900
  }
901
902
903

  void test_polarization_correction_default() {

Roman Tolchenov's avatar
Roman Tolchenov committed
904
905
    std::string const name = "input";
    prepareInputGroup(name, "Fredrikze");
906
    applyPolarizationEfficiencies(name);
Roman Tolchenov's avatar
Roman Tolchenov committed
907
908
909
910

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", name);
911
    alg.setProperty("ThetaIn", 10.0);
Roman Tolchenov's avatar
Roman Tolchenov committed
912
913
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
914
    alg.setProperty("ProcessingInstructions", "2");
Roman Tolchenov's avatar
Roman Tolchenov committed
915
916
917
918
919
920
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setProperty("PolarizationAnalysis", "ParameterFile");
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();
921

Roman Tolchenov's avatar
Roman Tolchenov committed
922
923
    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");
924

Roman Tolchenov's avatar
Roman Tolchenov committed
925
926
927
928
929
    TS_ASSERT_EQUALS(outQGroup.size(), 4);
    TS_ASSERT_EQUALS(outLamGroup.size(), 4);

    TS_ASSERT_EQUALS(outLamGroup[0]->blocksize(), 9);
    // X range in outLam
930
931
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).front(), 2.0729661466, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).back(), 14.2963182408, 0.0001);
Roman Tolchenov's avatar
Roman Tolchenov committed
932

933
934
935
936
    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.9, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[1]->y(0)[0], 0.8, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[2]->y(0)[0], 0.7, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[3]->y(0)[0], 0.6, 0.0001);
Roman Tolchenov's avatar
Roman Tolchenov committed
937
938
939

    TS_ASSERT_EQUALS(outQGroup[0]->blocksize(), 9);

940
941
942
943
    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 0.9, 0.0001);
    TS_ASSERT_DELTA(outQGroup[1]->y(0)[0], 0.8, 0.0001);
    TS_ASSERT_DELTA(outQGroup[2]->y(0)[0], 0.7, 0.0001);
    TS_ASSERT_DELTA(outQGroup[3]->y(0)[0], 0.6, 0.0001);
Roman Tolchenov's avatar
Roman Tolchenov committed
944
945
946
947

    ADS.clear();
  }

Gemma Guest's avatar
Gemma Guest committed
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
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
  void test_input_workspace_group_with_default_output_workspaces() {
    ReflectometryReductionOneAuto2 alg;
    setup_alg_on_input_workspace_group_with_run_number(alg);
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    // Mandatory workspaces should exist
    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_1234"), true);
    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_binned_1234"), true);
    // IvsLam is currently always output for group workspaces
    TS_ASSERT_EQUALS(ADS.doesExist("IvsLam_1234"), true);

    auto outQGroup = retrieveOutWS("IvsQ_1234");
    auto outQGroupBinned = retrieveOutWS("IvsQ_binned_1234");
    TS_ASSERT_EQUALS(outQGroup.size(), 4);
    TS_ASSERT_EQUALS(outQGroupBinned.size(), 4);

    ADS.clear();
  }

  void
  test_input_workspace_group_with_default_output_workspaces_and_debug_on() {
    ReflectometryReductionOneAuto2 alg;
    setup_alg_on_input_workspace_group_with_run_number(alg);
    alg.setProperty("Debug", true);
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    // Mandatory workspaces should exist
    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_1234"), true);
    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_binned_1234"), true);
    TS_ASSERT_EQUALS(ADS.doesExist("IvsLam_1234"), true);

    auto outLamGroup = retrieveOutWS("IvsLam_1234");
    TS_ASSERT_EQUALS(outLamGroup.size(), 4);

    ADS.clear();
  }

  void test_input_workspace_group_with_named_output_workspaces() {
    ReflectometryReductionOneAuto2 alg;
    setup_alg_on_input_workspace_group_with_run_number(alg);
    alg.setPropertyValue("OutputWorkspace", "testIvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "testIvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "testIvsLam");
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    // Mandatory workspaces should exist
    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ"), true);
    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ_binned"), true);
    // IvsLam is currently always output for group workspaces
    TS_ASSERT_EQUALS(ADS.doesExist("testIvsLam"), true);

    auto outQGroup = retrieveOutWS("testIvsQ");
    auto outQGroupBinned = retrieveOutWS("testIvsQ_binned");
    TS_ASSERT_EQUALS(outQGroup.size(), 4);
    TS_ASSERT_EQUALS(outQGroupBinned.size(), 4);

    ADS.clear();
  }

  void test_input_workspace_group_with_named_output_workspaces_and_debug_on() {
    ReflectometryReductionOneAuto2 alg;
    setup_alg_on_input_workspace_group_with_run_number(alg);
    alg.setPropertyValue("OutputWorkspace", "testIvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "testIvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "testIvsLam");
    alg.setProperty("Debug", true);
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    // Mandatory workspaces should exist
    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ"), true);
    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ_binned"), true);
    TS_ASSERT_EQUALS(ADS.doesExist("testIvsLam"), true);

    auto outLamGroup = retrieveOutWS("testIvsLam");
    TS_ASSERT_EQUALS(outLamGroup.size(), 4);

    ADS.clear();
  }

Samuel Jones's avatar
Samuel Jones committed
1027
  void test_one_transmissionrun() {
Samuel Jones's avatar
Samuel Jones committed
1028
    const double startX = 1000;
Samuel Jones's avatar
Samuel Jones committed
1029
    const int nBins = 3;
Samuel Jones's avatar
Samuel Jones committed
1030
    const double deltaX = 1000;
Samuel Jones's avatar
Samuel Jones committed
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
    const std::vector<double> yValues1 = {1, 2, 3};
    const std::vector<double> yValues2 = {4, 5, 6};
    MatrixWorkspace_sptr input =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("input", input);

    MatrixWorkspace_sptr first =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("first", first);
    MatrixWorkspace_sptr second =
        createWorkspaceSingle(startX, nBins, deltaX, yValues2);
    ADS.addOrReplace("second", second);

    GroupWorkspaces mkGroup;
    mkGroup.initialize();
    mkGroup.setProperty("InputWorkspaces", "input");
    mkGroup.setProperty("OutputWorkspace", "inputWSGroup");
    mkGroup.execute();

    mkGroup.setProperty("InputWorkspaces", "first,second");
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
    mkGroup.setProperty("OutputWorkspace", "transWSGroup");
    mkGroup.execute();

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setPropertyValue("InputWorkspace", "inputWSGroup");
    alg.setProperty("WavelengthMin", 0.0000000001);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("ThetaIn", 10.0);
    alg.setProperty("ProcessingInstructions", "2");
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.setPropertyValue("FirstTransmissionRun", "transWSGroup");
Gemma Guest's avatar
Gemma Guest committed
1067
    alg.setProperty("Debug", true);
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");

    TS_ASSERT_DELTA(outQGroup[0]->x(0)[0], 2.8022, 0.0001);
    TS_ASSERT_DELTA(outQGroup[0]->x(0)[3], 11.2088, 0.0001);

    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 1.3484, 0.0001);
    TS_ASSERT_DELTA(outQGroup[0]->y(0)[2], 0.9207, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->x(0)[0], 0.1946, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0)[3], 0.7787, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.9207, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[2], 1.3484, 0.0001);

    ADS.clear();
  }

  void test_polarization_with_transmissionrun() {
    const double startX = 1000;
    const int nBins = 3;
    const double deltaX = 1000;
    const std::vector<double> yValues1 = {1, 2, 3};
    const std::vector<double> yValues2 = {4, 5, 6};
    MatrixWorkspace_sptr input =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("input", input);

    MatrixWorkspace_sptr input2 =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("input2", input2);

    MatrixWorkspace_sptr first =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("first", first);
    MatrixWorkspace_sptr second =
        createWorkspaceSingle(startX, nBins, deltaX, yValues2);
    ADS.addOrReplace("second", second);

    GroupWorkspaces mkGroup;
    mkGroup.initialize();
    mkGroup.setProperty("InputWorkspaces", "input,input2");
    mkGroup.setProperty("OutputWorkspace", "inputWSGroup");
    mkGroup.execute();

    mkGroup.setProperty("InputWorkspaces", "first,second");
    mkGroup.setProperty("OutputWorkspace", "transWSGroup");
    mkGroup.execute();

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setPropertyValue("InputWorkspace", "inputWSGroup");
    alg.setProperty("WavelengthMin", 0.0000000001);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("ThetaIn", 10.0);
    alg.setProperty("ProcessingInstructions", "2");
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setProperty("PolarizationAnalysis", "PNR");
1129
1130
    alg.setProperty("CPp", "1");
    alg.setProperty("CRho", "1");
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.setPropertyValue("FirstTransmissionRun", "transWSGroup");
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");

    TS_ASSERT_DELTA(outQGroup[0]->x(0)[0], 2.8022, 0.0001);
    TS_ASSERT_DELTA(outQGroup[0]->x(0)[3], 11.2088, 0.0001);

    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 1.3484, 0.0001);
    TS_ASSERT_DELTA(outQGroup[0]->y(0)[2], 0.9207, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->x(0)[0], 0.1946, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0)[3], 0.7787, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.9207, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[2], 1.3484, 0.0001);

    ADS.clear();
  }

  void test_second_transmissionrun() {
    const double startX = 1000;
    const int nBins = 3;
    const double deltaX = 1000;
    const std::vector<double> yValues1 = {1, 2, 3};
    const std::vector<double> yValues2 = {4, 5, 6};
    MatrixWorkspace_sptr input =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("input", input);

    MatrixWorkspace_sptr first =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("first", first);
    MatrixWorkspace_sptr second =
        createWorkspaceSingle(startX, nBins, deltaX, yValues2);
    ADS.addOrReplace("second", second);

    MatrixWorkspace_sptr first2 =
        createWorkspaceSingle(startX, nBins, deltaX, yValues1);
    ADS.addOrReplace("first2", first2);
    MatrixWorkspace_sptr second2 =
        createWorkspaceSingle(startX, nBins, deltaX, yValues2);
    ADS.addOrReplace("second2", second2);

    GroupWorkspaces mkGroup;
    mkGroup.initialize();
    mkGroup.setProperty("InputWorkspaces", "input");
    mkGroup.setProperty("OutputWorkspace", "inputWSGroup");
    mkGroup.execute();

    mkGroup.setProperty("InputWorkspaces", "first,second");
    mkGroup.setProperty("OutputWorkspace", "transWSGroup");
    mkGroup.execute();

    mkGroup.setProperty("InputWorkspaces", "first2,second2");
    mkGroup.setProperty("OutputWorkspace", "transWSGroup2");
    mkGroup.execute();

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setChild(true);
    alg.setPropertyValue("InputWorkspace", "inputWSGroup");
    alg.setProperty("WavelengthMin", 0.0000000001);
    alg.setProperty("WavelengthMax", 15.0);
    alg.setProperty("ThetaIn", 10.0);
    alg.setProperty("ProcessingInstructions", "2");
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.setPropertyValue("FirstTransmissionRun", "transWSGroup");
    alg.setPropertyValue("SecondTransmissionRun", "transWSGroup2");
Gemma Guest's avatar
Gemma Guest committed
1207
    alg.setProperty("Debug", true);
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
    TS_ASSERT_THROWS_NOTHING(alg.execute());

    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");

    TS_ASSERT_DELTA(outQGroup[0]->x(0)[0], 2.8022, 0.0001);
    TS_ASSERT_DELTA(outQGroup[0]->x(0)[3], 11.2088, 0.0001);

    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 1.3484, 0.0001);
    TS_ASSERT_DELTA(outQGroup[0]->y(0)[2], 0.9207, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->x(0)[0], 0.1946, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0)[3], 0.7787, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.9207, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[2], 1.3484, 0.0001);

    ADS.clear();
  }
Samuel Jones's avatar
Samuel Jones committed
1227

1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
  void test_polarization_correction_default_Wildes() {

    std::string const name = "input";
    prepareInputGroup(name, "Wildes");
    applyPolarizationEfficiencies(name);

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", name);
    alg.setProperty("ThetaIn", 10.0);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 15.0);
1240
    alg.setProperty("ProcessingInstructions", "2");
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setProperty("PolarizationAnalysis", "ParameterFile");
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
    alg.execute();

    auto outQGroup = retrieveOutWS("IvsQ");
    auto outLamGroup = retrieveOutWS("IvsLam");

    TS_ASSERT_EQUALS(outQGroup.size(), 4);
    TS_ASSERT_EQUALS(outLamGroup.size(), 4);

    TS_ASSERT_EQUALS(outLamGroup[0]->blocksize(), 9);
    // X range in outLam
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).front(), 2.0729661466, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[0]->x(0).back(), 14.2963182408, 0.0001);

    TS_ASSERT_DELTA(outLamGroup[0]->y(0)[0], 0.9368, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[1]->y(0)[0], 0.7813, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[2]->y(0)[0], 0.6797, 0.0001);
    TS_ASSERT_DELTA(outLamGroup[3]->y(0)[0], 0.5242, 0.0001);

    TS_ASSERT_EQUALS(outQGroup[0]->blocksize(), 9);

    TS_ASSERT_DELTA(outQGroup[0]->y(0)[0], 0.9368, 0.0001);
    TS_ASSERT_DELTA(outQGroup[1]->y(0)[0], 0.7813, 0.0001);
    TS_ASSERT_DELTA(outQGroup[2]->y(0)[0], 0.6797, 0.0001);
    TS_ASSERT_DELTA(outQGroup[3]->y(0)[0], 0.5242, 0.0001);

    ADS.clear();
  }

Roman Tolchenov's avatar
Roman Tolchenov committed
1274
1275
1276
  void test_monitor_index_in_group() {
    std::string const name = "input";
    prepareInputGroup(name);
1277
1278

    ReflectometryReductionOneAuto2 alg;
Roman Tolchenov's avatar
Roman Tolchenov committed
1279
    alg.setRethrows(true);
1280
    alg.initialize();
Roman Tolchenov's avatar
Roman Tolchenov committed
1281
    alg.setPropertyValue("InputWorkspace", name);
1282
1283
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 5.0);
1284
    alg.setProperty("ProcessingInstructions", "1");
1285
1286
1287
1288
1289
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setProperty("PolarizationAnalysis", "ParameterFile");
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
Samuel Jones's avatar
Samuel Jones committed
1290
1291
1292
1293
    TS_ASSERT_THROWS_EQUALS(alg.execute(), std::invalid_argument & e,
                            std::string(e.what()),
                            "A detector is expected at workspace index 0 (Was "
                            "converted from specnum), found a monitor");
Roman Tolchenov's avatar
Roman Tolchenov committed
1294
  }
1295

Roman Tolchenov's avatar
Roman Tolchenov committed
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
  void test_I0MonitorIndex_is_detector() {
    std::string const name = "input";
    prepareInputGroup(name);

    ReflectometryReductionOneAuto2 alg;
    alg.setRethrows(true);
    alg.initialize();
    alg.setPropertyValue("InputWorkspace", name);
    alg.setProperty("WavelengthMin", 1.0);
    alg.setProperty("WavelengthMax", 5.0);
1306
1307
    alg.setProperty("MonitorBackgroundWavelengthMin", 1.0);
    alg.setProperty("MonitorBackgroundWavelengthMax", 5.0);
Roman Tolchenov's avatar
Roman Tolchenov committed
1308
    alg.setPropertyValue("I0MonitorIndex", "1");
1309
    alg.setProperty("ProcessingInstructions", "2");
Roman Tolchenov's avatar
Roman Tolchenov committed
1310
1311
1312
1313
    alg.setProperty("MomentumTransferStep", 0.04);
    alg.setPropertyValue("OutputWorkspace", "IvsQ");
    alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
    alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
Roman Tolchenov's avatar
Roman Tolchenov committed
1314
1315
1316
    TS_ASSERT_THROWS_EQUALS(alg.execute(), std::invalid_argument & e,
                            std::string(e.what()),
                            "A monitor is expected at spectrum index 1");
1317
  }
1318

Samuel Jones's avatar
Samuel Jones committed
1319
  void test_QStep_QMin_and_QMax() {
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    momentumTransferHelper(alg, inter, theta);
    alg.setProperty("MomentumTransferStep", 0.1);
    alg.setProperty("MomentumTransferMin", 0.1);
    alg.setProperty("MomentumTransferMax", 1.0);
    alg.execute();

    MatrixWorkspace_sptr outQBin = alg.getProperty("OutputWorkspaceBinned");

Antti Soininen's avatar
Antti Soininen committed
1333
1334
    const auto &outX = outQBin->x(0);
    const auto &outY = outQBin->y(0);
1335

Samuel Jones's avatar
Samuel Jones committed
1336
1337
1338
1339
1340
1341
1342
1343
    TS_ASSERT_DELTA(outX[0], 0.1, 0.0001);
    TS_ASSERT_DELTA(outY[0], 0.0, 0.0001);

    TS_ASSERT_DELTA(outX[24], 1.0, 0.0001);
    TS_ASSERT_DELTA(outY[23], 0, 0.0001);

    TS_ASSERT_EQUALS(outX.size(), 25);
    TS_ASSERT_EQUALS(outY.size(), 24);
1344
1345
  }

Samuel Jones's avatar
Samuel Jones committed
1346
  void test_QMin_alone() {
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
    auto inter = loadRun("INTER00013460.nxs");
    const double theta = 0.7;

    ReflectometryReductionOneAuto2 alg;
    alg.initialize();
    momentumTransferHelper(alg, inter, theta);
    alg.setProperty("MomentumTransferMin", 0.1);
    alg.execute();

    MatrixWorkspace_sptr outQbinned = alg.getProperty("OutputWorkspaceBinned");

Antti Soininen's avatar
Antti Soininen committed
1358
1359
    const auto &outX = outQbinned->x(0);
    const auto &outY = outQbinned->y(0);
Samuel Jones's avatar
Samuel Jones committed
1360
1361
1362
1363
1364
1365
1366