Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MANTID_CURVEFITTING_DLL PlotPeakByLogValue final : public API::Algorithm {
void setWorkspaceIndexAttribute(const API::IFunction_sptr &fun, int wsIndex) const;

std::shared_ptr<Algorithm> runSingleFit(bool createFitOutput, bool outputCompositeMembers,
bool outputConvolvedMembers, const API::IFunction_sptr &ifun,
bool outputConvolvedMembers, bool appendIdx, const API::IFunction_sptr &ifun,
const InputSpectraToFit &data, double startX, double endX,
const std::string &exclude);

Expand All @@ -79,10 +79,20 @@ class MANTID_CURVEFITTING_DLL PlotPeakByLogValue final : public API::Algorithm {
void appendTableRow(bool isDataName, API::ITableWorkspace_sptr &result, const API::IFunction_sptr &ifun,
const InputSpectraToFit &data, double logValue, double chi2) const;

void finaliseOutputWorkspaces(bool createFitOutput, const std::vector<API::MatrixWorkspace_sptr> &fitWorkspaces,
void finaliseOutputWorkspacesWithAppend(const std::vector<std::string> &fitWorkspaces,
const std::vector<std::string> &parameterWorkspaces,
const std::vector<std::string> &covarianceWorkspaces,
const std::vector<InputSpectraToFit> &wsNames);

void finaliseOutputWorkspaces(const std::vector<API::MatrixWorkspace_sptr> &fitWorkspaces,
const std::vector<API::ITableWorkspace_sptr> &parameterWorkspaces,
const std::vector<API::ITableWorkspace_sptr> &covarianceWorkspaces);

void groupResParams(const std::vector<API::ITableWorkspace_sptr> &paramsWs,
const std::vector<std::string> &paramsNames);

void finaliseMinimizerOutput();

API::IFunction_sptr setupFunction(bool individual, bool passWSIndexToFunction,
const API::IFunction_sptr &inputFunction, const std::vector<double> &initialParams,
bool isMultiDomainFunction, int i, const InputSpectraToFit &data) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ namespace Algorithms {

struct InputSpectraToFit {
/// Constructor
InputSpectraToFit(const std::string &nam, int ix, int p) : name(nam), i(ix), period(p) {}
InputSpectraToFit(const std::string &nam, int ix, double isp, double iv, int p, API::MatrixWorkspace_sptr mws)
: name(nam), wsIdx(ix), spectrumNum(isp), numericValue(iv), period(p), ws(mws) {}
/// Copy constructor
InputSpectraToFit(const InputSpectraToFit &data) = default;

std::string name; ///< Name of a workspace or file
int i; ///< Workspace index of the spectra to fit
int wsIdx; ///< Workspace index of the spectra to fit
double spectrumNum; ///< Spectrum number of the spectra to fit
double numericValue; ///< Numerix axis value associated with the spectra to fit
int period; ///< Period, needed if a file contains several periods
API::MatrixWorkspace_sptr ws; ///< shared pointer to the workspace
};
/// Get a workspace
MANTID_CURVEFITTING_DLL std::vector<int> getWorkspaceIndicesFromAxes(const API::MatrixWorkspace &ws, int workspaceIndex,
int spectrumNumber, double start, double end);
MANTID_CURVEFITTING_DLL void appendInputSpectraToList(std::vector<InputSpectraToFit> &nameList, const std::string &name,
const std::shared_ptr<API::MatrixWorkspace> &ws,
int workspaceIndex, int spectrumNumber, double start, double end,
int period, const bool &workspaceOptional);
MANTID_CURVEFITTING_DLL std::optional<API::Workspace_sptr> getWorkspace(const std::string &name, int period);

/// Create a list of input workspace names
Expand Down
254 changes: 203 additions & 51 deletions Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp

Large diffs are not rendered by default.

62 changes: 28 additions & 34 deletions Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void parseValueRange(const std::string &index, double &start, double &end, int &

void addGroupWorkspace(std::vector<InputSpectraToFit> &nameList, double start, double end, int wi, int spec, int period,
const std::shared_ptr<API::WorkspaceGroup> &wsg);
void addMatrixworkspace(std::vector<InputSpectraToFit> &nameList, double start, double end, std::string &name, int wi,
int spec, int period, const std::optional<API::Workspace_sptr> &workspaceOptional,
void addMatrixworkspace(std::vector<InputSpectraToFit> &nameList, double start, double end, const std::string &name,
int wi, int spec, int period, const std::optional<API::Workspace_sptr> &workspaceOptional,
const std::shared_ptr<API::MatrixWorkspace> &wsMatrix);
/// Create a list of input workspace names
std::vector<InputSpectraToFit> makeNames(const std::string &inputList, int default_wi, int default_spec) {
Expand Down Expand Up @@ -119,17 +119,10 @@ std::vector<InputSpectraToFit> makeNames(const std::string &inputList, int defau
}
return nameList;
}
void addMatrixworkspace(std::vector<InputSpectraToFit> &nameList, double start, double end, std::string &name, int wi,
int spec, int period, const std::optional<API::Workspace_sptr> &workspaceOptional,
void addMatrixworkspace(std::vector<InputSpectraToFit> &nameList, double start, double end, const std::string &name,
int wi, int spec, int period, const std::optional<API::Workspace_sptr> &workspaceOptional,
const std::shared_ptr<API::MatrixWorkspace> &wsMatrix) {
auto workspaceIndices = getWorkspaceIndicesFromAxes(*wsMatrix, wi, spec, start, end);

for (auto workspaceIndex : workspaceIndices) {
nameList.emplace_back(name, workspaceIndex, period);
if (workspaceOptional) {
nameList.back().ws = wsMatrix;
}
}
appendInputSpectraToList(nameList, name, wsMatrix, wi, spec, start, end, period, workspaceOptional.has_value());
}
void addGroupWorkspace(std::vector<InputSpectraToFit> &nameList, double start, double end, int wi, int spec, int period,
const std::shared_ptr<API::WorkspaceGroup> &wsg) {
Expand All @@ -138,45 +131,47 @@ void addGroupWorkspace(std::vector<InputSpectraToFit> &nameList, double start, d
for (const auto &wsName : wsNames) {
if (auto workspace =
std::dynamic_pointer_cast<API::MatrixWorkspace>(API::AnalysisDataService::Instance().retrieve(wsName))) {
auto workspaceIndices = getWorkspaceIndicesFromAxes(*workspace, wi, spec, start, end);

for (auto workspaceIndex : workspaceIndices) {
nameList.emplace_back(wsName, workspaceIndex, period);
nameList.back().ws = workspace;
}
appendInputSpectraToList(nameList, wsName, workspace, wi, spec, start, end, period, true);
}
}
}

/** Get a workspace identified by an InputSpectraToFit structure.
* @param nameList :: List of spectra to fit
* @param name :: Workspace name
* @param ws :: Workspace to fit required to work out indices
* @param workspaceIndex :: workspace index to use
* @param spectrumNumber :: spectrum number to use
* @param start :: Start of range for value based spectrum range
* @param end :: End of range for value based spectrum range
* @return Vector of workspace indices to fit
* @param period :: Period if the file has several periods
* @param workspaceOptional :: Whether a workspace is present or not
*/
std::vector<int> getWorkspaceIndicesFromAxes(const API::MatrixWorkspace &ws, int workspaceIndex, int spectrumNumber,
double start, double end) {
void appendInputSpectraToList(std::vector<InputSpectraToFit> &nameList, const std::string &name,
const std::shared_ptr<API::MatrixWorkspace> &ws, int workspaceIndex, int spectrumNumber,
double start, double end, int period, const bool &workspaceOptional) {
auto mws = workspaceOptional ? ws : nullptr;
if (workspaceIndex >= 0) {
return std::vector<int>({workspaceIndex});
nameList.emplace_back(name, workspaceIndex, -1, -1, period, mws);
return;
}
std::vector<int> out;
API::Axis *axis = ws.getAxis(1);

API::Axis *axis = ws->getAxis(1);
if (axis->isSpectra()) {
if (spectrumNumber < 0) {
for (size_t i = 0; i < axis->length(); ++i) {
auto s = double(axis->spectraNo(i));
if (s >= start && s <= end) {
out.emplace_back(static_cast<int>(i));
double spec = double(axis->spectraNo(i));
int wsIdx = static_cast<int>(i);
if (spec >= start && spec <= end) {
nameList.emplace_back(name, wsIdx, spec, -1, period, mws);
}
}

} else {
for (size_t i = 0; i < axis->length(); ++i) {
int j = axis->spectraNo(i);
int wsIdx = static_cast<int>(i);
if (j == spectrumNumber) {
out.emplace_back(static_cast<int>(i));
nameList.emplace_back(name, wsIdx, j, -1, period, mws);
break;
}
}
Expand All @@ -187,14 +182,13 @@ std::vector<int> getWorkspaceIndicesFromAxes(const API::MatrixWorkspace &ws, int
end = (*axis)(axis->length() - 1);
}
for (size_t i = 0; i < axis->length(); ++i) {
double s = (*axis)(i);
if (s >= start && s <= end) {
out.emplace_back(static_cast<int>(i));
double value = (*axis)(i);
int wsIdx = static_cast<int>(i);
if (value >= start && value <= end) {
nameList.emplace_back(name, wsIdx, -1, value, period, mws);
}
}
}

return out;
}

std::optional<API::Workspace_sptr> getWorkspace(const std::string &workspaceName, int period) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 1);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, -1);
TS_ASSERT_EQUALS(inputWithWorkspace.numericValue, -1);
TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "irs26176_graphite002_red.nxs");
}
Expand All @@ -41,7 +43,9 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 1);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, 1);
TS_ASSERT_EQUALS(inputWithWorkspace.numericValue, -1);
TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "irs26176_graphite002_red.nxs");
}
Expand All @@ -53,8 +57,10 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 2);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 1);
TS_ASSERT_EQUALS(namesList[1].i, 2);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 1);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, 2);
TS_ASSERT_EQUALS(inputWithWorkspace.numericValue, -1);
TS_ASSERT_EQUALS(namesList[1].wsIdx, 2);
TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "irs26176_graphite002_red.nxs");
}
Expand All @@ -66,7 +72,10 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 1);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, -1);
TS_ASSERT_EQUALS(inputWithWorkspace.numericValue, -1);

TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "saveNISTDAT_data.nxs");
}
Expand All @@ -78,7 +87,9 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 1);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 160);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 160);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, -1);
TS_ASSERT_EQUALS(inputWithWorkspace.numericValue, 0);
TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "saveNISTDAT_data.nxs");
}
Expand All @@ -90,8 +101,10 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 321);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 0);
TS_ASSERT_EQUALS(namesList[200].i, 200);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 0);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, -1);
TS_ASSERT_DELTA(inputWithWorkspace.numericValue, -0.16, 1e-3);
TS_ASSERT_EQUALS(namesList[200].wsIdx, 200);
TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "saveNISTDAT_data.nxs");
}
Expand All @@ -103,8 +116,10 @@ class PlotPeakByLogValueHelperTest : public CxxTest::TestSuite {
auto inputWithWorkspace = namesList[0];

TS_ASSERT_EQUALS(namesList.size(), 19);
TS_ASSERT_EQUALS(inputWithWorkspace.i, 151);
TS_ASSERT_EQUALS(namesList[15].i, 166);
TS_ASSERT_EQUALS(inputWithWorkspace.wsIdx, 151);
TS_ASSERT_EQUALS(inputWithWorkspace.spectrumNum, -1);
TS_ASSERT_DELTA(inputWithWorkspace.numericValue, -0.01, 1e-3);
TS_ASSERT_EQUALS(namesList[15].wsIdx, 166);
TS_ASSERT(inputWithWorkspace.ws);
TS_ASSERT_EQUALS(inputWithWorkspace.name, "saveNISTDAT_data.nxs");
}
Expand Down
Loading