Mantid
Loading...
Searching...
No Matches
BaseConvertToDiffractionMDWorkspace.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 <algorithm>
24#include <limits>
25
26using namespace Mantid::API;
27using namespace Mantid::Kernel;
28using namespace Mantid::DataObjects;
29using namespace Mantid::Geometry;
30
31namespace Mantid::MDAlgorithms {
32
35public:
36 DisabledProperty() : EnabledWhenProperty("NonExistingProperty", IS_DEFAULT) {}
37 bool checkCriterion(const IPropertyManager * /*algo*/) const override { return false; }
38};
39
40//----------------------------------------------------------------------------------------------
44
45 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
46 "An input workspace.");
47
48 declareProperty(std::make_unique<WorkspaceProperty<IMDEventWorkspace>>("OutputWorkspace", "", Direction::Output),
49 "Name of the output MDEventWorkspace. If the workspace "
50 "already exists, then the events will be added to it.");
51 declareProperty(std::make_unique<PropertyWithValue<bool>>("Append", false, Direction::Input),
52 "Append events to the output workspace. The workspace is replaced if "
53 "unchecked.");
54
55 // Disabled for this version
56 declareProperty(std::make_unique<PropertyWithValue<bool>>("ClearInputWorkspace", false, Direction::Input),
57 "Clearing the events from the input workspace during "
58 "conversion (to save memory) is not supported by algorithm "
59 "v2");
60 // disable property on interface
61 this->setPropertySettings("ClearInputWorkspace", std::make_unique<DisabledProperty>());
62
63 declareProperty(std::make_unique<PropertyWithValue<bool>>("OneEventPerBin", true, Direction::Input),
64 "Use the histogram representation (event for event workspaces).\n"
65 "One MDEvent will be created for each histogram bin (even empty ones).\n"
66 "Warning! This can use significantly more memory!");
67
68 frameOptions.emplace_back("Q (sample frame)");
69 frameOptions.emplace_back("Q (lab frame)");
70 frameOptions.emplace_back("HKL");
71 declareProperty("OutputDimensions", "Q (lab frame)", std::make_shared<StringListValidator>(frameOptions),
72 "What will be the dimensions of the output workspace?\n"
73 " Q (lab frame): Wave-vector change of the lattice in the lab frame.\n"
74 " Q (sample frame): Wave-vector change of the lattice in the frame of "
75 "the sample (taking out goniometer rotation).\n"
76 " HKL: Use the sample's UB matrix to convert to crystal's HKL indices.");
77
78 declareProperty(std::make_unique<PropertyWithValue<bool>>("LorentzCorrection", false, Direction::Input),
79 "Correct the weights of events by multiplying by the Lorentz "
80 "formula: sin(theta)^2 / lambda^4");
81
82 // Box controller properties. These are the defaults
83 this->initBoxControllerProps("2" /*SplitInto*/, 1500 /*SplitThreshold*/, 20 /*MaxRecursionDepth*/);
84
85 declareProperty(std::make_unique<PropertyWithValue<int>>("MinRecursionDepth", 1),
86 "Optional. If specified, then all the boxes will be split to this "
87 "minimum recursion depth. 1 = one level of splitting, etc.\n"
88 "Be careful using this since it can quickly create a huge number of "
89 "boxes = (SplitInto ^ (MinRercursionDepth * NumDimensions)).\n"
90 "But setting this property equal to MaxRecursionDepth property is "
91 "necessary if one wants to generate multiple file based workspaces in "
92 "order to merge them later\n");
93 setPropertyGroup("MinRecursionDepth", getBoxSettingsGroupName());
94}
95
106 std::string &TargFrameName,
107 std::string &ScalingName) {
108 // ----------------- Handle the type of output
109 // -------------------------------------
110
111 MDAlgorithms::MDWSTransform QSclAndFrames;
112
113 if (TargFrame == frameOptions[0]) // "Q (sample frame)"
114 {
115 TargFrameName = QSclAndFrames.getTargetFrame(MDAlgorithms::CnvrtToMD::SampleFrame);
116 ScalingName = QSclAndFrames.getQScaling(MDAlgorithms::CnvrtToMD::NoScaling); //< momentums in A^-1
117 } else if (TargFrame == frameOptions[1]) // "Q (lab frame)"
118 {
119 TargFrameName = QSclAndFrames.getTargetFrame(MDAlgorithms::CnvrtToMD::LabFrame);
120 ScalingName = QSclAndFrames.getQScaling(MDAlgorithms::CnvrtToMD::NoScaling); //< momentums in A^-1
121 } else if (TargFrame == frameOptions[2]) // "HKL"
122 {
123 TargFrameName = QSclAndFrames.getTargetFrame(MDAlgorithms::CnvrtToMD::HKLFrame);
124 ScalingName = QSclAndFrames.getQScaling(MDAlgorithms::CnvrtToMD::HKLScale); //< momentums in A^-1
125 } else {
126 throw std::invalid_argument("BaseConvertToDiffractionMDWorkspace::Unknown target frame: " + TargFrame);
127 }
128}
129
130//----------------------------------------------------------------------------------------------
133
134 Mantid::API::Algorithm_sptr Convert = createChildAlgorithm("ConvertToMD", 0., 1.);
135 Convert->initialize();
136
137 Convert->setRethrows(true);
138 Convert->initialize();
139
140 Convert->setProperty<MatrixWorkspace_sptr>("InputWorkspace", this->getProperty("InputWorkspace"));
141 Convert->setProperty("OutputWorkspace", this->getPropertyValue("OutputWorkspace"));
142 Convert->setProperty("OverwriteExisting", !this->getProperty("Append"));
143
144 if (!MDTransfFactory::Instance().exists("Q3D")) {
145 throw std::runtime_error(" ConvertToMD Q3D plugin used to transform into "
146 "DiffractionWorkspaced has not been registered "
147 "with the MDTransformation factory");
148 }
149 Convert->setPropertyValue("QDimensions", "Q3D");
150
151 std::vector<std::string> dE_modes = Kernel::DeltaEMode::availableTypes();
152 Convert->setPropertyValue("dEAnalysisMode", dE_modes[Kernel::DeltaEMode::Elastic]);
153
154 std::string TargetFrame, Scaling;
155 this->convertFramePropertyNames(this->getPropertyValue("OutputDimensions"), TargetFrame, Scaling);
156 Convert->setProperty("Q3DFrames", TargetFrame);
157 Convert->setProperty("QConversionScales", Scaling);
158
159 Convert->setProperty("OtherDimensions", "");
160 Convert->setProperty("PreprocDetectorsWS", "-");
161
162 bool lorCorr = this->getProperty("LorentzCorrection");
163 Convert->setProperty("LorentzCorrection", lorCorr);
164
165 bool ignoreZeros = !this->getProperty("OneEventPerBin");
166 Convert->setProperty("IgnoreZeroSignals", ignoreZeros);
167 // set extents
168 std::vector<double> extents = this->getProperty("Extents");
169 std::vector<double> minVal, maxVal;
170 convertExtents(extents, minVal, maxVal);
171 Convert->setProperty("MinValues", minVal);
172 Convert->setProperty("MaxValues", maxVal);
173
174 // Box controller properties. Has defaults
175 Convert->setProperty("SplitInto", this->getPropertyValue("SplitInto"));
176 Convert->setProperty("SplitThreshold", this->getPropertyValue("SplitThreshold"));
177 Convert->setProperty("MaxRecursionDepth", this->getPropertyValue("MaxRecursionDepth"));
178 std::string depth = this->getPropertyValue("MinRecursionDepth");
179 if (depth == "0")
180 depth = "1"; // ConvertToMD does not understand 0 depth
181 Convert->setProperty("MinRecursionDepth", depth);
182
183 Convert->executeAsChildAlg();
184
185 IMDEventWorkspace_sptr iOut = Convert->getProperty("OutputWorkspace");
186 this->setProperty("OutputWorkspace", iOut);
187}
188
189} // namespace Mantid::MDAlgorithms
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
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.
void initBoxControllerProps(const std::string &SplitInto="5", int SplitThreshold=1000, int MaxRecursionDepth=5)
Initialise the properties.
A property class for workspaces.
Interface to PropertyManager.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
The concrete, templated class for 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...
virtual void convertExtents(const std::vector< double > &Extents, std::vector< double > &minVal, std::vector< double > &maxVal)=0
Small class to diable propery on interface.
bool checkCriterion(const IPropertyManager *) const override
Checks that the specified property matches the criteria given.
CnvrtToMD::CoordScaling getQScaling(const std::string &ScID) const
function which convert input string representing coordinate scaling to correspondent enum
CnvrtToMD::TargetFrame getTargetFrame(const std::string &FrameID) const
converts the target frame string representation into the frame ID
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Definition Algorithm.h:52
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
TargetFrame
enum describes availible target coordinate systems for Q3D mode
static const std::vector< std::string > availableTypes()
Returns the string list of available modes.
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54