31 "List or group of MatrixWorkspaces");
34 "Stitched workspace.");
37 "Optional suffixes to use for child output workspaces when stitching workspace groups. "
38 "The default is to use 1-based numeric suffixes.");
42 "Rebinning Parameters, see Rebin algorithm for format.");
45 "Start overlaps for stitched workspaces "
46 "(number of input workspaces minus one).");
49 "End overlaps for stitched workspaces "
50 "(number of input workspaces minus one).");
55 "Scaling either with respect to first (first hand side, LHS) "
56 "or second (right hand side, RHS) workspace. "
57 "This property no longer has an effect, please use the IndexOfReference property instead.");
59 setPropertySettings(
"ScaleRHSWorkspace", std::make_unique<InvisibleProperty>());
62 "True to use provided values for the scale factor.");
65 "Either a single scale factor which will be applied to all "
66 "input workspaces or individual scale factors "
67 "(number of input workspaces minus one)");
68 setPropertySettings(
"ManualScaleFactors",
69 std::make_unique<VisibleWhenProperty>(
"UseManualScaleFactors",
IS_EQUAL_TO,
"1"));
72 "The actual used values for the scaling factors at each stitch step.");
74 auto scaleFactorFromPeriodValidator = std::make_shared<BoundedValidator<int>>();
75 scaleFactorFromPeriodValidator->setLower(1);
76 declareProperty(std::make_unique<
PropertyWithValue<int>>(
"ScaleFactorFromPeriod", 1, scaleFactorFromPeriodValidator,
78 "Provided index of period to obtain scale factor from; "
79 "periods are indexed from 1 and used only if stitching group "
80 "workspaces, UseManualScaleFactors is true and "
81 "ManualScaleFactors is set to default.");
85 auto scaleFactorFromPeriodVisible =
86 std::make_unique<VisibleWhenProperty>(useManualScaleFactorsTrue, manualScaleFactorsDefault,
AND);
88 setPropertySettings(
"ScaleFactorFromPeriod", std::move(scaleFactorFromPeriodVisible));
90 auto indexValidator = std::make_shared<BoundedValidator<int>>();
91 indexValidator->setLower(-1);
92 declareProperty(
"IndexOfReference", 0, indexValidator,
93 "Index of the workspace to be used as reference for scaling, or -1 to choose the last workspace as "
97 "If true, invalid signal values do not contribute to overlap bins where another workspace has valid "
103 std::map<std::string, std::string> issues;
104 const std::vector<std::string> inputWorkspacesStr = this->
getProperty(
"InputWorkspaces");
105 if (inputWorkspacesStr.size() < 2)
106 issues[
"InputWorkspaces"] =
"Nothing to stitch";
120 std::vector<MatrixWorkspace_sptr> column;
121 for (
const auto &ws : inputWorkspacesStr) {
122 auto groupWS = AnalysisDataService::Instance().retrieveWS<
WorkspaceGroup>(ws);
124 for (
size_t i = 0; i < groupWS->size(); i++) {
125 auto inputMatrix = std::dynamic_pointer_cast<MatrixWorkspace>(groupWS->getItem(i));
127 column.emplace_back(inputMatrix);
129 issues[
"InputWorkspaces"] =
"Input workspace " + ws +
" must be a MatrixWorkspace";
134 auto inputMatrix = AnalysisDataService::Instance().retrieveWS<
MatrixWorkspace>(ws);
135 column.emplace_back(inputMatrix);
142 issues[
"IndexOfReference"] =
"The index of reference workspace is larger than the number of "
143 "provided workspaces.";
149 if (!
isDefault(
"OutputWorkspaceSuffixes"))
150 issues[
"OutputWorkspaceSuffixes"] =
"OutputWorkspaceSuffixes can only be used with group workspaces";
153 for (
const auto &ws : column) {
156 if (!compatible.empty()) {
157 if (!(compatible ==
"spectra must have either Dx values or not; ") ||
158 (ws->isHistogramData()))
159 issues[
"RHSWorkspace"] =
"Workspace " + ws->getName() +
" is not compatible: " + compatible +
"\n";
164 issues[
"InputWorkspaces"] =
"All input workspaces must be groups";
170 issues[
"OutputWorkspaceSuffixes"] =
173 issues[
"OutputWorkspaceSuffixes"] =
"Suffixes must be unique";
180 issues[
"InputWorkspaces"] =
"Size mismatch of group workspaces";
186 if (!compatible.empty())
187 issues[
"InputWorkspaces"] =
188 "Workspace " + ws[spec]->
getName() +
" is not compatible: " + compatible +
"\n";
192 int scaleFactorFromPeriod = this->
getProperty(
"ScaleFactorFromPeriod");
196 std::stringstream expectedRange;
198 issues[
"ScaleFactorFromPeriod"] =
"Period index out of range, must be smaller than " + expectedRange.str();
207 size_t numStitchableWS =
208 (workspaces.size() == inputWorkspacesStr.size()) ? workspaces.size() : inputWorkspacesStr.size();
209 std::stringstream expectedVal;
210 expectedVal << numStitchableWS - 1;
212 issues[
"StartOverlaps"] =
"Expected " + expectedVal.str() +
" value(s)";
215 issues[
"EndOverlaps"] =
"EndOverlaps must have the same number of "
216 "entries as StartOverlaps.";
227 if ((numStitchableWS - 1) == 1)
228 issues[
"ManualScaleFactors"] =
"Must be a single value";
230 issues[
"ManualScaleFactors"] =
231 "Must be a single value for all input workspaces or " + expectedVal.str() +
" values";
235 issues[
"ManualScaleFactors"] =
"Must contain scale factors";
237 }
catch (
const std::exception &e) {
238 issues[
"InputWorkspaces"] = std::string(e.what());
247 g_log.
warning(
"The ScaleRHSWorkspace property no longer has any effect. Please see documentation on the "
248 "IndexOfReference parameter and use that instead.");
253 std::vector<std::string> toGroup;
254 std::string groupName = this->
getProperty(
"OutputWorkspace");
260 if (!usingScaleFromPeriod) {
264 std::vector<double> scaleFactors;
267 toGroup.emplace_back(outName);
274 std::string tempOutName;
275 std::vector<double> periodScaleFactors;
276 constexpr bool storeInADS =
false;
282 std::vector<MatrixWorkspace_sptr> inMatrix;
286 [i](
const auto &ws) { return ws[i]; });
289 doStitch1D(inMatrix, periodScaleFactors, outStitchedWS);
292 toGroup.emplace_back(outName);
293 AnalysisDataService::Instance().addOrReplace(outName, outStitchedWS);
298 groupAlg->initialize();
299 groupAlg->setAlwaysStoreInADS(
true);
300 groupAlg->setProperty(
"InputWorkspaces", toGroup);
301 groupAlg->setProperty(
"OutputWorkspace", groupName);
319 const std::vector<double> &manualScaleFactors,
Workspace_sptr &outWS) {
321 auto &lhsWS = toStitch.front();
325 for (
size_t i = 1; i < toStitch.size(); i++) {
326 auto rhsWS = toStitch[i];
328 auto scaleRHSWorkspace = i > indexOfReference;
332 alg->setProperty(
"LHSWorkspace", lhsWS);
333 alg->setProperty(
"RHSWorkspace", rhsWS);
338 alg->setProperty(
"Params",
m_params);
339 alg->setProperty(
"ScaleRHSWorkspace", scaleRHSWorkspace);
343 alg->setProperty(
"ManualScaleFactor", manualScaleFactors[i - 1]);
346 lhsWS = alg->getProperty(
"OutputWorkspace");
347 double outScaleFactor = alg->getProperty(
"OutScaleFactor");
353 for (
const auto &inputWS : toStitch) {
354 lhsWS->history().addHistory(inputWS->getHistory());
372 std::vector<double> &outScaleFactors,
const int indexOfReference,
373 const bool storeInADS) {
376 std::vector<std::string> toProcess;
379 const std::string &wsName = ws[period]->getName();
380 toProcess.emplace_back(wsName);
387 alg->setAlwaysStoreInADS(storeInADS);
388 alg->setProperty(
"InputWorkspaces", toProcess);
389 if (!outName.empty())
390 alg->setProperty(
"OutputWorkspace", outName);
393 alg->setProperty(
"Params",
m_params);
394 alg->setProperty(
"UseManualScaleFactors", useManualScaleFactors);
396 if (useManualScaleFactors)
398 alg->setProperty(
"IndexOfReference", indexOfReference);
401 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
API::Workspace_sptr m_outputWorkspace
std::vector< double > m_endOverlaps
size_t m_scaleFactorFromPeriod
std::vector< std::string > m_outputWorkspaceSuffixes
void doStitch1D(std::vector< API::MatrixWorkspace_sptr > &toStitch, const std::vector< double > &manualScaleFactors, API::Workspace_sptr &outWS)
Performs the Stitch1D algorithm at a specific workspace index.
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.
std::string createChildWorkspaceName(const std::string &groupName, const size_t periodIndex)
Creates a correctly formatted name for a stitched child workspace in a workspace group.
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.
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
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.