forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertEventsToMDTest.h
82 lines (68 loc) · 3.19 KB
/
ConvertEventsToMDTest.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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidAPI/FrameworkManager.h"
#include "MantidFrameworkTestHelpers/ComponentCreationHelper.h"
#include "MantidFrameworkTestHelpers/MDEventsTestHelper.h"
#include "MantidFrameworkTestHelpers/WorkspaceCreationHelper.h"
#include "MantidMDAlgorithms/ConvertToMD.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::MDAlgorithms;
class ConvertEvents2MDEvTestHelper : public ConvertToMD {
public:
ConvertEvents2MDEvTestHelper(){};
};
//
class ConvertEventsToMDTest : public CxxTest::TestSuite {
std::unique_ptr<ConvertEvents2MDEvTestHelper> pAlg;
public:
static ConvertEventsToMDTest *createSuite() { return new ConvertEventsToMDTest(); }
static void destroySuite(ConvertEventsToMDTest *suite) { delete suite; }
void testEventWS() {
// set up algorithm
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("InputWorkspace", "testEvWS"));
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("OutputWorkspace", "testMDEvWorkspace"));
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("OtherDimensions", ""));
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("QDimensions", "Q3D"));
pAlg->setPropertyValue("PreprocDetectorsWS", "");
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("dEAnalysisMode", "Elastic"));
pAlg->setPropertyValue("MinValues", "-10,-10,-10");
pAlg->setPropertyValue("MaxValues", " 10, 10, 10");
pAlg->setRethrows(false);
pAlg->execute();
TSM_ASSERT("Should finish succesfully", pAlg->isExecuted());
Mantid::API::Workspace_sptr spws;
TS_ASSERT_THROWS_NOTHING(spws = AnalysisDataService::Instance().retrieve("testMDEvWorkspace"));
TSM_ASSERT(" Worskpace should be retrieved", spws.get());
std::shared_ptr<DataObjects::MDEventWorkspace<DataObjects::MDEvent<3>, 3>> ws =
std::dynamic_pointer_cast<DataObjects::MDEventWorkspace<DataObjects::MDEvent<3>, 3>>(spws);
TSM_ASSERT("It should be 3D MD workspace", ws.get());
if (ws.get()) {
TS_ASSERT_EQUALS(900, ws->getNPoints());
} else {
TS_FAIL("event workspace has not beed build");
}
AnalysisDataService::Instance().remove("testMDEvWorkspace");
}
ConvertEventsToMDTest() {
FrameworkManager::Instance();
pAlg = std::make_unique<ConvertEvents2MDEvTestHelper>();
pAlg->initialize();
int numHist = 10;
Mantid::API::MatrixWorkspace_sptr wsEv = std::dynamic_pointer_cast<MatrixWorkspace>(
WorkspaceCreationHelper::createRandomEventWorkspace(100, numHist, 0.1));
wsEv->setInstrument(ComponentCreationHelper::createTestInstrumentCylindrical(numHist));
// any inelastic units or unit conversion using TOF needs Ei to be present
// among properties.
// wsEv->mutableRun().addProperty("Ei",13.,"meV",true);
AnalysisDataService::Instance().addOrReplace("testEvWS", wsEv);
}
};