diff --git a/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Framework/API/inc/MantidAPI/MatrixWorkspace.h
index 55e11fd5fc0e6168b8e3fc40881bc783b28759ec..d0065c7351b729e1e3635965bfa4708d36b300eb 100644
--- a/Framework/API/inc/MantidAPI/MatrixWorkspace.h
+++ b/Framework/API/inc/MantidAPI/MatrixWorkspace.h
@@ -455,9 +455,6 @@ public:
 
   void saveInstrumentNexus(::NeXus::File *file) const;
   void loadInstrumentNexus(::NeXus::File *file);
-  void saveSpectraMapNexus(
-      ::NeXus::File *file, const std::vector<int> &spec,
-      const ::NeXus::NXcompression compression = ::NeXus::LZW) const;
 
   //=====================================================================================
   // MD Geometry methods
diff --git a/Framework/API/src/FileBackedExperimentInfo.cpp b/Framework/API/src/FileBackedExperimentInfo.cpp
index 69aa290c4c65f943c48554b7cdf0ac557d8c6696..c0ae4a0a4b47953170b00f3b827001659e838465 100644
--- a/Framework/API/src/FileBackedExperimentInfo.cpp
+++ b/Framework/API/src/FileBackedExperimentInfo.cpp
@@ -3,8 +3,8 @@
 
 #include <sstream>
 
-#include <nexus/NeXusException.hpp>
 #include <nexus/NeXusFile.hpp>
+#include <nexus/NeXusException.hpp>
 
 namespace Mantid {
 namespace API {
diff --git a/Framework/API/src/FrameworkManager.cpp b/Framework/API/src/FrameworkManager.cpp
index 0206b3c52f93856b9496383968646968f1aec4d3..d9bb34fd7381fa947a56070f4ba4fb2e9128df40 100644
--- a/Framework/API/src/FrameworkManager.cpp
+++ b/Framework/API/src/FrameworkManager.cpp
@@ -11,6 +11,8 @@
 #include "MantidKernel/PropertyManagerDataService.h"
 #include "MantidKernel/UsageService.h"
 
+#include <nexus/NeXusFile.hpp>
+
 #include <Poco/ActiveResult.h>
 
 #include <clocale>
diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp
index e9e2aa541c798c84927174dac8939a34f8a7180a..a5e36f6477aa74f94bf88cd26a2794eeb8c9f5a2 100644
--- a/Framework/API/src/MatrixWorkspace.cpp
+++ b/Framework/API/src/MatrixWorkspace.cpp
@@ -29,7 +29,6 @@
 
 using Mantid::Kernel::DateAndTime;
 using Mantid::Kernel::TimeSeriesProperty;
-using NeXus::NXcompression;
 using Mantid::Kernel::Strings::toString;
 
 namespace Mantid {
@@ -1571,121 +1570,6 @@ signal_t MatrixWorkspace::getSignalWithMaskAtCoord(
   return getSignalAtCoord(coords, normalization);
 }
 
-/** Save the spectra detector map to an open NeXus file.
-* @param file :: open NeXus file
-* @param spec :: list of the Workspace Indices to save.
-* @param compression :: NXcompression int to indicate how to compress
-*/
-void MatrixWorkspace::saveSpectraMapNexus(
-    ::NeXus::File *file, const std::vector<int> &spec,
-    const ::NeXus::NXcompression compression) const {
-  // Count the total number of detectors
-  std::size_t nDetectors = 0;
-  for (auto index : spec) {
-    nDetectors +=
-        this->getSpectrum(static_cast<size_t>(index)).getDetectorIDs().size();
-  }
-
-  if (nDetectors < 1) {
-    // No data in spectraMap to write
-    g_log.warning("No spectramap data to write");
-    return;
-  }
-
-  // Start the detector group
-  file->makeGroup("detector", "NXdetector", 1);
-  file->putAttr("version", 1);
-
-  int numberSpec = int(spec.size());
-  // allocate space for the Nexus Muon format of spctra-detector mapping
-  std::vector<int32_t> detector_index(
-      numberSpec + 1, 0); // allow for writing one more than required
-  std::vector<int32_t> detector_count(numberSpec, 0);
-  std::vector<int32_t> detector_list(nDetectors, 0);
-  std::vector<int32_t> spectra(numberSpec, 0);
-  std::vector<double> detPos(nDetectors * 3);
-  detector_index[0] = 0;
-  int id = 0;
-
-  int ndet = 0;
-  // get data from map into Nexus Muon format
-  for (int i = 0; i < numberSpec; i++) {
-    // Workspace index
-    int si = spec[i];
-    // Spectrum there
-    const auto &spectrum = this->getSpectrum(si);
-    spectra[i] = int32_t(spectrum.getSpectrumNo());
-
-    // The detectors in this spectrum
-    const auto &detectorgroup = spectrum.getDetectorIDs();
-    const int ndet1 = static_cast<int>(detectorgroup.size());
-
-    detector_index[i + 1] = int32_t(
-        detector_index[i] +
-        ndet1); // points to start of detector list for the next spectrum
-    detector_count[i] = int32_t(ndet1);
-    ndet += ndet1;
-
-    std::set<detid_t>::const_iterator it;
-    for (it = detectorgroup.begin(); it != detectorgroup.end(); ++it) {
-      detector_list[id++] = int32_t(*it);
-    }
-  }
-  // Cut the extra entry at the end of detector_index
-  detector_index.resize(numberSpec);
-
-  // write data as Nexus sections detector{index,count,list}
-  std::vector<int> dims(1, numberSpec);
-  file->writeCompData("detector_index", detector_index, dims, compression,
-                      dims);
-  file->writeCompData("detector_count", detector_count, dims, compression,
-                      dims);
-  dims[0] = ndet;
-  file->writeCompData("detector_list", detector_list, dims, compression, dims);
-  dims[0] = numberSpec;
-  file->writeCompData("spectra", spectra, dims, compression, dims);
-
-  // Get all the positions
-  try {
-    Geometry::Instrument_const_sptr inst = this->getInstrument();
-    Geometry::IComponent_const_sptr sample = inst->getSample();
-    if (sample) {
-      Kernel::V3D sample_pos = sample->getPos();
-      for (int i = 0; i < ndet; i++) {
-        double R, Theta, Phi;
-        try {
-          Geometry::IDetector_const_sptr det =
-              inst->getDetector(detector_list[i]);
-          Kernel::V3D pos = det->getPos() - sample_pos;
-          pos.getSpherical(R, Theta, Phi);
-          R = det->getDistance(*sample);
-          Theta = this->detectorTwoTheta(*det) * rad2deg;
-        } catch (...) {
-          R = 0.;
-          Theta = 0.;
-          Phi = 0.;
-        }
-        // Need to get R & Theta through these methods to be correct for grouped
-        // detectors
-        detPos[3 * i] = R;
-        detPos[3 * i + 1] = Theta;
-        detPos[3 * i + 2] = Phi;
-      }
-    } else
-      for (int i = 0; i < 3 * ndet; i++)
-        detPos[i] = 0.;
-
-    dims[0] = ndet;
-    dims.push_back(3);
-    dims[1] = 3;
-    file->writeCompData("detector_positions", detPos, dims, compression, dims);
-  } catch (...) {
-    g_log.error("Unknown error caught when saving detector positions.");
-  }
-
-  file->closeGroup();
-}
-
 /*
 MDMasking for a Matrix Workspace has not been implemented.
 @param :
diff --git a/Framework/API/test/MatrixWorkspaceTest.h b/Framework/API/test/MatrixWorkspaceTest.h
index 3b984074a19a39be8d0f4a5d063d54718ed3a275..00b73f8761a3da1c13b437248793d36fd68f5400 100644
--- a/Framework/API/test/MatrixWorkspaceTest.h
+++ b/Framework/API/test/MatrixWorkspaceTest.h
@@ -803,21 +803,6 @@ public:
     TS_ASSERT_THROWS(wkspace.binIndexOf(0.), std::out_of_range);
   }
 
-  void test_nexus_spectraMap() {
-    NexusTestHelper th(true);
-    th.createFile("MatrixWorkspaceTest.nxs");
-    auto ws = makeWorkspaceWithDetectors(100, 50);
-    std::vector<int> spec;
-    for (int i = 0; i < 100; i++) {
-      // Give some funny numbers, so it is not the default
-      ws->getSpectrum(size_t(i)).setSpectrumNo(i * 11);
-      ws->getSpectrum(size_t(i)).setDetectorID(99 - i);
-      spec.push_back(i);
-    }
-    // Save that to the NXS file
-    TS_ASSERT_THROWS_NOTHING(ws->saveSpectraMapNexus(th.file, spec););
-  }
-
   void test_hasGroupedDetectors() {
     auto ws = makeWorkspaceWithDetectors(5, 1);
     TS_ASSERT_EQUALS(ws->hasGroupedDetectors(), false);
diff --git a/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h b/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h
index 9bdfd7a2db4b0f51f2861dd2e8df8a447eb63d9e..32fb36d812ffc806954ba4d06ac00c50c264fcb1 100644
--- a/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h
+++ b/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h
@@ -6,6 +6,8 @@
 #include "MantidKernel/V3D.h"
 #include "MantidGeometry/IDetector.h"
 
+#include <list>
+
 namespace Mantid {
 namespace Algorithms {
 /**
diff --git a/Framework/Algorithms/src/ReflectometryReductionOne2.cpp b/Framework/Algorithms/src/ReflectometryReductionOne2.cpp
index ad729a1c504f60321da6beb847baa328f6305b1e..7725eb4f199facb8391ca72a885e95f64b0a92c2 100644
--- a/Framework/Algorithms/src/ReflectometryReductionOne2.cpp
+++ b/Framework/Algorithms/src/ReflectometryReductionOne2.cpp
@@ -8,6 +8,7 @@
 #include "MantidKernel/MandatoryValidator.h"
 #include "MantidKernel/StringTokenizer.h"
 #include "MantidKernel/Unit.h"
+#include "MantidGeometry/IDetector.h"
 
 #include <algorithm>
 #include <boost/lexical_cast.hpp>
diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h b/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h
index 0c9139a92c8ff770e1762f9b7222f349153b534a..00519e38145a966ac6ebd767eeef2e63aade70fa 100644
--- a/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h
+++ b/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h
@@ -66,6 +66,11 @@ public:
   /// Algorithm's category for identification overriding a virtual method
   const std::string category() const override { return "DataHandling\\Nexus"; }
 
+  void saveSpectraMapNexus(
+      const API::MatrixWorkspace &ws, ::NeXus::File *file,
+      const std::vector<int> &spec,
+      const ::NeXus::NXcompression compression = ::NeXus::LZW) const;
+
 protected:
   /// Override process groups
   bool processGroups() override;
diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h b/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h
index e8dc0396f6febcd09f0ef9dcde5a64ac11270c9b..dc53024f17560f2a559f13761161a489cbe5ebe9 100644
--- a/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h
+++ b/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h
@@ -1,9 +1,6 @@
 #ifndef MANTID_DATAHANDLING_SAVESNSNEXUS_H_
 #define MANTID_DATAHANDLING_SAVESNSNEXUS_H_
 
-//----------------------------------------------------------------------
-// Includes
-//----------------------------------------------------------------------
 #include "MantidAPI/Algorithm.h"
 #include "MantidAPI/MatrixWorkspace_fwd.h"
 #include "MantidAPI/Progress.h"
@@ -12,8 +9,8 @@
 #include "MantidDataObjects/Workspace2D.h"
 #include "MantidGeometry/Instrument/RectangularDetector.h"
 #include <climits>
-#include <nexus/NeXusException.hpp>
 #include <nexus/NeXusFile.hpp>
+#include <nexus/NeXusException.hpp>
 
 namespace Mantid {
 namespace DataHandling {
diff --git a/Framework/DataHandling/src/LoadIDFFromNexus.cpp b/Framework/DataHandling/src/LoadIDFFromNexus.cpp
index ab9e7484b49498243529d3d619b5460b246b2643..f68ae54eb58d351ee064453a00349d043824e8ed 100644
--- a/Framework/DataHandling/src/LoadIDFFromNexus.cpp
+++ b/Framework/DataHandling/src/LoadIDFFromNexus.cpp
@@ -12,6 +12,7 @@
 #include <Poco/DOM/NodeIterator.h>
 #include <Poco/File.h>
 #include <Poco/Path.h>
+#include <nexus/NeXusFile.hpp>
 
 using Poco::XML::DOMParser;
 using Poco::XML::Document;
diff --git a/Framework/DataHandling/src/LoadMcStasNexus.cpp b/Framework/DataHandling/src/LoadMcStasNexus.cpp
index cb42ae556e7722e8a473657bf0c6ad5c5f3d16fb..ec1aebbaf44ba09ece1bc64d7eb59cf1516b7210 100644
--- a/Framework/DataHandling/src/LoadMcStasNexus.cpp
+++ b/Framework/DataHandling/src/LoadMcStasNexus.cpp
@@ -6,8 +6,8 @@
 #include "MantidAPI/WorkspaceFactory.h"
 #include "MantidAPI/WorkspaceGroup.h"
 #include "MantidKernel/Unit.h"
-#include <nexus/NeXusException.hpp>
 #include <nexus/NeXusFile.hpp>
+#include <nexus/NeXusException.hpp>
 
 #include <boost/algorithm/string.hpp>
 
diff --git a/Framework/DataHandling/src/LoadMuonNexus2.cpp b/Framework/DataHandling/src/LoadMuonNexus2.cpp
index 608162ee272f8f414b3d15a77240dcf9b7440d5b..0d64914640397a192992c103cf683cdeb0ecfc71 100644
--- a/Framework/DataHandling/src/LoadMuonNexus2.cpp
+++ b/Framework/DataHandling/src/LoadMuonNexus2.cpp
@@ -16,8 +16,8 @@
 #include "MantidKernel/UnitFactory.h"
 #include "MantidKernel/UnitLabelTypes.h"
 #include "MantidNexus/NexusClasses.h"
-#include <nexus/NeXusException.hpp>
 #include <nexus/NeXusFile.hpp>
+#include <nexus/NeXusException.hpp>
 
 #include <Poco/Path.h>
 #include <boost/lexical_cast.hpp>
diff --git a/Framework/DataHandling/src/LoadNXSPE.cpp b/Framework/DataHandling/src/LoadNXSPE.cpp
index 9f5e0dcfddd842c7a68e757e709be6b532ebebb4..43eb55b4b9a725903c8da5f4cb185f46c9d52645 100644
--- a/Framework/DataHandling/src/LoadNXSPE.cpp
+++ b/Framework/DataHandling/src/LoadNXSPE.cpp
@@ -11,8 +11,8 @@
 #include "MantidKernel/UnitFactory.h"
 
 #include "MantidNexus/NexusClasses.h"
-#include <nexus/NeXusException.hpp>
 #include <nexus/NeXusFile.hpp>
+#include <nexus/NeXusException.hpp>
 
 #include "MantidGeometry/Instrument.h"
 #include "MantidGeometry/Instrument/Detector.h"
diff --git a/Framework/DataHandling/src/LoadNXcanSAS.cpp b/Framework/DataHandling/src/LoadNXcanSAS.cpp
index 191c24c271a48e04ff3a842839ac9476847ddf6b..54bf55f6623dc315cd9aad16e670f85d4587e0a1 100644
--- a/Framework/DataHandling/src/LoadNXcanSAS.cpp
+++ b/Framework/DataHandling/src/LoadNXcanSAS.cpp
@@ -20,6 +20,7 @@
 #include <H5Cpp.h>
 #include <Poco/DirectoryIterator.h>
 #include <Poco/Path.h>
+#include <nexus/NeXusFile.hpp>
 #include <type_traits>
 
 using namespace Mantid::Kernel;
diff --git a/Framework/DataHandling/src/SaveNXSPE.cpp b/Framework/DataHandling/src/SaveNXSPE.cpp
index 1a4f80f53a375bfe97aa5ceb7c5a4750dd766568..b76d875c1362a7c0ea925775284ac32bf8b8c835 100644
--- a/Framework/DataHandling/src/SaveNXSPE.cpp
+++ b/Framework/DataHandling/src/SaveNXSPE.cpp
@@ -16,6 +16,7 @@
 
 #include <Poco/File.h>
 #include <Poco/Path.h>
+#include <nexus/NeXusFile.hpp>
 #include <boost/scoped_array.hpp>
 #include <limits>
 
diff --git a/Framework/DataHandling/src/SaveNXTomo.cpp b/Framework/DataHandling/src/SaveNXTomo.cpp
index 2cdb0e63512645f3e6240b1bf750f9ecef9bb4ca..3b82c5aa24930d1b6ad5667492a877cb7ab07989 100644
--- a/Framework/DataHandling/src/SaveNXTomo.cpp
+++ b/Framework/DataHandling/src/SaveNXTomo.cpp
@@ -14,8 +14,8 @@
 #include "MantidKernel/CompositeValidator.h"
 #include "MantidKernel/MantidVersion.h"
 
-#include <nexus/NeXusException.hpp>
 #include <nexus/NeXusFile.hpp>
+#include <nexus/NeXusException.hpp>
 
 namespace Mantid {
 namespace DataHandling {
diff --git a/Framework/DataHandling/src/SaveNexusProcessed.cpp b/Framework/DataHandling/src/SaveNexusProcessed.cpp
index 154d8a8a20b3b3a5479c47f7cfff9d411728f6ad..7908617397a9d23fadf45df3d880c6d21f5f2f3c 100644
--- a/Framework/DataHandling/src/SaveNexusProcessed.cpp
+++ b/Framework/DataHandling/src/SaveNexusProcessed.cpp
@@ -10,6 +10,7 @@
 #include "MantidDataObjects/EventWorkspace.h"
 #include "MantidDataObjects/OffsetsWorkspace.h"
 #include "MantidDataObjects/PeaksWorkspace.h"
+#include "MantidGeometry/Crystal/AngleUnits.h"
 #include "MantidKernel/ArrayProperty.h"
 #include "MantidKernel/BoundedValidator.h"
 #include "MantidNexus/NexusFileIO.h"
@@ -261,7 +262,7 @@ void SaveNexusProcessed::doExec(Workspace_sptr inputWorkspace,
     }
 
     cppFile->openGroup("instrument", "NXinstrument");
-    matrixWorkspace->saveSpectraMapNexus(cppFile, spec, ::NeXus::LZW);
+    saveSpectraMapNexus(*matrixWorkspace, cppFile, spec, ::NeXus::LZW);
     cppFile->closeGroup();
 
   } // finish matrix workspace specifics
@@ -523,5 +524,121 @@ bool SaveNexusProcessed::processGroups() {
   return true;
 }
 
+/** Save the spectra detector map to an open NeXus file.
+* @param file :: open NeXus file
+* @param spec :: list of the Workspace Indices to save.
+* @param compression :: NXcompression int to indicate how to compress
+*/
+void SaveNexusProcessed::saveSpectraMapNexus(
+    const MatrixWorkspace &ws, ::NeXus::File *file,
+    const std::vector<int> &spec,
+    const ::NeXus::NXcompression compression) const {
+  // Count the total number of detectors
+  std::size_t nDetectors = 0;
+  for (auto index : spec) {
+    nDetectors +=
+        ws.getSpectrum(static_cast<size_t>(index)).getDetectorIDs().size();
+  }
+
+  if (nDetectors < 1) {
+    // No data in spectraMap to write
+    g_log.warning("No spectramap data to write");
+    return;
+  }
+
+  // Start the detector group
+  file->makeGroup("detector", "NXdetector", 1);
+  file->putAttr("version", 1);
+
+  int numberSpec = int(spec.size());
+  // allocate space for the Nexus Muon format of spctra-detector mapping
+  std::vector<int32_t> detector_index(
+      numberSpec + 1, 0); // allow for writing one more than required
+  std::vector<int32_t> detector_count(numberSpec, 0);
+  std::vector<int32_t> detector_list(nDetectors, 0);
+  std::vector<int32_t> spectra(numberSpec, 0);
+  std::vector<double> detPos(nDetectors * 3);
+  detector_index[0] = 0;
+  int id = 0;
+
+  int ndet = 0;
+  // get data from map into Nexus Muon format
+  for (int i = 0; i < numberSpec; i++) {
+    // Workspace index
+    int si = spec[i];
+    // Spectrum there
+    const auto &spectrum = ws.getSpectrum(si);
+    spectra[i] = int32_t(spectrum.getSpectrumNo());
+
+    // The detectors in this spectrum
+    const auto &detectorgroup = spectrum.getDetectorIDs();
+    const int ndet1 = static_cast<int>(detectorgroup.size());
+
+    detector_index[i + 1] = int32_t(
+        detector_index[i] +
+        ndet1); // points to start of detector list for the next spectrum
+    detector_count[i] = int32_t(ndet1);
+    ndet += ndet1;
+
+    std::set<detid_t>::const_iterator it;
+    for (it = detectorgroup.begin(); it != detectorgroup.end(); ++it) {
+      detector_list[id++] = int32_t(*it);
+    }
+  }
+  // Cut the extra entry at the end of detector_index
+  detector_index.resize(numberSpec);
+
+  // write data as Nexus sections detector{index,count,list}
+  std::vector<int> dims(1, numberSpec);
+  file->writeCompData("detector_index", detector_index, dims, compression,
+                      dims);
+  file->writeCompData("detector_count", detector_count, dims, compression,
+                      dims);
+  dims[0] = ndet;
+  file->writeCompData("detector_list", detector_list, dims, compression, dims);
+  dims[0] = numberSpec;
+  file->writeCompData("spectra", spectra, dims, compression, dims);
+
+  // Get all the positions
+  try {
+    Geometry::Instrument_const_sptr inst = ws.getInstrument();
+    Geometry::IComponent_const_sptr sample = inst->getSample();
+    if (sample) {
+      Kernel::V3D sample_pos = sample->getPos();
+      for (int i = 0; i < ndet; i++) {
+        double R, Theta, Phi;
+        try {
+          Geometry::IDetector_const_sptr det =
+              inst->getDetector(detector_list[i]);
+          Kernel::V3D pos = det->getPos() - sample_pos;
+          pos.getSpherical(R, Theta, Phi);
+          R = det->getDistance(*sample);
+          Theta = ws.detectorTwoTheta(*det) * Geometry::rad2deg;
+        } catch (...) {
+          R = 0.;
+          Theta = 0.;
+          Phi = 0.;
+        }
+        // Need to get R & Theta through these methods to be correct for grouped
+        // detectors
+        detPos[3 * i] = R;
+        detPos[3 * i + 1] = Theta;
+        detPos[3 * i + 2] = Phi;
+      }
+    } else
+      for (int i = 0; i < 3 * ndet; i++)
+        detPos[i] = 0.;
+
+    dims[0] = ndet;
+    dims.push_back(3);
+    dims[1] = 3;
+    file->writeCompData("detector_positions", detPos, dims, compression, dims);
+  } catch (...) {
+    g_log.error("Unknown error caught when saving detector positions.");
+  }
+
+  file->closeGroup();
+}
+
 } // namespace DataHandling
 } // namespace Mantid
diff --git a/Framework/DataHandling/test/CMakeLists.txt b/Framework/DataHandling/test/CMakeLists.txt
index 76b892c268307e01a937433d46a130296268d603..0cfd3daaa25d7827b86d9912c986514fbe33aa7b 100644
--- a/Framework/DataHandling/test/CMakeLists.txt
+++ b/Framework/DataHandling/test/CMakeLists.txt
@@ -11,6 +11,7 @@ if ( CXXTEST_FOUND )
                         ../../TestHelpers/src/StartFrameworkManager.cpp
                         ../../TestHelpers/src/TearDownWorld.cpp
                         ../../TestHelpers/src/WorkspaceCreationHelper.cpp
+                        ../../TestHelpers/src/NexusTestHelper.cpp
                         NXcanSASTestHelper.cpp
       )
 
diff --git a/Framework/DataHandling/test/LoadDetectorInfoTest.h b/Framework/DataHandling/test/LoadDetectorInfoTest.h
index c41a65134db2ba77c6ca4114376031456062165d..31be49186dd90dc611dc49ff11d4df64a899384c 100644
--- a/Framework/DataHandling/test/LoadDetectorInfoTest.h
+++ b/Framework/DataHandling/test/LoadDetectorInfoTest.h
@@ -17,6 +17,7 @@
 #include "MantidKernel/UnitFactory.h"
 
 #include <Poco/File.h>
+#include <nexus/NeXusFile.hpp>
 #include <boost/lexical_cast.hpp>
 #include <vector>
 
diff --git a/Framework/DataHandling/test/SaveNXTomoTest.h b/Framework/DataHandling/test/SaveNXTomoTest.h
index d96d7e9fb574bac44415438707918c6eb3b59837..c2632ae035cc89f1e0a1ca70139c438e98604bff 100644
--- a/Framework/DataHandling/test/SaveNXTomoTest.h
+++ b/Framework/DataHandling/test/SaveNXTomoTest.h
@@ -8,6 +8,7 @@
 #include "MantidAPI/WorkspaceGroup.h"
 #include "MantidTestHelpers/WorkspaceCreationHelper.h"
 #include <Poco/File.h>
+#include <nexus/NeXusFile.hpp>
 
 using namespace Mantid::API;
 using namespace Mantid::Kernel;
diff --git a/Framework/DataHandling/test/SaveNexusProcessedTest.h b/Framework/DataHandling/test/SaveNexusProcessedTest.h
index b0e10668043967bfd39505e199f020ee09d7955d..3e0a76736959318fe1a85c6a47fa78c1116e39e9 100644
--- a/Framework/DataHandling/test/SaveNexusProcessedTest.h
+++ b/Framework/DataHandling/test/SaveNexusProcessedTest.h
@@ -24,6 +24,10 @@
 #include "MantidKernel/Unit.h"
 #include "MantidKernel/UnitFactory.h"
 #include "MantidDataHandling/LoadRaw3.h"
+#include "MantidGeometry/Instrument.h"
+#include "MantidTestHelpers/FakeObjects.h"
+#include "MantidTestHelpers/ComponentCreationHelper.h"
+#include "MantidTestHelpers/NexusTestHelper.h"
 #include "MantidTestHelpers/WorkspaceCreationHelper.h"
 #include <Poco/File.h>
 #include <Poco/Path.h>
@@ -38,6 +42,7 @@ using namespace Mantid::API;
 using namespace Mantid::Kernel;
 using namespace Mantid::DataHandling;
 using namespace Mantid::DataObjects;
+using namespace Mantid::Geometry;
 using namespace Mantid::NeXus;
 using Mantid::HistogramData::HistogramDx;
 
@@ -84,7 +89,7 @@ public:
     outputFile = doExec(outputFile, useXErrors);
 
     // Assert XError correctness
-    NeXus::File savedNexus(outputFile);
+    ::NeXus::File savedNexus(outputFile);
     savedNexus.openGroup("mantid_workspace_1", "NXentry");
     savedNexus.openGroup("workspace", "NXdata");
 
@@ -462,7 +467,7 @@ public:
     outputFileName = alg.getPropertyValue("Filename");
 
     try {
-      NeXus::File savedNexus(outputFileName);
+      ::NeXus::File savedNexus(outputFileName);
 
       savedNexus.openGroup("mantid_workspace_1", "NXentry");
       savedNexus.openGroup("table_workspace", "NXdata");
@@ -471,7 +476,7 @@ public:
 
       savedNexus.openData("column_1");
 
-      NeXus::Info columnInfo1 = savedNexus.getInfo();
+      ::NeXus::Info columnInfo1 = savedNexus.getInfo();
       TS_ASSERT_EQUALS(columnInfo1.dims.size(), 2);
       TS_ASSERT_EQUALS(columnInfo1.dims[0], 3);
       TS_ASSERT_EQUALS(columnInfo1.dims[1], 4);
@@ -487,7 +492,7 @@ public:
       TS_ASSERT_EQUALS(data1[8], 4);
       TS_ASSERT_EQUALS(data1[11], 7);
 
-      std::vector<NeXus::AttrInfo> attrInfos1 = savedNexus.getAttrInfos();
+      std::vector<::NeXus::AttrInfo> attrInfos1 = savedNexus.getAttrInfos();
       TS_ASSERT_EQUALS(attrInfos1.size(), 6);
 
       if (attrInfos1.size() == 6) {
@@ -509,7 +514,7 @@ public:
 
       savedNexus.openData("column_2");
 
-      NeXus::Info columnInfo2 = savedNexus.getInfo();
+      ::NeXus::Info columnInfo2 = savedNexus.getInfo();
       TS_ASSERT_EQUALS(columnInfo2.dims.size(), 2);
       TS_ASSERT_EQUALS(columnInfo2.dims[0], 3);
       TS_ASSERT_EQUALS(columnInfo2.dims[1], 2);
@@ -523,7 +528,7 @@ public:
       TS_ASSERT_EQUALS(data2[3], 2.5);
       TS_ASSERT_EQUALS(data2[5], 0.0);
 
-      std::vector<NeXus::AttrInfo> attrInfos2 = savedNexus.getAttrInfos();
+      std::vector<::NeXus::AttrInfo> attrInfos2 = savedNexus.getAttrInfos();
       TS_ASSERT_EQUALS(attrInfos2.size(), 6);
 
       if (attrInfos2.size() == 6) {
@@ -633,7 +638,7 @@ public:
     // Get full output file path
     outputFileName = alg.getPropertyValue("Filename");
 
-    NeXus::File savedNexus(outputFileName);
+    ::NeXus::File savedNexus(outputFileName);
 
     savedNexus.openGroup("mantid_workspace_1", "NXentry");
     savedNexus.openGroup("table_workspace", "NXdata");
@@ -697,13 +702,13 @@ public:
     {
       savedNexus.openData("column_9");
 
-      NeXus::Info columnInfo = savedNexus.getInfo();
+      ::NeXus::Info columnInfo = savedNexus.getInfo();
       TS_ASSERT_EQUALS(columnInfo.dims.size(), 2);
       TS_ASSERT_EQUALS(columnInfo.dims[0], 3);
       TS_ASSERT_EQUALS(columnInfo.dims[1], 9);
       TS_ASSERT_EQUALS(columnInfo.type, NX_CHAR);
 
-      std::vector<NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos();
+      std::vector<::NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos();
       TS_ASSERT_EQUALS(attrInfos.size(), 3);
 
       if (attrInfos.size() == 3) {
@@ -767,7 +772,7 @@ public:
     // Get full output file path
     outputFileName = alg.getPropertyValue("Filename");
 
-    NeXus::File savedNexus(outputFileName);
+    ::NeXus::File savedNexus(outputFileName);
 
     savedNexus.openGroup("mantid_workspace_1", "NXentry");
     savedNexus.openGroup("table_workspace", "NXdata");
@@ -782,13 +787,13 @@ public:
     {
       savedNexus.openData("column_2");
 
-      NeXus::Info columnInfo = savedNexus.getInfo();
+      ::NeXus::Info columnInfo = savedNexus.getInfo();
       TS_ASSERT_EQUALS(columnInfo.dims.size(), 2);
       TS_ASSERT_EQUALS(columnInfo.dims[0], 3);
       TS_ASSERT_EQUALS(columnInfo.dims[1], 1);
       TS_ASSERT_EQUALS(columnInfo.type, NX_CHAR);
 
-      std::vector<NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos();
+      std::vector<::NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos();
       TS_ASSERT_EQUALS(attrInfos.size(), 3);
 
       if (attrInfos.size() == 3) {
@@ -856,16 +861,31 @@ public:
     AnalysisDataService::Instance().remove("testSpace");
   }
 
+  void test_nexus_spectraMap() {
+    NexusTestHelper th(true);
+    th.createFile("MatrixWorkspaceTest.nxs");
+    auto ws = makeWorkspaceWithDetectors(100, 50);
+    std::vector<int> spec;
+    for (int i = 0; i < 100; i++) {
+      // Give some funny numbers, so it is not the default
+      ws->getSpectrum(size_t(i)).setSpectrumNo(i * 11);
+      ws->getSpectrum(size_t(i)).setDetectorID(99 - i);
+      spec.push_back(i);
+    }
+    SaveNexusProcessed alg;
+    TS_ASSERT_THROWS_NOTHING(alg.saveSpectraMapNexus(*ws, th.file, spec););
+  }
+
 private:
-  void doTestColumnInfo(NeXus::File &file, int type,
+  void doTestColumnInfo(::NeXus::File &file, int type,
                         const std::string &interpret_as,
                         const std::string &name) {
-    NeXus::Info columnInfo = file.getInfo();
+    ::NeXus::Info columnInfo = file.getInfo();
     TSM_ASSERT_EQUALS(name, columnInfo.dims.size(), 1);
     TSM_ASSERT_EQUALS(name, columnInfo.dims[0], 3);
     TSM_ASSERT_EQUALS(name, columnInfo.type, type);
 
-    std::vector<NeXus::AttrInfo> attrInfos = file.getAttrInfos();
+    std::vector<::NeXus::AttrInfo> attrInfos = file.getAttrInfos();
     TSM_ASSERT_EQUALS(name, attrInfos.size(), 3);
 
     if (attrInfos.size() == 3) {
@@ -880,16 +900,16 @@ private:
     }
   }
 
-  void doTestColumnInfo2(NeXus::File &file, int type,
+  void doTestColumnInfo2(::NeXus::File &file, int type,
                          const std::string &interpret_as,
                          const std::string &name, int dim1) {
-    NeXus::Info columnInfo = file.getInfo();
+    ::NeXus::Info columnInfo = file.getInfo();
     TSM_ASSERT_EQUALS(name, columnInfo.dims.size(), 2);
     TSM_ASSERT_EQUALS(name, columnInfo.dims[0], 3);
     TSM_ASSERT_EQUALS(name, columnInfo.dims[1], dim1);
     TSM_ASSERT_EQUALS(name, columnInfo.type, type);
 
-    std::vector<NeXus::AttrInfo> attrInfos = file.getAttrInfos();
+    std::vector<::NeXus::AttrInfo> attrInfos = file.getAttrInfos();
     TSM_ASSERT_EQUALS(name, attrInfos.size(), 6);
 
     if (attrInfos.size() == 6) {
@@ -905,7 +925,7 @@ private:
   }
 
   template <typename T>
-  void doTestColumnData(const std::string &name, NeXus::File &file,
+  void doTestColumnData(const std::string &name, ::NeXus::File &file,
                         const T expectedData[], size_t len = 3) {
     std::vector<T> data;
     file.getData(data);
@@ -977,6 +997,34 @@ private:
     return outputFile;
   }
 
+  /** Create a workspace with numSpectra, with
+   * each spectrum having one detector, at id = workspace index.
+   * @param numSpectra
+   * @return
+   */
+  boost::shared_ptr<MatrixWorkspace>
+  makeWorkspaceWithDetectors(size_t numSpectra, size_t numBins) const {
+    boost::shared_ptr<MatrixWorkspace> ws2 =
+        boost::make_shared<WorkspaceTester>();
+    ws2->initialize(numSpectra, numBins, numBins);
+
+    auto inst = boost::make_shared<Instrument>("TestInstrument");
+    // We get a 1:1 map by default so the detector ID should match the spectrum
+    // number
+    for (size_t i = 0; i < ws2->getNumberHistograms(); ++i) {
+      // Create a detector for each spectra
+      Detector *det =
+          new Detector("pixel", static_cast<detid_t>(i), inst.get());
+      det->setShape(
+          ComponentCreationHelper::createSphere(0.01, V3D(0, 0, 0), "1"));
+      inst->add(det);
+      inst->markAsDetector(det);
+      ws2->getSpectrum(i).addDetectorID(static_cast<detid_t>(i));
+    }
+    ws2->setInstrument(inst);
+    return ws2;
+  }
+
   std::string outputFile;
   std::string entryName;
   std::string dataName;
diff --git a/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h b/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h
index 3079799086ac2b8d83ee4c7a1892de7f29aefcae..33fd493ebb0ffea5469f8dceb8148f5dbcd97d25 100644
--- a/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h
+++ b/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h
@@ -5,6 +5,7 @@
 #include "MantidDataObjects/Peak.h"
 
 #include <boost/variant.hpp>
+#include <list>
 
 namespace Mantid {
 namespace DataObjects {
diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h b/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h
index abb01237fd54a1de0e8dccbc63e221e33ddd03be..6b18d34700013e51da3f8607e3e57e181afabbe9 100644
--- a/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h
+++ b/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h
@@ -7,6 +7,7 @@
 
 #include "MantidKernel/Exception.h"
 #include <functional>
+#include <map>
 #include <boost/spirit/include/qi.hpp>
 
 namespace Mantid {
diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h b/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h
index 2032ca0603b9d75aed9522717e0e0445138f594a..0de5373f0a9f423cb7d0ca0e9dfab984425e5010 100644
--- a/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h
+++ b/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h
@@ -10,6 +10,7 @@
 #include <vector>
 #include <string>
 #include <set>
+#include <map>
 
 #include "MantidGeometry/Crystal/SymmetryOperation.h"
 #include "MantidGeometry/Crystal/Group.h"
diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h
index 30dd5b1603e8e81f29754c69f72cdb0ee8a1c620..b0e3c5c1195225f3842ec865b9899757bb1c50da 100644
--- a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h
+++ b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h
@@ -8,6 +8,7 @@
 #include "MantidKernel/RegistrationHelper.h"
 
 #include <boost/make_shared.hpp>
+#include <map>
 #include <unordered_set>
 
 namespace Mantid {
diff --git a/Framework/Geometry/inc/MantidGeometry/IComponent.h b/Framework/Geometry/inc/MantidGeometry/IComponent.h
index 0c00673b5bc9b6282d9e81cf57ff0f806a6d2168..7da1732bd2b6d771798707144a166d66f62de999 100644
--- a/Framework/Geometry/inc/MantidGeometry/IComponent.h
+++ b/Framework/Geometry/inc/MantidGeometry/IComponent.h
@@ -1,12 +1,10 @@
 #ifndef MANTID_GEOMETRY_ICOMPONENT_H_
 #define MANTID_GEOMETRY_ICOMPONENT_H_
 
-//----------------------------------------------------------------------
-// Includes
-//----------------------------------------------------------------------
 #include "MantidGeometry/DllConfig.h"
 #include "MantidKernel/V3D.h"
 
+#include <map>
 #include <string>
 #include <vector>
 #include <set>
@@ -22,9 +20,6 @@ class Quat;
 }
 
 namespace Geometry {
-//---------------------------------------------------------
-// Forward declarations
-//---------------------------------------------------------
 class IComponent;
 class BoundingBox;
 class ParameterMap;
diff --git a/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h b/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h
index dd57786c6369ac5955e2cba182ca91b48f39c604..e22c94171804f85fcfef5912cdf821748886c3e6 100644
--- a/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h
+++ b/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h
@@ -4,6 +4,7 @@
 #include "MantidGeometry/DllConfig.h"
 #include "MantidKernel/V3D.h"
 #include <complex>
+#include <list>
 
 namespace Mantid {
 
diff --git a/Framework/Geometry/src/Instrument.cpp b/Framework/Geometry/src/Instrument.cpp
index 963aea28060c6f790ecc7452ffda255c4dce8fb6..712e7f331fe8a0799f63507354b55430e98efe19 100644
--- a/Framework/Geometry/src/Instrument.cpp
+++ b/Framework/Geometry/src/Instrument.cpp
@@ -12,6 +12,7 @@
 #include "MantidKernel/PhysicalConstants.h"
 #include "MantidKernel/make_unique.h"
 
+#include <nexus/NeXusFile.hpp>
 #include <boost/make_shared.hpp>
 #include <queue>
 
diff --git a/Framework/Geometry/src/Instrument/ParameterMap.cpp b/Framework/Geometry/src/Instrument/ParameterMap.cpp
index 64b6b0e49cd11cf53a22b2d277ff71f608de3cde..50bcb188e0179ee2d820e8eda60bf34cd41b09a6 100644
--- a/Framework/Geometry/src/Instrument/ParameterMap.cpp
+++ b/Framework/Geometry/src/Instrument/ParameterMap.cpp
@@ -7,6 +7,7 @@
 #include "MantidGeometry/Instrument.h"
 #include "MantidGeometry/Instrument/ParameterFactory.h"
 #include <cstring>
+#include <nexus/NeXusFile.hpp>
 #include <boost/algorithm/string.hpp>
 
 #ifdef _WIN32
diff --git a/Framework/Kernel/inc/MantidKernel/V3D.h b/Framework/Kernel/inc/MantidKernel/V3D.h
index 938c88d012bbfb1a5543a7170c47b675fe35e975..36547602a3c5c4d0a5295144596d80b3f970f7ba 100644
--- a/Framework/Kernel/inc/MantidKernel/V3D.h
+++ b/Framework/Kernel/inc/MantidKernel/V3D.h
@@ -2,9 +2,13 @@
 #define MANTID_KERNEL_V3D_H_
 
 #include <cmath>
+#include <iosfwd>
 #include <vector>
 #include "MantidKernel/DllConfig.h"
-#include <nexus/NeXusFile.hpp>
+
+namespace NeXus {
+class File;
+}
 
 namespace Mantid {
 namespace Kernel {
diff --git a/Framework/Kernel/src/V3D.cpp b/Framework/Kernel/src/V3D.cpp
index a3f5c4f8cec9298307ab30109bda2fad4dcc7761..1a95a402e68d05bdc14d36d0649dc99fff762c39 100644
--- a/Framework/Kernel/src/V3D.cpp
+++ b/Framework/Kernel/src/V3D.cpp
@@ -9,6 +9,7 @@
 #include "MantidKernel/Exception.h"
 #include "MantidKernel/Quat.h"
 #include <boost/math/common_factor.hpp>
+#include <nexus/NeXusFile.hpp>
 
 namespace Mantid {
 namespace Kernel {
diff --git a/Framework/MDAlgorithms/src/LoadILLAscii.cpp b/Framework/MDAlgorithms/src/LoadILLAscii.cpp
index 572e7af1de85cea123dca48c5f539cba90cff6d3..a33d44958c8bf7e7ee87c44ba9d685296b182d41 100644
--- a/Framework/MDAlgorithms/src/LoadILLAscii.cpp
+++ b/Framework/MDAlgorithms/src/LoadILLAscii.cpp
@@ -21,6 +21,7 @@
 #include "MantidKernel/TimeSeriesProperty.h"
 #include "MantidKernel/UnitFactory.h"
 #include "MantidMDAlgorithms/LoadILLAsciiHelper.h"
+#include "MantidGeometry/IDetector.h"
 
 #include <Poco/TemporaryFile.h>
 #include <boost/shared_ptr.hpp>