Skip to content
Snippets Groups Projects
Commit ad30b644 authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #22896 Implement SortXAxis in Stitch1D

parent 98d01d0b
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceProperty.h" #include "MantidAPI/WorkspaceProperty.h"
#include "MantidAlgorithms/RunCombinationHelpers/RunCombinationHelper.h" #include "MantidAlgorithms/RunCombinationHelpers/RunCombinationHelper.h"
#include "MantidAlgorithms/SortXAxis.h"
#include "MantidHistogramData/HistogramDx.h" #include "MantidHistogramData/HistogramDx.h"
#include "MantidHistogramData/HistogramE.h" #include "MantidHistogramData/HistogramE.h"
#include "MantidHistogramData/HistogramX.h" #include "MantidHistogramData/HistogramX.h"
...@@ -41,32 +42,11 @@ bool isNonzero(double i) { return (0 != i); } ...@@ -41,32 +42,11 @@ bool isNonzero(double i) { return (0 != i); }
@return A shared pointer to the resulting MatrixWorkspace @return A shared pointer to the resulting MatrixWorkspace
*/ */
void sortXAxis(MatrixWorkspace_sptr &ws) { void sortXAxis(MatrixWorkspace_sptr &ws) {
// using a std::multimap (keys are sorted) Mantid::Algorithms::SortXAxis alg;
std::multimap<double, double> sorter; alg.initialize();
double x_value; alg.setProperty("InputWorkspace", ws);
const int nHists = static_cast<int>(ws->getNumberHistograms()); alg.setProperty("OutputWorkspace", "outputSearch");
for (int i = 0; i < nHists; ++i) { alg.execute();
for (size_t k = 0; k < ws->size(); ++k) {
x_value = ws->x(i)[k];
sorter.insert(std::pair<double, double>(x_value, ws->y(i)[k]));
sorter.insert(std::pair<double, double>(x_value, ws->e(i)[k]));
// histograms: no recalculation of Dx implemented -> skip
if (ws->hasDx(i) && !ws->isHistogramData())
sorter.insert(std::pair<double, double>(x_value, ws->dx(i)[k]));
}
int l = 0;
auto it = sorter.cbegin();
while (it != sorter.cend()) {
ws->mutableX(i)[l] = it->first;
ws->mutableY(i)[l] = it->second;
ws->mutableE(i)[l] = (++it)->second;
// histograms: no recalculation of Dx implemented -> skip
if (ws->hasDx(i) && !ws->isHistogramData())
ws->mutableDx(i)[l] = (++it)->second;
++l;
++it;
}
}
} }
} // namespace } // namespace
...@@ -658,6 +638,10 @@ void Stitch1D::exec() { ...@@ -658,6 +638,10 @@ void Stitch1D::exec() {
if (!result) if (!result)
g_log.error("Could not retrieve joined workspace."); g_log.error("Could not retrieve joined workspace.");
sortXAxis(result); sortXAxis(result);
MatrixWorkspace_sptr outputSearch =
boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve("outputSearch"));
result = outputSearch;
} }
setProperty("OutputWorkspace", result); setProperty("OutputWorkspace", result);
setProperty("OutScaleFactor", m_scaleFactor); setProperty("OutScaleFactor", m_scaleFactor);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment