Newer
Older
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
115
116
117
118
119
120
121
#ifndef COMPRESSEVENTSTEST_H_
#define COMPRESSEVENTSTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidDataHandling/CompressEvents.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include <iostream>
using Mantid::MantidVecPtr;
using namespace Mantid::Kernel;
using namespace Mantid::DataHandling;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::DataObjects;
class CompressEventsTest : public CxxTest::TestSuite
{
public:
void test_TheBasics()
{
CompressEvents alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() );
TS_ASSERT_EQUALS( alg.name(), "CompressEvents");
}
void test_InvalidInputs()
{
CompressEvents alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() );
TS_ASSERT_THROWS( alg.setPropertyValue("Tolerance", "-1.0"), std::invalid_argument);
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Tolerance", "0.0"));
}
void doTest(std::string inputName, std::string outputName, double tolerance)
{
EventWorkspace_sptr input, output;
/** Create event workspace with:
* 50 pixels
* 100 histogrammed bins from 0.0 in steps of 1.0
* 200 events; two in each bin, at time 0.5, 1.5, etc.
* PulseTime = 1 second, 2 seconds, etc.
*/
input = WorkspaceCreationHelper::CreateEventWorkspace2();
AnalysisDataService::Instance().addOrReplace(inputName, input);
// Quick initial check
TS_ASSERT_EQUALS( input->getNumberEvents(), 200*50 );
CompressEvents alg;
alg.initialize();
alg.setPropertyValue("InputWorkspace", inputName);
alg.setPropertyValue("OutputWorkspace", outputName);
alg.setProperty("Tolerance", tolerance);
TS_ASSERT_THROWS_NOTHING( alg.execute() );
TS_ASSERT( alg.isExecuted() );
TS_ASSERT_THROWS_NOTHING(
input = boost::dynamic_pointer_cast<EventWorkspace>(AnalysisDataService::Instance().retrieve(inputName)) );
TS_ASSERT_THROWS_NOTHING(
output = boost::dynamic_pointer_cast<EventWorkspace>(AnalysisDataService::Instance().retrieve(outputName)) );
// Avoid accessing empty pointer
TS_ASSERT(output);
if (!output) return;
if (inputName == outputName)
{ TS_ASSERT_EQUALS( input, output); }
else
{ TS_ASSERT_DIFFERS( input, output); }
// Half the previous # of events
TS_ASSERT_EQUALS( output->getNumberEvents(), 100*50 );
// Event list is now of type WeightedEventNoTime
TS_ASSERT_EQUALS( output->getEventType(), WEIGHTED_NOTIME );
// Check an event to see if it makes sense
if (output->getEventList(0).getNumberEvents() > 0)
{
WeightedEvent ev = output->getEventList(0).getEvent(0);
TS_ASSERT_DELTA( ev.weight(), 2.0, 1e-6);
TS_ASSERT_DELTA( ev.errorSquared(), 2.0, 1e-6 );
TS_ASSERT_DELTA( ev.tof(), 0.5, 1e-6);
}
// We still have an X axis with the right # of bins
TS_ASSERT_EQUALS( output->readX(0).size(), 101 );
// Y and E values are the same
TS_ASSERT_DELTA( output->readY(0)[1], 2.0, 1e-5 );
TS_ASSERT_DELTA( output->readE(0)[1], sqrt(2.0), 1e-5 );
TS_ASSERT_EQUALS( output->YUnit(), input->YUnit() );
TS_ASSERT_EQUALS( output->getAxis(0)->unit(), input->getAxis(0)->unit() );
TS_ASSERT_EQUALS( output->getAxis(1)->unit(), input->getAxis(1)->unit() );
}
void test_DifferentOutput()
{
doTest( "CompressEvents_input", "CompressEvents_output", 0.5);
}
void test_InPlace()
{
doTest( "CompressEvents_input", "CompressEvents_input", 0.5);
}
void test_DifferentOutput_ZeroTolerance()
{
doTest( "CompressEvents_input", "CompressEvents_output", 0.0);
}
void test_InPlace_ZeroTolerance()
{
doTest( "CompressEvents_input", "CompressEvents_input", 0.0);
}
};
#endif