From 57432e6cbf345e29870bc307ba1285aee5f0ffb6 Mon Sep 17 00:00:00 2001
From: Verena Reimund <reimund@ill.eu>
Date: Tue, 27 Mar 2018 14:56:20 +0200
Subject: [PATCH] Add implementation for point data

- update release notes

Refs #22197
---
 .../inc/MantidAlgorithms/Stitch1D.h           |  6 +++-
 Framework/Algorithms/src/Stitch1D.cpp         | 32 +++++++++++++++----
 Framework/Algorithms/test/Stitch1DTest.h      |  1 -
 docs/source/release/v3.13.0/framework.rst     |  2 +-
 4 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h b/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
index 973bd63c7cc..050d7dd5d9f 100644
--- a/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
+++ b/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
@@ -74,10 +74,14 @@ private:
   integration(Mantid::API::MatrixWorkspace_sptr &input, const double &start,
               const double &stop);
   Mantid::API::MatrixWorkspace_sptr singleValueWS(double val);
-  /// Calclate the weighted mean
+  /// Calculate the weighted mean
   Mantid::API::MatrixWorkspace_sptr
   weightedMean(Mantid::API::MatrixWorkspace_sptr &inOne,
                Mantid::API::MatrixWorkspace_sptr &inTwo);
+  /// Conjoin x axis
+  Mantid::API::MatrixWorkspace_sptr conjoinXAxis(Mantid::API::MatrixWorkspace_sptr &inWS);
+  /// Sort x axis
+  Mantid::API::MatrixWorkspace_sptr sortXAxis(Mantid::API::MatrixWorkspace_sptr &inWS);
   /// Find the start and end indexes
   boost::tuple<int, int>
   findStartEndIndexes(double startOverlap, double endOverlap,
diff --git a/Framework/Algorithms/src/Stitch1D.cpp b/Framework/Algorithms/src/Stitch1D.cpp
index edb105e40b4..3d8dc0f93c7 100644
--- a/Framework/Algorithms/src/Stitch1D.cpp
+++ b/Framework/Algorithms/src/Stitch1D.cpp
@@ -370,6 +370,30 @@ MatrixWorkspace_sptr Stitch1D::weightedMean(MatrixWorkspace_sptr &inOne,
   return outWS;
 }
 
+/**Runs the ConjoinXRuns Algorithm as a child
+ @param inWS :: Input workspace
+ @return A shared pointer to the resulting MatrixWorkspace
+ */
+MatrixWorkspace_sptr Stitch1D::conjoinXAxis(MatrixWorkspace_sptr &inWS) {
+  auto conjoinX = this->createChildAlgortihm("ConjoinXRuns");
+  conjoinX->setProperty("InputWorkspace", inWS);
+  conjoinX->execute();
+  MatrixWorkspace_sptr outWS = conjoinX->getProperty("OutputWorkspace");
+  return outWS;
+}
+
+/**Runs the SortXAxis Algorithm as a child
+ @param inWS :: Input workspace
+ @return A shared pointer to the resulting MatrixWorkspace
+ */
+MatrixWorkspace_sptr Stitch1D::sortXAxis(MatrixWorkspace_sptr &inWS) {
+  auto sortX = this->createChildAlgortihm("SortXAxis");
+  sortX->setProperty("InputWorkspace", inWS);
+  sortX->execute();
+  MatrixWorkspace_sptr outWS = sortX->getProperty("OutputWorkspace");
+  return outWS;
+}
+
 /**Runs the CreateSingleValuedWorkspace Algorithm as a child
  @param val :: The double to convert to a single value workspace
  @return A shared pointer to the resulting MatrixWorkspace
@@ -437,7 +461,6 @@ bool Stitch1D::hasNonzeroErrors(MatrixWorkspace_sptr ws) {
 void Stitch1D::exec() {
   MatrixWorkspace_sptr rhsWS = this->getProperty("RHSWorkspace");
   MatrixWorkspace_sptr lhsWS = this->getProperty("LHSWorkspace");
-
   const MinMaxTuple intesectionXRegion = calculateXIntersection(lhsWS, rhsWS);
 
   const double intersectionMin = intesectionXRegion.get<0>();
@@ -473,7 +496,6 @@ void Stitch1D::exec() {
         startOverlap % xMin);
     throw std::runtime_error(message);
   }
-
   if (endOverlap > xMax) {
     std::string message = boost::str(
         boost::format("Stitch1D EndOverlap is outside the available X range "
@@ -500,7 +522,6 @@ void Stitch1D::exec() {
     lhs = rebin(lhsWS, params);
     rhs = rebin(rhsWS, params);
   }
-
   if (useManualScaleFactor) {
     double manualScaleFactor = this->getProperty("ManualScaleFactor");
     MatrixWorkspace_sptr manualScaleFactorWS = singleValueWS(manualScaleFactor);
@@ -536,7 +557,6 @@ void Stitch1D::exec() {
 
   boost::tuple<int, int> startEnd =
       findStartEndIndexes(startOverlap, endOverlap, lhs);
-
   int a1 = boost::tuples::get<0>(startEnd);
   int a2 = boost::tuples::get<1>(startEnd);
 
@@ -564,8 +584,8 @@ void Stitch1D::exec() {
   } else {
     // If the input workspaces are point data ...
     if (!rhsWS->isHistogramData() && !lhsWS->isHistogramData()) {
-      g_log.error("Missing implementation");
-      throw std::invalid_argument("Missing implementation");
+      // Sort according to x values
+      overlapave = sortXAxis(conjoinXaxis(overlap1, overlap2));
     } else {
       g_log.error("Input workspaces must be both histograms or point data");
       throw std::invalid_argument(
diff --git a/Framework/Algorithms/test/Stitch1DTest.h b/Framework/Algorithms/test/Stitch1DTest.h
index 3002385367b..10140983dd9 100644
--- a/Framework/Algorithms/test/Stitch1DTest.h
+++ b/Framework/Algorithms/test/Stitch1DTest.h
@@ -40,7 +40,6 @@ MatrixWorkspace_sptr createWorkspace(const HistogramX &xData,
 
   Workspace2D_sptr outWS = boost::make_shared<Workspace2D>();
   outWS->initialize(nSpec, xData.size(), yData.size());
-
   for (int i = 0; i < nSpec; ++i) {
     outWS->mutableY(i) = yData;
     outWS->mutableE(i) = eData;
diff --git a/docs/source/release/v3.13.0/framework.rst b/docs/source/release/v3.13.0/framework.rst
index 4f8aa93fda2..4daee33a607 100644
--- a/docs/source/release/v3.13.0/framework.rst
+++ b/docs/source/release/v3.13.0/framework.rst
@@ -19,7 +19,7 @@ Algorithms
 ----------
 
 - :ref:`ConvertToPointData <algm-ConvertToPointData>` and :ref:`ConvertToHistogram <algm-ConvertToHistogram>` now propagate the Dx errors to the output.
-- The `OutputWorkspace` of the algorithm :ref:`algm-Stitch1D` will be created according to the default option for the x values `WeightedMeanOverlap` or the newly implemented option `OriginalOverlap`. Furthermore, the Dx error values will be propagated for the `WeightedMeanOverlap` output option.
+- The algorithm :ref:`algm-Stitch1D` can now receive point data as input workspaces and does apply a full overlap while keeping corresponding Dx values.
 
 
 :ref:`Release 3.13.0 <v3.13.0>`
-- 
GitLab