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).");
51 "Scaling either with respect to first (first hand side, LHS) "
52 "or second (right hand side, RHS) workspace. "
53 "This property no longer has an effect, please use the IndexOfReference property instead.");
55 setPropertySettings(
"ScaleRHSWorkspace", std::make_unique<InvisibleProperty>());
58 "True to use provided values for the scale factor.");
61 "Either a single scale factor which will be applied to all "
62 "input workspaces or individual scale factors "
63 "(number of input workspaces minus one)");
64 setPropertySettings(
"ManualScaleFactors",
65 std::make_unique<VisibleWhenProperty>(
"UseManualScaleFactors",
IS_EQUAL_TO,
"1"));
68 "The actual used values for the scaling factors at each stitch step.");
70 auto scaleFactorFromPeriodValidator = std::make_shared<BoundedValidator<int>>();
71 scaleFactorFromPeriodValidator->setLower(1);
72 declareProperty(std::make_unique<
PropertyWithValue<int>>(
"ScaleFactorFromPeriod", 1, scaleFactorFromPeriodValidator,
74 "Provided index of period to obtain scale factor from; "
75 "periods are indexed from 1 and used only if stitching group "
76 "workspaces, UseManualScaleFactors is true and "
77 "ManualScaleFactors is set to default.");
81 auto scaleFactorFromPeriodVisible =
82 std::make_unique<VisibleWhenProperty>(useManualScaleFactorsTrue, manualScaleFactorsDefault,
AND);
84 setPropertySettings(
"ScaleFactorFromPeriod", std::move(scaleFactorFromPeriodVisible));
86 auto indexValidator = std::make_shared<BoundedValidator<int>>();
87 indexValidator->setLower(-1);
88 declareProperty(
"IndexOfReference", 0, indexValidator,
89 "Index of the workspace to be used as reference for scaling, or -1 to choose the last workspace as "
95 std::map<std::string, std::string> issues;
96 const std::vector<std::string> inputWorkspacesStr = this->
getProperty(
"InputWorkspaces");
97 if (inputWorkspacesStr.size() < 2)
98 issues[
"InputWorkspaces"] =
"Nothing to stitch";
112 std::vector<MatrixWorkspace_sptr> column;
113 for (
const auto &ws : inputWorkspacesStr) {
114 auto groupWS = AnalysisDataService::Instance().retrieveWS<
WorkspaceGroup>(ws);
116 for (
size_t i = 0; i < groupWS->size(); i++) {
117 auto inputMatrix = std::dynamic_pointer_cast<MatrixWorkspace>(groupWS->getItem(i));
119 column.emplace_back(inputMatrix);
121 issues[
"InputWorkspaces"] =
"Input workspace " + ws +
" must be a MatrixWorkspace";
126 auto inputMatrix = AnalysisDataService::Instance().retrieveWS<
MatrixWorkspace>(ws);
127 column.emplace_back(inputMatrix);
134 issues[
"IndexOfReference"] =
"The index of reference workspace is larger than the number of "
135 "provided workspaces.";
143 for (
const auto &ws : column) {
146 if (!compatible.empty()) {
147 if (!(compatible ==
"spectra must have either Dx values or not; ") ||
148 (ws->isHistogramData()))
149 issues[
"RHSWorkspace"] =
"Workspace " + ws->getName() +
" is not compatible: " + compatible +
"\n";
154 issues[
"InputWorkspaces"] =
"All input workspaces must be groups";
160 issues[
"InputWorkspaces"] =
"Size mismatch of group workspaces";
166 if (!compatible.empty())
167 issues[
"InputWorkspaces"] =
168 "Workspace " + ws[spec]->
getName() +
" is not compatible: " + compatible +
"\n";
172 int scaleFactorFromPeriod = this->
getProperty(
"ScaleFactorFromPeriod");
176 std::stringstream expectedRange;
178 issues[
"ScaleFactorFromPeriod"] =
"Period index out of range, must be smaller than " + expectedRange.str();
187 size_t numStitchableWS =
188 (workspaces.size() == inputWorkspacesStr.size()) ? workspaces.size() : inputWorkspacesStr.size();
189 std::stringstream expectedVal;
190 expectedVal << numStitchableWS - 1;
192 issues[
"StartOverlaps"] =
"Expected " + expectedVal.str() +
" value(s)";
195 issues[
"EndOverlaps"] =
"EndOverlaps must have the same number of "
196 "entries as StartOverlaps.";
206 if ((numStitchableWS - 1) == 1)
207 issues[
"ManualScaleFactors"] =
"Must be a single value";
209 issues[
"ManualScaleFactors"] =
210 "Must be a single value for all input workspaces or " + expectedVal.str() +
" values";
214 issues[
"ManualScaleFactors"] =
"Must contain scale factors";
216 }
catch (
const std::exception &e) {
217 issues[
"InputWorkspaces"] = std::string(e.what());
226 g_log.
warning(
"The ScaleRHSWorkspace property no longer has any effect. Please see documentation on the "
227 "IndexOfReference parameter and use that instead.");
231 std::vector<std::string> toGroup;
232 std::string groupName = this->
getProperty(
"OutputWorkspace");
238 if (!usingScaleFromPeriod) {
242 std::vector<double> scaleFactors;
245 toGroup.emplace_back(outName);
252 std::string tempOutName;
253 std::vector<double> periodScaleFactors;
254 constexpr bool storeInADS =
false;
260 std::vector<MatrixWorkspace_sptr> inMatrix;
264 [i](
const auto &ws) { return ws[i]; });
267 doStitch1D(inMatrix, periodScaleFactors, outStitchedWS);
270 toGroup.emplace_back(outName);
271 AnalysisDataService::Instance().addOrReplace(outName, outStitchedWS);
276 groupAlg->initialize();
277 groupAlg->setAlwaysStoreInADS(
true);
278 groupAlg->setProperty(
"InputWorkspaces", toGroup);
279 groupAlg->setProperty(
"OutputWorkspace", groupName);
297 const std::vector<double> &manualScaleFactors,
Workspace_sptr &outWS) {
299 auto &lhsWS = toStitch.front();
303 for (
size_t i = 1; i < toStitch.size(); i++) {
304 auto rhsWS = toStitch[i];
306 auto scaleRHSWorkspace = i > indexOfReference;
310 alg->setProperty(
"LHSWorkspace", lhsWS);
311 alg->setProperty(
"RHSWorkspace", rhsWS);
316 alg->setProperty(
"Params",
m_params);
317 alg->setProperty(
"ScaleRHSWorkspace", scaleRHSWorkspace);
320 alg->setProperty(
"ManualScaleFactor", manualScaleFactors[i - 1]);
323 lhsWS = alg->getProperty(
"OutputWorkspace");
324 double outScaleFactor = alg->getProperty(
"OutScaleFactor");
330 for (
const auto &inputWS : toStitch) {
331 lhsWS->history().addHistory(inputWS->getHistory());
349 std::vector<double> &outScaleFactors,
const int indexOfReference,
350 const bool storeInADS) {
353 std::vector<std::string> toProcess;
356 const std::string &wsName = ws[period]->getName();
357 toProcess.emplace_back(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
API::Workspace_sptr m_outputWorkspace
std::vector< double > m_endOverlaps
size_t m_scaleFactorFromPeriod
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.