-
Notifications
You must be signed in to change notification settings - Fork 122
/
SymmetriseModel.cpp
103 lines (83 loc) · 4.46 KB
/
SymmetriseModel.cpp
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2022 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 +
#include "SymmetriseModel.h"
#include "Common/IndirectDataValidationHelper.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidQtWidgets/Common/UserInputValidator.h"
#include <QDoubleValidator>
#include <QFileInfo>
using namespace IndirectDataValidationHelper;
using namespace Mantid::API;
namespace MantidQt::CustomInterfaces {
SymmetriseModel::SymmetriseModel()
: m_inputWorkspace(), m_reflectedInputWorkspace(), m_negativeOutputWorkspace(), m_positiveOutputWorkspace(),
m_eMin(), m_eMax(), m_isPositiveReflect(), m_spectraRange() {}
void SymmetriseModel::setupPreviewAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner,
std::vector<long> const &spectraRange) {
if (!m_isPositiveReflect) {
reflectNegativeToPositive();
}
// Run the algorithm on the preview spectrum only, these outputs are only for plotting in the preview window and are
// not accessed by users directly.
IAlgorithm_sptr symmetriseAlg = AlgorithmManager::Instance().create("Symmetrise");
symmetriseAlg->initialize();
symmetriseAlg->setProperty("InputWorkspace", m_isPositiveReflect ? m_inputWorkspace : m_reflectedInputWorkspace);
symmetriseAlg->setProperty("XMin", m_eMin);
symmetriseAlg->setProperty("XMax", m_eMax);
symmetriseAlg->setProperty("SpectraRange", spectraRange);
symmetriseAlg->setProperty("OutputWorkspace", "__Symmetrise_temp");
symmetriseAlg->setProperty("OutputPropertiesTable", "__SymmetriseProps_temp");
symmetriseAlg->setRethrows(true);
batchAlgoRunner->addAlgorithm(symmetriseAlg);
}
std::string SymmetriseModel::setupSymmetriseAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) {
std::string outputWorkspace = m_positiveOutputWorkspace;
if (!m_isPositiveReflect) {
reflectNegativeToPositive();
outputWorkspace = m_negativeOutputWorkspace;
}
IAlgorithm_sptr symmetriseAlg = AlgorithmManager::Instance().create("Symmetrise");
symmetriseAlg->initialize();
symmetriseAlg->setProperty("InputWorkspace", m_isPositiveReflect ? m_inputWorkspace : m_reflectedInputWorkspace);
symmetriseAlg->setProperty("XMin", m_eMin);
symmetriseAlg->setProperty("XMax", m_eMax);
symmetriseAlg->setProperty("OutputWorkspace", outputWorkspace);
symmetriseAlg->setProperty("OutputPropertiesTable", "__SymmetriseProps_temp");
batchAlgoRunner->addAlgorithm(symmetriseAlg);
return outputWorkspace;
}
void SymmetriseModel::reflectNegativeToPositive() {
IAlgorithm_sptr scaleXAlg = AlgorithmManager::Instance().create("ScaleX");
scaleXAlg->initialize();
scaleXAlg->setProperty("InputWorkspace", m_inputWorkspace);
scaleXAlg->setProperty("Operation", "Multiply");
scaleXAlg->setProperty("Factor", -1.0);
scaleXAlg->setProperty("OutputWorkspace", m_reflectedInputWorkspace);
scaleXAlg->execute();
IAlgorithm_sptr sortXAxisAlg = AlgorithmManager::Instance().create("SortXAxis");
sortXAxisAlg->initialize();
sortXAxisAlg->setProperty("InputWorkspace", m_reflectedInputWorkspace);
sortXAxisAlg->setProperty("OutputWorkspace", m_reflectedInputWorkspace);
sortXAxisAlg->execute();
}
void SymmetriseModel::setWorkspaceName(std::string const &workspaceName) {
m_inputWorkspace = workspaceName;
m_reflectedInputWorkspace = m_inputWorkspace + "_reflected";
// the last 4 characters in the workspace name are '_red' the ouput workspace name is inserting '_sym' before that
// '_red'
m_positiveOutputWorkspace = workspaceName.substr(0, workspaceName.size() - 4) + "_sym_pn" +
workspaceName.substr(workspaceName.size() - 4, workspaceName.size());
m_negativeOutputWorkspace = workspaceName.substr(0, workspaceName.size() - 4) + "_sym_np" +
workspaceName.substr(workspaceName.size() - 4, workspaceName.size());
}
void SymmetriseModel::setEMin(double value) { m_eMin = value; }
void SymmetriseModel::setEMax(double value) { m_eMax = value; }
void SymmetriseModel::setIsPositiveReflect(bool value) { m_isPositiveReflect = value; }
bool SymmetriseModel::getIsPositiveReflect() const { return m_isPositiveReflect; }
} // namespace MantidQt::CustomInterfaces