LoadILLSANSTest.h 23.1 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 "MantidAPI/AnalysisDataService.h"
LamarMoore's avatar
LamarMoore committed
12
#include "MantidAPI/Axis.h"
13
#include "MantidAPI/MatrixWorkspace.h"
14
#include "MantidDataHandling/LoadILLSANS.h"
15
16
17
18
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/ConfigService.h"
19
#include "MantidKernel/Unit.h"
20
#include "MantidTypes/Core/DateAndTimeHelpers.h"
21

LamarMoore's avatar
LamarMoore committed
22
using Mantid::API::AnalysisDataService;
23
using Mantid::API::Axis;
24
using Mantid::API::MatrixWorkspace_const_sptr;
LamarMoore's avatar
LamarMoore committed
25
using Mantid::DataHandling::LoadILLSANS;
26
using Mantid::Geometry::IComponent_const_sptr;
27
using Mantid::Geometry::IDetector_const_sptr;
28
using Mantid::Geometry::Instrument;
LamarMoore's avatar
LamarMoore committed
29
30
31
using Mantid::Kernel::ConfigService;
using Mantid::Kernel::Unit;
using Mantid::Kernel::V3D;
32
using detid2det_map = std::map<Mantid::detid_t, IDetector_const_sptr>;
33

34
class LoadILLSANSTest : public CxxTest::TestSuite {
35
public:
36
37
38
39
40
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static LoadILLSANSTest *createSuite() { return new LoadILLSANSTest(); }
  static void destroySuite(LoadILLSANSTest *suite) { delete suite; }

41
42
  LoadILLSANSTest() {
    ConfigService::Instance().appendDataSearchSubDir("ILL/D11/");
43
    ConfigService::Instance().appendDataSearchSubDir("ILL/D11B/");
44
    ConfigService::Instance().appendDataSearchSubDir("ILL/D22/");
45
    ConfigService::Instance().appendDataSearchSubDir("ILL/D22B/");
46
47
48
49
    ConfigService::Instance().appendDataSearchSubDir("ILL/D33/");
    ConfigService::Instance().appendDataSearchSubDir("ILL/D16/");
    ConfigService::Instance().setFacility("ILL");
  }
50

Gagik Vardanyan's avatar
Gagik Vardanyan committed
51
  void tearDown() override { AnalysisDataService::Instance().clear(); }
52

53
  void test_name() {
54
55
56
57
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.name(), "LoadILLSANS");
  }

58
  void test_version() {
59
60
61
62
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.version(), 1);
  }

63
  void test_init() {
64
65
66
67
68
    LoadILLSANS alg;
    TS_ASSERT_THROWS_NOTHING(alg.initialize())
    TS_ASSERT(alg.isInitialized())
  }

69
  void test_D11() {
70
71
72
73
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "010560.nxs"))
Samuel Jones's avatar
Samuel Jones committed
74
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
75
76
77
78
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
79
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 128 * 128 + 2)
80
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
81
82
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 128))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 128 + 1))
83
84
85
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
Samuel Jones's avatar
Samuel Jones committed
86
    IComponent_const_sptr component = instrument->getComponentByName("detector");
87
88
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), 20.007, 1E-3)
89
90
91
    const auto &xAxis = outputWS->x(0).rawData();
    const auto &spec6 = outputWS->y(6).rawData();
    const auto &err6 = outputWS->e(6).rawData();
92
    TS_ASSERT_EQUALS(xAxis.size(), 2)
93
94
    TS_ASSERT_DELTA(xAxis[0], 5.73, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 6.27, 1E-5)
95
    TS_ASSERT_EQUALS(spec6[0], 20)
96
97
98
    TS_ASSERT_DELTA(err6[0], sqrt(20), 1E-5)
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
99
    checkTimeFormat(outputWS);
100
  }
101

102
103
104
105
  void test_D11B() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
106
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "000410.nxs"))
Samuel Jones's avatar
Samuel Jones committed
107
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
108
109
110
111
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
Samuel Jones's avatar
Samuel Jones committed
112
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 192 * 256 + 2 * 32 * 256 + 2)
113
114
115
116
117
118
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(192 * 256 + 2 * 32 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(192 * 256 + 2 * 32 * 256 + 1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
119
120
121
122
123
124
125
    const auto &run = outputWS->run();
    TS_ASSERT(run.hasProperty("Detector 1.det_calc"));
    TS_ASSERT(run.hasProperty("L2"));
    const double detCalc = run.getPropertyAsSingleValue("Detector 1.det_calc");
    const double l2 = run.getPropertyAsSingleValue("L2");
    TS_ASSERT_EQUALS(detCalc, l2);
    const double panelOffset = 0.105;
Samuel Jones's avatar
Samuel Jones committed
126
    IComponent_const_sptr component = instrument->getComponentByName("detector_center");
127
    V3D pos = component->getPos();
128
    TS_ASSERT_DELTA(pos.Z(), l2, 1E-5)
129
130
    component = instrument->getComponentByName("detector_left");
    pos = component->getPos();
131
    TS_ASSERT_DELTA(pos.Z(), l2 - panelOffset, 1E-5)
132
133
    component = instrument->getComponentByName("detector_right");
    pos = component->getPos();
134
    TS_ASSERT_DELTA(pos.Z(), l2 - panelOffset, 1E-5)
135
    const auto &xAxis = outputWS->x(0).rawData();
136
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1);
137
    TS_ASSERT_EQUALS(xAxis.size(), 2)
138
139
    TS_ASSERT_DELTA(xAxis[0], 5.73, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 6.27, 1E-5)
140
141
142
143
144
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
    checkTimeFormat(outputWS);
  }

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
  void test_D11B_Kinetic() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "017177.nxs"))
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 192 * 256 + 2 * 32 * 256 + 2)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(192 * 256 + 2 * 32 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(192 * 256 + 2 * 32 * 256 + 1))
    TS_ASSERT(!outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    TS_ASSERT(outputWS->isCommonBins())
    const auto &instrument = outputWS->getInstrument();
    const auto &run = outputWS->run();
    TS_ASSERT(run.hasProperty("Detector 1.det_calc"));
    TS_ASSERT(run.hasProperty("L2"));
    const double detCalc = run.getPropertyAsSingleValue("Detector 1.det_calc");
    const double l2 = run.getPropertyAsSingleValue("L2");
    TS_ASSERT_EQUALS(detCalc, l2);
    const double panelOffset = 0.105;
    const double lambda = run.getPropertyAsSingleValue("wavelength");
    TS_ASSERT_EQUALS(lambda, 6.);
    IComponent_const_sptr component = instrument->getComponentByName("detector_center");
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), l2, 1E-5)
    component = instrument->getComponentByName("detector_left");
    pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), l2 - panelOffset, 1E-5)
    component = instrument->getComponentByName("detector_right");
    pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), l2 - panelOffset, 1E-5)
    const size_t nExpectedFrames = 85;
    TS_ASSERT_EQUALS(outputWS->blocksize(), nExpectedFrames)
    const auto &xAxis = outputWS->x(0).rawData();
    TS_ASSERT_EQUALS(outputWS->blocksize(), nExpectedFrames);
    TS_ASSERT_EQUALS(xAxis.size(), nExpectedFrames)
    TS_ASSERT_DELTA(xAxis[0], 0, 1E-9)
    TS_ASSERT_DELTA(xAxis[13], 13, 1E-9)
    const auto &mon1 = outputWS->y(192 * 256 + 2 * 32 * 256).rawData();
    const auto &mon1err = outputWS->e(192 * 256 + 2 * 32 * 256).rawData();
    TS_ASSERT_EQUALS(mon1.size(), nExpectedFrames)
    TS_ASSERT_EQUALS(mon1[0], 367)
    TS_ASSERT_EQUALS(mon1err.size(), nExpectedFrames)
    TS_ASSERT_DELTA(mon1err[0], std::sqrt(367), 1E-9)
    const auto &mon2 = outputWS->y(192 * 256 + 2 * 32 * 256 + 1).rawData();
    const auto &mon2err = outputWS->e(192 * 256 + 2 * 32 * 256 + 1).rawData();
    TS_ASSERT_EQUALS(mon2.size(), nExpectedFrames)
    TS_ASSERT_DELTA(mon2[0], 0.05, 1E-3)
    TS_ASSERT_EQUALS(mon2err.size(), nExpectedFrames)
    TS_ASSERT_DELTA(mon2err[0], 0, 1E-9)
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Empty");
    checkTimeFormat(outputWS);
  }

204
  void test_D22() {
205
206
207
208
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "192068.nxs"))
Samuel Jones's avatar
Samuel Jones committed
209
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
210
211
212
213
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
214
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 128 * 256 + 2)
215
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
216
217
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256 + 1))
218
219
220
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
Samuel Jones's avatar
Samuel Jones committed
221
    IComponent_const_sptr component = instrument->getComponentByName("detector");
222
223
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), 8, 0.01)
224
    TS_ASSERT_DELTA(pos.X(), -0.35, 0.01)
225
226
227
    const auto &xAxis = outputWS->x(0).rawData();
    const auto &spec6 = outputWS->y(6).rawData();
    const auto &err6 = outputWS->e(6).rawData();
228
    TS_ASSERT_EQUALS(xAxis.size(), 2)
229
230
    TS_ASSERT_DELTA(xAxis[0], 4.75, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 5.25, 1E-5)
231
    TS_ASSERT_EQUALS(spec6[0], 45)
232
233
234
    TS_ASSERT_DELTA(err6[0], sqrt(45), 1E-5)
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
235
    checkTimeFormat(outputWS);
236
  }
237

238
239
240
  void test_D22B_Cycle211() {
    // During cycle 211 the front detector was detector 1, back detector was detector 2
    // This wasn't consistent with the rest of the instruments, so was swapped from 212 on
241
242
243
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
Gagik Vardanyan's avatar
Gagik Vardanyan committed
244
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "000180.nxs"))
Samuel Jones's avatar
Samuel Jones committed
245
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
246
247
248
249
250
251
252
253
254
255
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 128 * 256 + 96 * 256 + 2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256 + 96 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256 + 96 * 256 + 1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
Gagik Vardanyan's avatar
Gagik Vardanyan committed
256
    TS_ASSERT_EQUALS(outputWS->getAxis(0)->unit()->unitID(), "Wavelength");
257
    const auto &instrument = outputWS->getInstrument();
Gagik Vardanyan's avatar
Gagik Vardanyan committed
258
    const auto &run = outputWS->run();
Samuel Jones's avatar
Samuel Jones committed
259
    IComponent_const_sptr comp = instrument->getComponentByName("detector_back");
260
    V3D pos = comp->getPos();
Gagik Vardanyan's avatar
Gagik Vardanyan committed
261
262
    TS_ASSERT(run.hasProperty("Detector 2.det2_calc"))
    double det2_calc = run.getLogAsSingleValue("Detector 2.det2_calc");
263
264
    TS_ASSERT(run.hasProperty("Detector 2.dtr2_actual"))
    double dtr2_act = run.getLogAsSingleValue("Detector 2.dtr2_actual");
Gagik Vardanyan's avatar
Gagik Vardanyan committed
265
266
267
268
269
    TS_ASSERT_DELTA(pos.Z(), det2_calc, 1E-6)
    TS_ASSERT_DELTA(pos.X(), -dtr2_act / 1000., 1E-6)
    TS_ASSERT(run.hasProperty("L2"))
    double l2 = run.getLogAsSingleValue("L2");
    TS_ASSERT_DELTA(l2, det2_calc, 1E-6)
270
    comp = instrument->getComponentByName("detector_front");
271
    pos = comp->getPos();
Gagik Vardanyan's avatar
Gagik Vardanyan committed
272
273
    TS_ASSERT(run.hasProperty("Detector 1.det1_calc"))
    double det1_calc = run.getLogAsSingleValue("Detector 1.det1_calc");
274
275
    TS_ASSERT(run.hasProperty("Detector 1.dtr1_actual"))
    double dtr1_act = run.getLogAsSingleValue("Detector 1.dtr1_actual");
Gagik Vardanyan's avatar
Gagik Vardanyan committed
276
277
    TS_ASSERT_DELTA(pos.Z(), det1_calc, 1E-6)
    TS_ASSERT_DELTA(pos.X(), -dtr1_act / 1000., 1E-6)
278
279
280
281
    TS_ASSERT(run.hasProperty("Detector 1.dan1_actual"))
    double dan1_act = run.getLogAsSingleValue("Detector 1.dan1_actual");
    double angle, qx, qy, qz;
    comp->getRotation().getAngleAxis(angle, qx, qy, qz);
282
    TS_ASSERT_DELTA(angle, dan1_act, 1E-6)
283
    TS_ASSERT_EQUALS(qx, 0.)
284
    TS_ASSERT_DELTA(std::fabs(qy), 1., 1E-6)
285
    TS_ASSERT_EQUALS(qz, 0.)
286
287
288
    checkTimeFormat(outputWS);
  }

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
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
  void test_D22B() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "046600.nxs"))
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 128 * 256 + 96 * 256 + 2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256 + 96 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256 + 96 * 256 + 1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    TS_ASSERT_EQUALS(outputWS->getAxis(0)->unit()->unitID(), "Wavelength");
    const auto &instrument = outputWS->getInstrument();
    const auto &run = outputWS->run();
    IComponent_const_sptr comp = instrument->getComponentByName("detector_back");
    V3D pos = comp->getPos();
    TS_ASSERT(run.hasProperty("Detector 1.det1_calc"))
    double det2_calc = run.getLogAsSingleValue("Detector 1.det1_calc");
    TS_ASSERT(run.hasProperty("Detector 1.dtr1_actual"))
    double dtr2_act = run.getLogAsSingleValue("Detector 1.dtr1_actual");
    TS_ASSERT_DELTA(pos.Z(), det2_calc, 1E-6)
    TS_ASSERT_DELTA(pos.X(), -dtr2_act / 1000., 1E-6)
    TS_ASSERT(run.hasProperty("L2"))
    double l2 = run.getLogAsSingleValue("L2");
    TS_ASSERT_DELTA(l2, det2_calc, 1E-6)
    comp = instrument->getComponentByName("detector_front");
    pos = comp->getPos();
    TS_ASSERT(run.hasProperty("Detector 2.det2_calc"))
    double det1_calc = run.getLogAsSingleValue("Detector 2.det2_calc");
    TS_ASSERT(run.hasProperty("Detector 2.dtr2_actual"))
    double dtr1_act = run.getLogAsSingleValue("Detector 2.dtr2_actual");
    TS_ASSERT_DELTA(pos.Z(), det1_calc, 1E-6)
    TS_ASSERT_DELTA(pos.X(), -dtr1_act / 1000., 1E-6)
    TS_ASSERT(run.hasProperty("Detector 2.dan2_actual"))
    double dan1_act = run.getLogAsSingleValue("Detector 2.dan2_actual");
    double angle, qx, qy, qz;
    comp->getRotation().getAngleAxis(angle, qx, qy, qz);
    TS_ASSERT_DELTA(angle, dan1_act, 1E-6)
    TS_ASSERT_EQUALS(qx, 0.)
    TS_ASSERT_DELTA(std::fabs(qy), 1., 1E-6)
    TS_ASSERT_EQUALS(qz, 0.)
    checkTimeFormat(outputWS);
  }

  void test_D16_GAMMA() {
339
340
341
342
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "218356.nxs"));
Samuel Jones's avatar
Samuel Jones committed
343
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"));
344
345
346
347
    TS_ASSERT_THROWS_NOTHING(alg.execute());
    TS_ASSERT(alg.isExecuted());
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS);
348
    TS_ASSERT(outputWS->isHistogramData())
349
350
351
    TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320));
    TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320 + 1));
    const auto &instrument = outputWS->getInstrument();
Samuel Jones's avatar
Samuel Jones committed
352
    IComponent_const_sptr component = instrument->getComponentByName("detector");
353
354
355
    V3D pos = component->getPos();
    V3D origin(0, 0, 0);
    TS_ASSERT_DELTA(pos.distance(origin), 1, 1E-5);
356
357
    TS_ASSERT_DELTA(pos.X(), -0.17365, 1E-5); // sin(10)
    TS_ASSERT_DELTA(pos.Z(), 0.98481, 1E-5);  // cos(10)
358
359
360
361
    Mantid::detid_t bl_id, tr_id;
    instrument->getMinMaxDetectorIDs(bl_id, tr_id);
    detid2det_map det_map;
    instrument->getDetectors(det_map);
362
363
364
365
    IDetector_const_sptr bottom_right_pixel = det_map[bl_id];
    IDetector_const_sptr top_left_pixel = det_map[320 * 320 - 1];
    V3D br_pos = bottom_right_pixel->getPos();
    V3D tl_pos = top_left_pixel->getPos();
366
    // check the detector has 10 degrees angle
367
368
369
370
371
372
    TS_ASSERT_DELTA(br_pos.distance(origin), 1.02512, 1E-5);
    TS_ASSERT_DELTA(tl_pos.distance(origin), 1.02512, 1E-5);
    TS_ASSERT_DELTA(tl_pos.X(), -0.33073, 1E-5);
    TS_ASSERT_DELTA(tl_pos.Z(), 0.95711, 1E-5);
    TS_ASSERT_DELTA(br_pos.X(), -0.01657, 1E-5);
    TS_ASSERT_DELTA(br_pos.Z(), 1.01250, 1E-5);
373
374
375
376
    const auto &xAxis = outputWS->x(0).rawData();
    const auto &spec = outputWS->y(51972).rawData();
    const auto &err = outputWS->e(51972).rawData();
    TS_ASSERT_EQUALS(xAxis.size(), 2)
377
378
    TS_ASSERT_DELTA(xAxis[0], 6.965, 1E-3)
    TS_ASSERT_DELTA(xAxis[1], 7.035, 1E-3)
379
380
    TS_ASSERT_EQUALS(spec[0], 17)
    TS_ASSERT_DELTA(err[0], sqrt(17), 1E-5)
381
    checkTimeFormat(outputWS);
382
383
  }

384
385
386
387
388
389
390
391
392
393
  void test_D16_OMEGA() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "023583.nxs"));
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"));
    TS_ASSERT_THROWS_NOTHING(alg.execute());
    TS_ASSERT(alg.isExecuted());
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS);
394
    TS_ASSERT(outputWS->isHistogramData())
395
396
397
398
399
400
401
402
    TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320));
    TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320 + 1));
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 320 * 320 + 2);
    checkTimeFormat(outputWS);
  }

  void test_D33_MONO() {
403
404
405
406
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "002294.nxs"))
Samuel Jones's avatar
Samuel Jones committed
407
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 256 * 256 + 2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(256 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(256 * 256 + 1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &xAxis = outputWS->x(0).rawData();
    const auto &spec = outputWS->y(15947).rawData();
    const auto &err = outputWS->e(15947).rawData();
    TS_ASSERT_EQUALS(xAxis.size(), 2)
    TS_ASSERT_DELTA(xAxis[0], 9.5, 1E-3)
    TS_ASSERT_DELTA(xAxis[1], 10.5, 1E-3)
    TS_ASSERT_EQUALS(spec[0], 220)
    TS_ASSERT_DELTA(err[0], sqrt(220), 1E-5)
    const auto &instrument = outputWS->getInstrument();
Samuel Jones's avatar
Samuel Jones committed
427
    IComponent_const_sptr back = instrument->getComponentByName("back_detector");
428
    TS_ASSERT_EQUALS(back->getPos(), V3D(0, 0, 10.1128));
Samuel Jones's avatar
Samuel Jones committed
429
    IComponent_const_sptr right = instrument->getComponentByName("front_detector_right");
430
    TS_ASSERT_EQUALS(right->getPos(), V3D(-0.41, 0, 1.4968));
Samuel Jones's avatar
Samuel Jones committed
431
    IComponent_const_sptr left = instrument->getComponentByName("front_detector_left");
432
    TS_ASSERT_EQUALS(left->getPos(), V3D(0.41, 0, 1.4968));
Samuel Jones's avatar
Samuel Jones committed
433
    IComponent_const_sptr top = instrument->getComponentByName("front_detector_top");
434
    TS_ASSERT_EQUALS(top->getPos(), V3D(0, 0.41, 1.3118));
Samuel Jones's avatar
Samuel Jones committed
435
    IComponent_const_sptr bottom = instrument->getComponentByName("front_detector_bottom");
436
437
438
    TS_ASSERT_EQUALS(bottom->getPos(), V3D(0, -0.41, 1.3118));
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
439
    checkTimeFormat(outputWS);
440
441
  }

442
  void test_D33_LTOF() {
443
444
445
446
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "042610.nxs"))
Samuel Jones's avatar
Samuel Jones committed
447
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
448
449
450
451
452
453
454
455
456
457
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 256 * 256 + 2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 200)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(256 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(256 * 256 + 1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
458
    TS_ASSERT(!outputWS->isCommonBins())
459
460
461
462
463
464
    const auto &x = outputWS->x(0).rawData();
    TS_ASSERT_DELTA(x[0], 0.04969, 1E-5)
    TS_ASSERT_DELTA(x[1], 0.14873, 1E-5)
    TS_ASSERT_DELTA(x[200], 19.85713, 1E-5)
    const auto &run = outputWS->run();
    TS_ASSERT(run.hasProperty("tof_mode"))
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
    const auto tof = run.getLogData("tof_mode");
    TS_ASSERT_EQUALS(tof->value(), "TOF");
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
    checkTimeFormat(outputWS);
  }

  void test_D33_VTOF() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "093410.nxs"))
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 256 * 256 + 2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 30)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(256 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(256 * 256 + 1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    TS_ASSERT(!outputWS->isCommonBins())
    const auto &x = outputWS->x(0).rawData();
    TS_ASSERT_DELTA(x[0], 0., 1E-5)
    TS_ASSERT_DELTA(x[1], 0.1998, 1E-5)
    TS_ASSERT_DELTA(x[2], 0.3996, 1E-5)
    const auto &run = outputWS->run();
    TS_ASSERT(run.hasProperty("tof_mode"))
495
496
497
498
    const auto tof = run.getLogData("tof_mode");
    TS_ASSERT_EQUALS(tof->value(), "TOF");
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
499
500
501
502
    checkTimeFormat(outputWS);
  }

  void checkTimeFormat(MatrixWorkspace_const_sptr outputWS) {
503
    TS_ASSERT(outputWS->run().hasProperty("start_time"));
Samuel Jones's avatar
Samuel Jones committed
504
505
    TS_ASSERT(
        Mantid::Types::Core::DateAndTimeHelpers::stringIsISO8601(outputWS->run().getProperty("start_time")->value()));
506
  }
507
508
};

509
510
511
class LoadILLSANSTestPerformance : public CxxTest::TestSuite {
public:
  void setUp() override {
512
513
514
515
    m_alg.initialize();
    m_alg.setChild(true);
    m_alg.setPropertyValue("Filename", "ILL/D33/042610.nxs");
    m_alg.setPropertyValue("OutputWorkspace", "__unused_for_child");
516
517
  }
  void testLoadILLSANSPerformance() {
518
519
    for (int i = 0; i < 10; ++i) {
      TS_ASSERT_THROWS_NOTHING(m_alg.execute());
520
521
    }
  }
522
  void tearDown() override { AnalysisDataService::Instance().clear(); }
523
524

private:
525
  LoadILLSANS m_alg;
526
};