Newer
Older
#ifndef CALCULATEEFFICIENCYTEST_H_
#define CALCULATEEFFICIENCYTEST_H_
Doucet, Mathieu
committed
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
115
116
117
118
119
120
121
122
123
124
125
#include <cxxtest/TestSuite.h>
#include "MantidAlgorithms/CalculateEfficiency.h"
#include "MantidAlgorithms/SolidAngleCorrection.h"
#include "MantidDataHandling/LoadSpice2D.h"
#include "MantidDataHandling/MoveInstrumentComponent.h"
using namespace Mantid::API;
using namespace Mantid::Kernel;
class CalculateEfficiencyTest : public CxxTest::TestSuite
{
public:
void testName()
{
TS_ASSERT_EQUALS( correction.name(), "CalculateEfficiency" )
}
void testVersion()
{
TS_ASSERT_EQUALS( correction.version(), 1 )
}
void testCategory()
{
TS_ASSERT_EQUALS( correction.category(), "SANS" )
}
void testInit()
{
TS_ASSERT_THROWS_NOTHING( correction.initialize() )
TS_ASSERT( correction.isInitialized() )
}
/*
* Function that will validate results against known results found with
* "standard" HFIR reduction package.
*/
void validate()
{
Mantid::DataHandling::LoadSpice2D loader;
loader.initialize();
loader.setPropertyValue("Filename","../../../../Test/Data/SANS2D/BioSANS_exp61_scan0004_0001.xml");
const std::string inputWS("wav");
loader.setPropertyValue("OutputWorkspace",inputWS);
loader.execute();
Mantid::DataHandling::MoveInstrumentComponent mover;
mover.initialize();
mover.setPropertyValue("Workspace","wav");
mover.setPropertyValue("ComponentName","detector1");
// According to the instrument geometry, the center of the detector is located at N_pixel / 2 + 0.5
// X = (16-192.0/2.0+0.5)*5.15/1000.0 = -0.409425
// Y = (95-192.0/2.0+0.5)*5.15/1000.0 = -0.002575
mover.setPropertyValue("X","0.409425");
mover.setPropertyValue("Y","0.002575");
mover.setPropertyValue("Z","6");
mover.execute();
// Solid angle correction
Mantid::Algorithms::SolidAngleCorrection sa_corr;
const std::string sa_corrWS("sa_corrected");
sa_corr.initialize();
sa_corr.setPropertyValue("InputWorkspace", inputWS);
sa_corr.setPropertyValue("OutputWorkspace", sa_corrWS);
sa_corr.execute();
if (!correction.isInitialized()) correction.initialize();
const std::string outputWS("result");
TS_ASSERT_THROWS_NOTHING( correction.setPropertyValue("InputWorkspace",sa_corrWS) )
TS_ASSERT_THROWS_NOTHING( correction.setPropertyValue("OutputWorkspace",outputWS) )
TS_ASSERT_THROWS_NOTHING( correction.setProperty<double>("MinEfficiency",0.5) )
TS_ASSERT_THROWS_NOTHING( correction.setProperty<double>("MaxEfficiency",1.50) )
correction.execute();
TS_ASSERT( correction.isExecuted() )
Mantid::API::MatrixWorkspace_sptr result;
TS_ASSERT_THROWS_NOTHING( result = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>
(Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)) )
TS_ASSERT_EQUALS( result->getNumberHistograms(), 36866 )
TS_ASSERT_EQUALS( result->getAxis(0)->unit()->unitID(), "Wavelength" )
Mantid::API::Workspace_sptr ws_in;
TS_ASSERT_THROWS_NOTHING( ws_in = Mantid::API::AnalysisDataService::Instance().retrieve(inputWS) );
Mantid::DataObjects::Workspace2D_sptr ws2d_in = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D>(ws_in);
Mantid::API::Workspace_sptr ws_out;
TS_ASSERT_THROWS_NOTHING( ws_out = Mantid::API::AnalysisDataService::Instance().retrieve(outputWS) );
Mantid::DataObjects::Workspace2D_sptr ws2d_out = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D>(ws_out);
// Number of monitors
int nmon = Mantid::DataHandling::LoadSpice2D::nMonitors;
// Get the coordinate of the detector pixel
double tolerance(1e-03);
TS_ASSERT_DELTA( ws2d_out->dataY(1+nmon)[0], 0.980083, tolerance );
TS_ASSERT_DELTA( ws2d_out->dataY(193+nmon)[0], 1.23006, tolerance );
TS_ASSERT_DELTA( ws2d_out->dataY(6+nmon)[0], 1.10898, tolerance );
TS_ASSERT_DELTA( ws2d_out->dataE(1+nmon)[0], 0.0990047, tolerance );
TS_ASSERT_DELTA( ws2d_out->dataE(193+nmon)[0], 0.110913, tolerance );
TS_ASSERT_DELTA( ws2d_out->dataE(6+nmon)[0], 0.105261, tolerance );
// Check that pixels that were out of range were masked
TS_ASSERT(ws2d_out->getDetector(1826)->isMasked())
TS_ASSERT(ws2d_out->getDetector(2014)->isMasked())
TS_ASSERT(ws2d_out->getDetector(2015)->isMasked())
Mantid::API::AnalysisDataService::Instance().remove(inputWS);
Mantid::API::AnalysisDataService::Instance().remove(outputWS);
}
private:
Mantid::Algorithms::CalculateEfficiency correction;
std::string inputWS;
};
#endif /*Q1DTEST_H_*/