31 "List or group of MatrixWorkspaces");
34 "Stitched workspace.");
38 "Rebinning Parameters, see Rebin algorithm for format.");
41 "Start overlaps for stitched workspaces "
42 "(number of input workspaces minus one).");
45 "End overlaps for stitched workspaces "
46 "(number of input workspaces minus one).");
50 "Scaling either with respect to first (first hand side, LHS) "
51 "or second (right hand side, RHS) workspace. "
52 "This property no longer has an effect, please use the IndexOfReference property instead.");
54 setPropertySettings(
"ScaleRHSWorkspace", std::make_unique<InvisibleProperty>());
57 "True to use provided values for the scale factor.");
60 "Either a single scale factor which will be applied to all "
61 "input workspaces or individual scale factors "
62 "(number of input workspaces minus one)");
63 setPropertySettings(
"ManualScaleFactors",
64 std::make_unique<VisibleWhenProperty>(
"UseManualScaleFactors",
IS_EQUAL_TO,
"1"));
67 "The actual used values for the scaling factors at each stitch step.");
69 auto scaleFactorFromPeriodValidator = std::make_shared<BoundedValidator<int>>();
70 scaleFactorFromPeriodValidator->setLower(1);
71 declareProperty(std::make_unique<
PropertyWithValue<int>>(
"ScaleFactorFromPeriod", 1, scaleFactorFromPeriodValidator,
73 "Provided index of period to obtain scale factor from; "
74 "periods are indexed from 1 and used only if stitching group "
75 "workspaces, UseManualScaleFactors is true and "
76 "ManualScaleFactors is set to default.");
80 auto scaleFactorFromPeriodVisible =
81 std::make_unique<VisibleWhenProperty>(useManualScaleFactorsTrue, manualScaleFactorsDefault,
AND);
83 setPropertySettings(
"ScaleFactorFromPeriod", std::move(scaleFactorFromPeriodVisible));
85 auto indexValidator = std::make_shared<BoundedValidator<int>>();
86 indexValidator->setLower(-1);
87 declareProperty(
"IndexOfReference", 0, indexValidator,
88 "Index of the workspace to be used as reference for scaling, or -1 to choose the last workspace as "
94 std::map<std::string, std::string> issues;
95 const std::vector<std::string> inputWorkspacesStr = this->
getProperty(
"InputWorkspaces");
96 if (inputWorkspacesStr.size() < 2)
97 issues[
"InputWorkspaces"] =
"Nothing to stitch";
107 std::vector<MatrixWorkspace_sptr> column;
108 for (
const auto &ws : inputWorkspacesStr) {
111 for (
size_t i = 0; i < groupWS->size(); i++) {
112 auto inputMatrix = std::dynamic_pointer_cast<MatrixWorkspace>(groupWS->getItem(i));
114 column.emplace_back(inputMatrix);
116 issues[
"InputWorkspaces"] =
"Input workspace " + ws +
" must be a MatrixWorkspace";
122 column.emplace_back(inputMatrix);
129 issues[
"IndexOfReference"] =
"The index of reference workspace is larger than the number of "
130 "provided workspaces.";
138 for (
const auto &ws : column) {
141 if (!compatible.empty()) {
142 if (!(compatible ==
"spectra must have either Dx values or not; ") ||
143 (ws->isHistogramData()))
144 issues[
"RHSWorkspace"] =
"Workspace " + ws->getName() +
" is not compatible: " + compatible +
"\n";
149 issues[
"InputWorkspaces"] =
"All input workspaces must be groups";
155 issues[
"InputWorkspaces"] =
"Size mismatch of group workspaces";
161 if (!compatible.empty())
162 issues[
"InputWorkspaces"] =
163 "Workspace " + ws[spec]->
getName() +
" is not compatible: " + compatible +
"\n";
167 int scaleFactorFromPeriod = this->
getProperty(
"ScaleFactorFromPeriod");
171 std::stringstream expectedRange;
173 issues[
"ScaleFactorFromPeriod"] =
"Period index out of range, must be smaller than " + expectedRange.str();
182 size_t numStitchableWS =
183 (workspaces.size() == inputWorkspacesStr.size()) ? workspaces.size() : inputWorkspacesStr.size();
184 std::stringstream expectedVal;
185 expectedVal << numStitchableWS - 1;
187 issues[
"StartOverlaps"] =
"Expected " + expectedVal.str() +
" value(s)";
190 issues[
"EndOverlaps"] =
"EndOverlaps must have the same number of "
191 "entries as StartOverlaps.";
201 if ((numStitchableWS - 1) == 1)
202 issues[
"ManualScaleFactors"] =
"Must be a single value";
204 issues[
"ManualScaleFactors"] =
205 "Must be a single value for all input workspaces or " + expectedVal.str() +
" values";
209 issues[
"ManualScaleFactors"] =
"Must contain scale factors";
211 }
catch (
const std::exception &e) {
212 issues[
"InputWorkspaces"] = std::string(e.what());
221 g_log.
warning(
"The ScaleRHSWorkspace property no longer has any effect. Please see documentation on the "
222 "IndexOfReference parameter and use that instead.");
226 std::vector<std::string> toGroup;
227 std::string groupName = this->
getProperty(
"OutputWorkspace");
233 if (!usingScaleFromPeriod) {
237 std::vector<double> scaleFactors;
241 toGroup.emplace_back(outName);
248 std::string tempOutName;
249 std::vector<double> periodScaleFactors;
250 constexpr bool storeInADS =
false;
256 std::vector<MatrixWorkspace_sptr> inMatrix;
260 [i](
const auto &ws) { return ws[i]; });
264 doStitch1D(inMatrix, periodScaleFactors, outStitchedWS, outName);
266 toGroup.emplace_back(outName);
272 groupAlg->initialize();
273 groupAlg->setAlwaysStoreInADS(
true);
274 groupAlg->setProperty(
"InputWorkspaces", toGroup);
275 groupAlg->setProperty(
"OutputWorkspace", groupName);
280 std::string tempOutName;
295 const std::vector<double> &manualScaleFactors,
Workspace_sptr &outWS,
296 std::string &outName) {
298 auto lhsWS = toStitch.front();
299 outName +=
"_" + lhsWS->getName();
303 for (
size_t i = 1; i < toStitch.size(); i++) {
304 auto rhsWS = toStitch[i];
305 outName +=
"_" + rhsWS->getName();
307 auto scaleRHSWorkspace = i > indexOfReference;
311 alg->setProperty(
"LHSWorkspace", lhsWS);
312 alg->setProperty(
"RHSWorkspace", rhsWS);
317 alg->setProperty(
"Params",
m_params);
318 alg->setProperty(
"ScaleRHSWorkspace", scaleRHSWorkspace);
321 alg->setProperty(
"ManualScaleFactor", manualScaleFactors[i - 1]);
324 lhsWS = alg->getProperty(
"OutputWorkspace");
325 double outScaleFactor = alg->getProperty(
"OutScaleFactor");
331 for (
const auto &inputWS : toStitch) {
332 lhsWS->history().addHistory(inputWS->getHistory());
350 std::vector<double> &outScaleFactors,
const int indexOfReference,
351 const bool storeInADS) {
354 std::vector<std::string> toProcess;
357 const std::string &wsName = ws[period]->getName();
358 toProcess.emplace_back(wsName);
359 outName +=
"_" + wsName;
364 alg->setAlwaysStoreInADS(storeInADS);
365 alg->setProperty(
"InputWorkspaces", toProcess);
366 if (!outName.empty())
367 alg->setProperty(
"OutputWorkspace", outName);
370 alg->setProperty(
"Params",
m_params);
371 alg->setProperty(
"UseManualScaleFactors", useManualScaleFactors);
372 if (useManualScaleFactors)
374 alg->setProperty(
"IndexOfReference", indexOfReference);
377 outScaleFactors = alg->getProperty(
"OutScaleFactors");
#define DECLARE_ALGORITHM(classname)
std::string getName(const IMDDimension &self)
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.
bool isChild() const override
To query whether algorithm is a child.
bool isDefault(const std::string &name) const
Base MatrixWorkspace Abstract Class.
Class to hold a set of workspaces.
A property class for workspaces.
Base Workspace Abstract Class.
static std::vector< std::string > unWrapGroups(const std::vector< std::string > &)
Flattens the list of group workspaces (if any) into list of workspaces.
void setReferenceProperties(const API::MatrixWorkspace_sptr &)
Sets the properties of the reference (usually first) workspace, to later check the compatibility of t...
std::string checkCompatibility(const API::MatrixWorkspace_sptr &, bool checkNumberHistograms=false)
Compares the properties of the input workspace with the reference.
Stitch1DMany : Stitches multiple Matrix Workspaces together into a single output.
void exec() override
Overwrites Algorithm method.
bool m_useManualScaleFactors
std::vector< double > m_scaleFactors
std::vector< std::vector< API::MatrixWorkspace_sptr > > m_inputWSMatrix
std::vector< double > m_params
void doStitch1D(std::vector< API::MatrixWorkspace_sptr > &toStitch, const std::vector< double > &manualScaleFactors, API::Workspace_sptr &outWS, std::string &outName)
Performs the Stitch1D algorithm at a specific workspace index.
API::Workspace_sptr m_outputWorkspace
std::vector< double > m_endOverlaps
size_t m_scaleFactorFromPeriod
std::vector< double > m_startOverlaps
std::map< std::string, std::string > validateInputs() override
Validates algorithm inputs.
std::vector< double > m_manualScaleFactors
void doStitch1DMany(const size_t period, const bool useManualScaleFactors, std::string &outName, std::vector< double > &outScaleFactors, const int indexOfReference, const bool storeInADS=true)
Performs the Stitch1DMany algorithm at a specific period.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
OptionalBool : Tri-state bool.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Same as EnabledWhenProperty, but returns the value for the isVisible() property instead of the isEnab...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
@ Input
An input workspace.
@ Output
An output workspace.