Mantid
Loading...
Searching...
No Matches
ConvertToDiffractionMDWorkspace3.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
10
14
18
22
23#include <boost/math/special_functions/sign.hpp>
24
25#include <algorithm>
26#include <limits>
27
28using namespace Mantid::API;
29using namespace Mantid::Kernel;
30using namespace Mantid::DataObjects;
31using namespace Mantid::Geometry;
32
33namespace Mantid::MDAlgorithms {
34
35// Register the algorithm into the AlgorithmFactory
36DECLARE_ALGORITHM(ConvertToDiffractionMDWorkspace3)
37
38//----------------------------------------------------------------------------------------------
42 // initilise common properties between versions
44
45 std::vector<double> extents;
46 declareProperty(std::make_unique<ArrayProperty<double>>("Extents", std::move(extents)),
47 "A comma separated list of min, max for each dimension,\n"
48 "specifying the extents of each dimension. Optional, default "
49 "will use ConvertToMDMinMaxLocal to calculate extents for each "
50 "dimension.");
51 setPropertyGroup("Extents", getBoxSettingsGroupName());
52}
53
64void ConvertToDiffractionMDWorkspace3::convertExtents(const std::vector<double> &Extents, std::vector<double> &minVal,
65 std::vector<double> &maxVal) {
66 minVal.resize(3);
67 maxVal.resize(3);
68 if (Extents.size() == 2) {
69 for (size_t d = 0; d < 3; d++) {
70 minVal[d] = Extents[0];
71 maxVal[d] = Extents[1];
72 }
73 } else if (Extents.size() == 6) {
74 for (size_t d = 0; d < 3; d++) {
75 minVal[d] = Extents[2 * d + 0];
76 maxVal[d] = Extents[2 * d + 1];
77 }
78 } else if (Extents.empty()) {
79 calculateExtentsFromData(minVal, maxVal);
80 } else
81 throw std::invalid_argument("You must specify either 2 or 6 extents (min,max).");
82}
83
90 std::vector<double> &maxVal) {
91 auto alg = createChildAlgorithm("ConvertToMDMinMaxLocal");
92 alg->initialize();
93 alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", getProperty("InputWorkspace"));
94 alg->setPropertyValue("QDimensions", "Q3D");
95 std::vector<std::string> dE_modes = Kernel::DeltaEMode::availableTypes();
96 alg->setPropertyValue("dEAnalysisMode", dE_modes[Kernel::DeltaEMode::Elastic]);
97
98 std::string TargetFrame, Scaling;
99 convertFramePropertyNames(getPropertyValue("OutputDimensions"), TargetFrame, Scaling);
100 alg->setProperty("Q3DFrames", TargetFrame);
101 alg->setProperty("QConversionScales", Scaling);
102
103 alg->execute();
104
105 minVal = alg->getProperty("MinValues");
106 maxVal = alg->getProperty("MaxValues");
107
108 // If the calculation produced +/- infinity as one of the extents
109 // replace this with a more reasonable value.
110 const auto INF = std::numeric_limits<double>::infinity();
111 const auto MAX_DBL = std::numeric_limits<double>::max();
112 const auto DEFAULT_BOUND = 50.0;
113
114 std::replace(minVal.begin(), minVal.end(), -INF, -DEFAULT_BOUND);
115 std::replace(maxVal.begin(), maxVal.end(), INF, DEFAULT_BOUND);
116 std::replace(minVal.begin(), minVal.end(), MAX_DBL, -DEFAULT_BOUND);
117 std::replace(maxVal.begin(), maxVal.end(), -MAX_DBL, DEFAULT_BOUND);
118
119 // Increases bounds by a small margin and ensures they aren't too close to
120 // zero. This is to prevent events from being incorrectly discarded as out
121 // of bounds by calcMatrixCoord functions (or, if fixed there, later causing
122 // further issues in MDGridBox::calculateChildIndex due to events sitting
123 // on maximum boundaries)
124 for (size_t i = 0; i < maxVal.size(); ++i) {
125 minVal[i] *= (1 - 1.e-5 * boost::math::sign(minVal[i]));
126 if (fabs(minVal[i]) < 1.e-5)
127 minVal[i] = -1.e-5;
128 maxVal[i] *= (1 + 1.e-5 * boost::math::sign(maxVal[i]));
129 if (fabs(maxVal[i]) < 1.e-5)
130 maxVal[i] = 1.e-5;
131 }
132}
133
134} // namespace Mantid::MDAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#define fabs(x)
Definition: Matrix.cpp:22
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
void init() override
Initialize the algorithm's properties.
void convertFramePropertyNames(const std::string &TargFrame, std::string &TargFrameName, std::string &ScalingName)
method to convert the value of the target frame specified for the ConvertToDiffractionMDWorksapce int...
ConvertToDiffractionMDWorkspace3 : Create a MDEventWorkspace with events in reciprocal space (Qx,...
void convertExtents(const std::vector< double > &Extents, std::vector< double > &minVal, std::vector< double > &maxVal) override
Splits extents accepted by convertToDiffreactionMD workspace in the form min1,max1 or min1,...
void calculateExtentsFromData(std::vector< double > &minVal, std::vector< double > &maxVal)
Calculate the extents to use for the conversion from the input workspace.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
TargetFrame
enum describes availible target coordinate systems for Q3D mode
Definition: MDWSTransform.h:40
static const std::vector< std::string > availableTypes()
Returns the string list of available modes.
Definition: DeltaEMode.cpp:35