-
Notifications
You must be signed in to change notification settings - Fork 121
/
CorrectFlightPathsTest.h
114 lines (90 loc) · 3.33 KB
/
CorrectFlightPathsTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
#ifndef MANTID_ALGORITHMS_CORRECTFLIGHTPATHSTEST_H_
#define MANTID_ALGORITHMS_CORRECTFLIGHTPATHSTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAlgorithms/CorrectFlightPaths.h"
#include "MantidAlgorithms/DetectorEfficiencyCorUser.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IAlgorithm.h"
#include <cmath>
using namespace Mantid::API;
using namespace Mantid;
using namespace Kernel;
using Mantid::Algorithms::CorrectFlightPaths;
class CorrectFlightPathsTest: public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static CorrectFlightPathsTest *createSuite() {
return new CorrectFlightPathsTest();
}
static void destroySuite(CorrectFlightPathsTest *suite) {
delete suite;
}
CorrectFlightPathsTest() :
// alter here if needed
m_l2(4) {
}
void testTheBasics() {
CorrectFlightPaths c;
TS_ASSERT_EQUALS(c.name(), "CorrectFlightPaths");
TS_ASSERT_EQUALS(c.version(), 1);
}
void testExec() {
std::string inputWSName("test_input_ws");
std::string outputWSName("test_output_ws");
std::vector<double> L2(5, 5);
std::vector<double> polar(5, (30. / 180.) * M_PI);
polar[0] = 0;
std::vector<double> azimutal(5, 0);
azimutal[1] = (45. / 180.) * M_PI;
azimutal[2] = (90. / 180.) * M_PI;
azimutal[3] = (135. / 180.) * M_PI;
azimutal[4] = (180. / 180.) * M_PI;
int numBins = 10;
Mantid::API::MatrixWorkspace_sptr dataws = WorkspaceCreationHelper::createProcessedInelasticWS(L2, polar,
azimutal, numBins, -1, 3, 3);
dataws->getAxis(0)->setUnit("TOF");
dataws->mutableRun().addProperty("wavelength",boost::lexical_cast<std::string>(5));
dataws->instrumentParameters().addString(dataws->getInstrument()->getComponentID(),"l2",boost::lexical_cast<std::string>(m_l2) );
API::AnalysisDataService::Instance().addOrReplace(inputWSName, dataws);
// BEFORE
for (int i = 0; i < 5; i++) {
Mantid::Geometry::IDetector_const_sptr det = dataws->getDetector(i);
double r, theta, phi;
Mantid::Kernel::V3D pos = det->getPos();
pos.getSpherical(r, theta, phi);
// Corrected distance to 4!
TS_ASSERT_DIFFERS(r, m_l2)
}
CorrectFlightPaths c;
if (!c.isInitialized())
c.initialize();
c.setPropertyValue("InputWorkspace", inputWSName);
c.setPropertyValue("OutputWorkspace", outputWSName);
c.execute();
TS_ASSERT(c.isExecuted());
Mantid::API::MatrixWorkspace_const_sptr output;
output = Mantid::API::AnalysisDataService::Instance().retrieveWS<
Mantid::API::MatrixWorkspace>(outputWSName);
// AFTER
// test the first tube to see if distance was well corrected to l2
for (int i = 0; i < 5; i++) {
Mantid::Geometry::IDetector_const_sptr det = output->getDetector(i);
double r, theta, phi;
Mantid::Kernel::V3D pos = det->getPos();
pos.getSpherical(r, theta, phi);
// Corrected distance to l2!
// TS_ASSERT_EQUALS(r, m_l2)
TS_ASSERT_DELTA(r, m_l2,0.001)
}
AnalysisDataService::Instance().remove(outputWSName);
AnalysisDataService::Instance().remove(inputWSName);
}
private:
int m_l2;
};
#endif /* MANTID_ALGORITHMS_CORRECTFLIGHTPATHSTEST_H_ */