LoadILLSANSTest.h 8.47 KB
Newer Older
1
2
3
4
5
#ifndef MANTID_DATAHANDLING_LOADILLSANSTEST_H_
#define MANTID_DATAHANDLING_LOADILLSANSTEST_H_

#include <cxxtest/TestSuite.h>

6
#include "MantidAPI/Axis.h"
7
#include "MantidAPI/AnalysisDataService.h"
8
#include "MantidAPI/MatrixWorkspace.h"
9
#include "MantidDataHandling/LoadILLSANS.h"
10
11
12
13
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/ConfigService.h"
14
#include "MantidKernel/Unit.h"
15
16

using Mantid::DataHandling::LoadILLSANS;
17
using Mantid::API::Axis;
18
19
20
21
using Mantid::API::MatrixWorkspace_const_sptr;
using Mantid::API::AnalysisDataService;
using Mantid::Kernel::ConfigService;
using Mantid::Kernel::V3D;
22
using Mantid::Kernel::Unit;
23
24
using Mantid::Geometry::IComponent_const_sptr;
using Mantid::Geometry::Instrument;
25

26
class LoadILLSANSTest : public CxxTest::TestSuite {
27
public:
28
29
30
31
32
  // 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; }

33
34
35
36
37
38
39
  void setUp() override {
    ConfigService::Instance().appendDataSearchSubDir("ILL/D11/");
    ConfigService::Instance().appendDataSearchSubDir("ILL/D22/");
    ConfigService::Instance().appendDataSearchSubDir("ILL/D33/");
    ConfigService::Instance().setFacility("ILL");
  }

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

42
  void test_name() {
43
44
45
46
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.name(), "LoadILLSANS");
  }

47
  void test_version() {
48
49
50
51
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.version(), 1);
  }

52
  void test_init() {
53
54
55
56
57
    LoadILLSANS alg;
    TS_ASSERT_THROWS_NOTHING(alg.initialize())
    TS_ASSERT(alg.isInitialized())
  }

58
  void test_D11() {
59
60
61
62
63
64
65
66
67
68
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "010560.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)
69
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 128 * 128 + 2)
70
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
71
72
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 128))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 128 + 1))
73
74
75
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
76
77
    IComponent_const_sptr component =
        instrument->getComponentByName("detector");
78
79
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), 20.007, 1E-3)
80
81
82
    const auto &xAxis = outputWS->x(0).rawData();
    const auto &spec6 = outputWS->y(6).rawData();
    const auto &err6 = outputWS->e(6).rawData();
83
84
85
86
    TS_ASSERT_EQUALS(xAxis.size(), 2)
    TS_ASSERT_DELTA(xAxis[0], 5.72778, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 6.26757, 1E-5)
    TS_ASSERT_EQUALS(spec6[0], 20)
87
88
89
90
    TS_ASSERT_DELTA(err6[0], sqrt(20), 1E-5)
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
  }
91

92
  void test_D22() {
93
94
95
96
97
98
99
100
101
102
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "192068.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)
103
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 128 * 256 + 2)
104
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
105
106
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128 * 256 + 1))
107
108
109
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
110
111
    IComponent_const_sptr component =
        instrument->getComponentByName("detector");
112
113
114
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), 8, 0.01)
    TS_ASSERT_DELTA(pos.X(), 0.35, 0.01)
115
116
117
    const auto &xAxis = outputWS->x(0).rawData();
    const auto &spec6 = outputWS->y(6).rawData();
    const auto &err6 = outputWS->e(6).rawData();
118
119
120
121
    TS_ASSERT_EQUALS(xAxis.size(), 2)
    TS_ASSERT_DELTA(xAxis[0], 4.75015, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 5.25016, 1E-5)
    TS_ASSERT_EQUALS(spec6[0], 45)
122
123
124
125
    TS_ASSERT_DELTA(err6[0], sqrt(45), 1E-5)
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
  }
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
  void test_D33() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "002294.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(), 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();
    IComponent_const_sptr back =
        instrument->getComponentByName("back_detector");
    TS_ASSERT_EQUALS(back->getPos(), V3D(0, 0, 10.1128));
    IComponent_const_sptr right =
        instrument->getComponentByName("front_detector_right");
    TS_ASSERT_EQUALS(right->getPos(), V3D(-0.41, 0, 1.4968));
    IComponent_const_sptr left =
        instrument->getComponentByName("front_detector_left");
    TS_ASSERT_EQUALS(left->getPos(), V3D(0.41, 0, 1.4968));
    IComponent_const_sptr top =
        instrument->getComponentByName("front_detector_top");
    TS_ASSERT_EQUALS(top->getPos(), V3D(0, 0.41, 1.3118));
    IComponent_const_sptr bottom =
        instrument->getComponentByName("front_detector_bottom");
    TS_ASSERT_EQUALS(bottom->getPos(), V3D(0, -0.41, 1.3118));
    const auto unit = outputWS->getAxis(0)->unit()->unitID();
    TS_ASSERT_EQUALS(unit, "Wavelength");
  }

  void test_D33_TOF() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "042610.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(), 200)
    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 &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"))
    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");
  }
200
201
};

202
203
204
class LoadILLSANSTestPerformance : public CxxTest::TestSuite {
public:
  void setUp() override {
205
206
207
208
    m_alg.initialize();
    m_alg.setChild(true);
    m_alg.setPropertyValue("Filename", "ILL/D33/042610.nxs");
    m_alg.setPropertyValue("OutputWorkspace", "__unused_for_child");
209
210
  }
  void testLoadILLSANSPerformance() {
211
212
    for (int i = 0; i < 10; ++i) {
      TS_ASSERT_THROWS_NOTHING(m_alg.execute());
213
214
    }
  }
215
  void tearDown() override { AnalysisDataService::Instance().clear(); }
216
217

private:
218
  LoadILLSANS m_alg;
219
220
};

221
#endif /* MANTID_DATAHANDLING_LOADILLSANSTEST_H_ */