From d5877f2eeca375a3a24b486591d64ccf01137b7c Mon Sep 17 00:00:00 2001
From: Vickie Lynch <lynchve@ornl.gov>
Date: Mon, 29 Aug 2011 20:23:35 +0000
Subject: [PATCH] Refs #3636 Summing 2 MaskWorkspaces for calibration is
 correct now

---
 .../Framework/Algorithms/src/GetDetectorOffsets.cpp       | 8 ++++++--
 .../PythonAlgorithms/CalibrateRectangularDetectors.py     | 4 +++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Code/Mantid/Framework/Algorithms/src/GetDetectorOffsets.cpp b/Code/Mantid/Framework/Algorithms/src/GetDetectorOffsets.cpp
index 1a6000b87c0..f48cb324fa4 100644
--- a/Code/Mantid/Framework/Algorithms/src/GetDetectorOffsets.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/GetDetectorOffsets.cpp
@@ -94,6 +94,8 @@ namespace Mantid
       OffsetsWorkspace_sptr outputW(new OffsetsWorkspace(inputW->getInstrument()));
       // Create the output MaskWorkspace
       MatrixWorkspace_sptr maskWS(new SpecialWorkspace2D(inputW->getInstrument()));
+      //To get the workspace index from the detector ID
+      detid2index_map * pixel_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap(true);
 
       // Fit all the spectra with a gaussian
       Progress prog(this, 0, 1.0, nspec);
@@ -103,11 +105,11 @@ namespace Mantid
         PARALLEL_START_INTERUPT_REGION
         // Fit the peak
         double offset=fitSpectra(wi);
-        maskWS->dataY(wi)[0] = 1.0;
+        double mask=1.0;
         if (std::abs(offset) > maxOffset)
         { 
           offset = 0.0;
-          maskWS->maskWorkspaceIndex(wi);
+          mask = 0.0;
         }
 
         // Get the list of detectors in this pixel
@@ -121,6 +123,8 @@ namespace Mantid
           for (it = dets.begin(); it != dets.end(); it++)
           {
             outputW->setValue(*it, offset);
+            if (mask == 0.) maskWS->maskWorkspaceIndex((*pixel_to_wi)[*it]);
+            else maskWS->dataY((*pixel_to_wi)[*it])[0] = mask;
           }
         }
         prog.report();
diff --git a/Code/Mantid/Framework/PythonAPI/PythonAlgorithms/CalibrateRectangularDetectors.py b/Code/Mantid/Framework/PythonAPI/PythonAlgorithms/CalibrateRectangularDetectors.py
index 022b0266bd1..407e52d7879 100644
--- a/Code/Mantid/Framework/PythonAPI/PythonAlgorithms/CalibrateRectangularDetectors.py
+++ b/Code/Mantid/Framework/PythonAPI/PythonAlgorithms/CalibrateRectangularDetectors.py
@@ -218,10 +218,12 @@ class CalibrateRectangularDetectors(PythonAlgorithm):
                 WorkspaceIndexMin=self._lastpixel+1, WorkspaceIndexMax=wksp.getNumberHistograms()-1, XMin=self._peakmin2, XMax=self._peakmax2)
             # Get offsets for pixels using interval around cross correlations center and peak at peakpos (d-Spacing)
             GetDetectorOffsets(InputWorkspace=str(wksp)+"cc2", OutputWorkspace=str(wksp)+"offset2", Step=abs(self._binning[1]),
-                DReference=self._peakpos2, XMin=-self._ccnumber, XMax=self._ccnumber, MaxOffset=self._maxoffset, MaskWorkspace=str(wksp)+"mask",)
+                DReference=self._peakpos2, XMin=-self._ccnumber, XMax=self._ccnumber, MaxOffset=self._maxoffset, MaskWorkspace=str(wksp)+"mask2",)
             Plus(LHSWorkspace=str(wksp)+"offset", RHSWorkspace=str(wksp)+"offset2",OutputWorkspace=str(wksp)+"offset")
+            Plus(LHSWorkspace=str(wksp)+"mask", RHSWorkspace=str(wksp)+"mask2",OutputWorkspace=str(wksp)+"mask")
             mtd.deleteWorkspace(str(wksp)+"cc2")
             mtd.deleteWorkspace(str(wksp)+"offset2")
+            mtd.deleteWorkspace(str(wksp)+"mask2")
             mtd.releaseFreeMemory()
         CreateGroupingWorkspace(InputWorkspace=wksp, GroupNames=groups, OutputWorkspace=str(wksp)+"group")
         lcinst = str(self._instrument)
-- 
GitLab