diff --git a/Framework/Algorithms/src/ExtractMask.cpp b/Framework/Algorithms/src/ExtractMask.cpp index c595ccdad76938f19932bd873cdbfb7bc8bc72ac..2d474bf92b4c81227dcf97f01509a07d7ce648c5 100644 --- a/Framework/Algorithms/src/ExtractMask.cpp +++ b/Framework/Algorithms/src/ExtractMask.cpp @@ -54,9 +54,12 @@ void ExtractMask::exec() { std::vector<detid_t> detectorList; const auto &detInfo = inputWS->detectorInfo(); const auto &detIds = detInfo.detectorIDs(); - for (size_t i = 0; i < detInfo.size(); ++i) - if (detInfo.isMasked(i)) + for (size_t i = 0; i < detInfo.size(); ++i) { + if ((inputWSIsSpecial && inputMaskWS->isMasked(detIds[i])) || + detInfo.isMasked(i)) { detectorList.push_back(detIds[i]); + } + } // Create a new workspace for the results, copy from the input to ensure // that we copy over the instrument and current masking diff --git a/Framework/Algorithms/test/ExtractMaskTest.h b/Framework/Algorithms/test/ExtractMaskTest.h index e9803cf60e6c508e7227aaed47f558044a704f42..94d2c8503d51653c5e4398497cafaaeae39d1004 100644 --- a/Framework/Algorithms/test/ExtractMaskTest.h +++ b/Framework/Algorithms/test/ExtractMaskTest.h @@ -6,6 +6,7 @@ #include "MantidAlgorithms/ExtractMask.h" #include "MantidDataObjects/MaskWorkspace.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" +#include "MantidAPI/SpectrumInfo.h" using namespace Mantid::API; using namespace Mantid::DataObjects; @@ -59,6 +60,67 @@ public: AnalysisDataService::Instance().remove(outputWS->getName()); } + void test_That_Masked_Detector_List_Populated_When_Passed_A_Mask_Workspace() { + // Create a simple test workspace + const int nvectors(50), nbins(10); + Workspace2D_sptr inputWS = + WorkspaceCreationHelper::create2DWorkspace(nvectors, nbins); + // Mask every 10th spectra + std::set<int64_t> maskedIndices; + for (int i = 0; i < 50; i += 10) { + maskedIndices.insert(i); + } + // A few randoms + maskedIndices.insert(5); + maskedIndices.insert(23); + maskedIndices.insert(37); + inputWS = WorkspaceCreationHelper::maskSpectra(inputWS, maskedIndices); + const std::string inputName("inputWSMask"); + AnalysisDataService::Instance().add(inputName, inputWS); + MaskWorkspace_sptr inputWSMask = runExtractMask(inputName); + std::vector<Mantid::detid_t> expectedDetectorList = {1, 6, 11, 21, + 24, 31, 38, 41}; + + std::vector<Mantid::detid_t> detectorList; + + TS_ASSERT_THROWS_NOTHING( + detectorList = runExtractMaskReturnList(inputWSMask->getName())); + TS_ASSERT_EQUALS(detectorList, expectedDetectorList) + + AnalysisDataService::Instance().remove(inputName); + AnalysisDataService::Instance().remove(inputWSMask->getName()); + } + + void test_That_Masked_Detector_List_Populated_When_Passed_A_Workspace() { + // Create a simple test workspace + const int nvectors(50), nbins(10); + Workspace2D_sptr inputWS = + WorkspaceCreationHelper::create2DWorkspace(nvectors, nbins); + // Mask every 10th spectra + std::set<int64_t> maskedIndices; + for (int i = 0; i < 50; i += 10) { + maskedIndices.insert(i); + } + // A few randoms + maskedIndices.insert(5); + maskedIndices.insert(23); + maskedIndices.insert(37); + inputWS = WorkspaceCreationHelper::maskSpectra(inputWS, maskedIndices); + const std::string inputName("inputWS"); + AnalysisDataService::Instance().add(inputName, inputWS); + + std::vector<Mantid::detid_t> expectedDetectorList = {1, 6, 11, 21, + 24, 31, 38, 41}; + + std::vector<Mantid::detid_t> detectorList; + + TS_ASSERT_THROWS_NOTHING(detectorList = + runExtractMaskReturnList(inputName)); + TS_ASSERT_EQUALS(detectorList, expectedDetectorList) + + AnalysisDataService::Instance().remove(inputName); + } + private: // The input workspace should be in the analysis data service MaskWorkspace_sptr runExtractMask(const std::string &inputName) { @@ -82,6 +144,21 @@ private: } } + std::vector<Mantid::detid_t> + runExtractMaskReturnList(const std::string &inputName) { + ExtractMask maskExtractor; + maskExtractor.initialize(); + maskExtractor.setPropertyValue("InputWorkspace", inputName); + const std::string outputName("masking"); + maskExtractor.setPropertyValue("OutputWorkspace", outputName); + maskExtractor.setRethrows(true); + maskExtractor.execute(); + std::vector<Mantid::detid_t> detectorList = + maskExtractor.getProperty("DetectorList"); + AnalysisDataService::Instance().remove(outputName); + return detectorList; + } + void doTest(MatrixWorkspace_const_sptr inputWS, MaskWorkspace_const_sptr outputWS) { TS_ASSERT_EQUALS(outputWS->blocksize(), 1); diff --git a/docs/source/algorithms/ExtractMask-v1.rst b/docs/source/algorithms/ExtractMask-v1.rst index 78f5160f5b756fc53865afea7526231ee3fdb4d1..1f13ca0e28b5f4324f99ae8718128bbd45487917 100644 --- a/docs/source/algorithms/ExtractMask-v1.rst +++ b/docs/source/algorithms/ExtractMask-v1.rst @@ -18,6 +18,8 @@ new MatrixWorkspace with a single X bin where: The spectra containing 0 are also marked as masked and the instrument link is preserved so that the instrument view functions correctly. +A list of masked detector IDs is also output. Note this contains the detector IDs which +are masked rather than the index or spectrum number. Usage ----- @@ -29,11 +31,11 @@ Usage #create a workspace with a 3*3 pixel detector bankPixelWidth = 3 ws = CreateSampleWorkspace(NumBanks=1,BankPixelWidth=bankPixelWidth) - + #Mask out every other detector MaskDetectors(ws,WorkspaceIndexList=range(0,bankPixelWidth*bankPixelWidth,2)) - wsMask = ExtractMask(ws) + wsMask, maskList = ExtractMask(ws) #This mask can then be applied to another workspace ws2 = CreateSampleWorkspace(NumBanks=1,BankPixelWidth=bankPixelWidth) @@ -43,6 +45,9 @@ Usage print("n ws ws2") for i in range (ws.getNumberHistograms()): print("%i %-5s %s" % (i, ws.getDetector(i).isMasked(), ws2.getDetector(i).isMasked())) + + print("\nMasked detector IDs") + print(maskList) Output: @@ -59,6 +64,9 @@ Output: 6 True True 7 False False 8 True True + + Masked detector IDs + [ 9 11 13 15 17] .. categories:: diff --git a/docs/source/release/v3.13.0/framework.rst b/docs/source/release/v3.13.0/framework.rst index fdd7ddf079981fbbe30617fd15a43d310a9c4851..09108138319a9e1469e1e578fc5dd790eb74dae2 100644 --- a/docs/source/release/v3.13.0/framework.rst +++ b/docs/source/release/v3.13.0/framework.rst @@ -10,7 +10,6 @@ Framework Changes improvements, followed by bug fixes. - Algorithms ---------- @@ -36,5 +35,6 @@ Bug fixes ######### - The documentation of the algorithm :ref:`algm-CreateSampleWorkspace` did not match its implementation. The axis in beam direction will now be correctly described as Z instead of X. +- The :ref:`ExtractMask <algm-ExtractMask>` algorithm now returns a non-empty list of detector ID's when given a MaskWorkspace. :ref:`Release 3.13.0 <v3.13.0>`