From 343a822fac1e264d49cdc68e3db020554787c78d Mon Sep 17 00:00:00 2001
From: Lamar Moore <lamar.moore@stfc.ac.uk>
Date: Wed, 22 Aug 2018 18:18:44 +0100
Subject: [PATCH] Fix det relative positions and failing unit tests

---
 Framework/NexusGeometry/src/InstrumentBuilder.cpp      | 3 ++-
 Framework/NexusGeometry/src/NexusGeometryParser.cpp    | 2 +-
 Framework/NexusGeometry/test/NexusGeometryParserTest.h | 7 ++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Framework/NexusGeometry/src/InstrumentBuilder.cpp b/Framework/NexusGeometry/src/InstrumentBuilder.cpp
index 544143e818d..4b62666a0a2 100644
--- a/Framework/NexusGeometry/src/InstrumentBuilder.cpp
+++ b/Framework/NexusGeometry/src/InstrumentBuilder.cpp
@@ -96,7 +96,8 @@ void InstrumentBuilder::doAddTube(
   for (size_t i = 0; i < tube.detPositions().size(); ++i) {
     auto *detector = new Geometry::Detector(baseName + std::to_string(i),
                                             tube.detIDs()[i], objComp);
-    detector->translate(Mantid::Kernel::toV3D(tube.detPositions()[i]));
+    detector->translate(
+        Mantid::Kernel::toV3D(tube.detPositions()[i] - tube.tubePosition()));
     detector->setShape(pixelShape);
     objComp->add(detector);
     m_instrument->markAsDetectorIncomplete(detector);
diff --git a/Framework/NexusGeometry/src/NexusGeometryParser.cpp b/Framework/NexusGeometry/src/NexusGeometryParser.cpp
index f4a508cc6ab..5b819a9b8eb 100644
--- a/Framework/NexusGeometry/src/NexusGeometryParser.cpp
+++ b/Framework/NexusGeometry/src/NexusGeometryParser.cpp
@@ -637,7 +637,7 @@ extractInstrument(const H5File &file, const Group &root) {
     std::vector<detail::TubeBuilder> tubes;
     if (searchTubes) {
       tubes =
-          TubeHelpers::findAndSortTubes(*detShape, pixelOffsets, detectorIds);
+          TubeHelpers::findAndSortTubes(*detShape, detectorPixels, detectorIds);
       builder.addTubes(bankName, tubes, detShape);
     } else {
       for (size_t i = 0; i < detectorIds.size(); ++i) {
diff --git a/Framework/NexusGeometry/test/NexusGeometryParserTest.h b/Framework/NexusGeometry/test/NexusGeometryParserTest.h
index 72ebde24bac..0581dbc408e 100644
--- a/Framework/NexusGeometry/test/NexusGeometryParserTest.h
+++ b/Framework/NexusGeometry/test/NexusGeometryParserTest.h
@@ -52,10 +52,11 @@ public:
     auto beamline = extractBeamline(*instrument);
     auto componentInfo = std::move(beamline.first);
     auto detectorInfo = std::move(beamline.second);
+
     TSM_ASSERT_EQUALS("Detectors + 1 monitor", detectorInfo->size(),
                       128 * 2 + 1);
-    TSM_ASSERT_EQUALS("Detectors + 2 banks + root + source + sample",
-                      componentInfo->size(), detectorInfo->size() + 5);
+    TSM_ASSERT_EQUALS("Detectors + 2 banks + 16 tubes + root + source + sample",
+                      componentInfo->size(), detectorInfo->size() + 21);
     // Check 128 detectors in first bank
     TS_ASSERT_EQUALS(
         128,
@@ -68,7 +69,7 @@ public:
     // Check 128 detectors in second bank
     TS_ASSERT_EQUALS(
         128,
-        componentInfo->detectorsInSubtree(componentInfo->root() - 4).size());
+        componentInfo->detectorsInSubtree(componentInfo->root() - 12).size());
   }
 
   void test_source_is_where_expected() {
-- 
GitLab