diff --git a/Code/Mantid/Framework/Algorithms/src/MuonGroupDetectors.cpp b/Code/Mantid/Framework/Algorithms/src/MuonGroupDetectors.cpp index bf5b2b211cbe..c1cdc3e12c47 100644 --- a/Code/Mantid/Framework/Algorithms/src/MuonGroupDetectors.cpp +++ b/Code/Mantid/Framework/Algorithms/src/MuonGroupDetectors.cpp @@ -104,17 +104,22 @@ namespace Algorithms // Compile the groups for ( auto rowIt = nonEmptyRows.begin(); rowIt != nonEmptyRows.end(); ++rowIt ) { - // Not "detectors" as such, but workspace indices. For Muons there is only one detector for - // workspace index in the data before grouping. - std::vector& detectors = table->cell< std::vector >(*rowIt, 0); - // Group index in the output workspace size_t groupIndex = static_cast( std::distance(nonEmptyRows.begin(), rowIt) ); + std::vector& detectorIDs = table->cell< std::vector >(*rowIt, 0); + + // Recieve detector IDs, but need workspace indices to group, so convert + std::vector wsIndices; + inWS->getIndicesFromDetectorIDs(detectorIDs, wsIndices); + + if ( wsIndices.size() != detectorIDs.size() ) + throw std::invalid_argument("Some of the detector IDs were not found"); + // We will be setting them anew outWS->getSpectrum(groupIndex)->clearDetectorIDs(); - for(auto detIt = detectors.begin(); detIt != detectors.end(); detIt++) + for(auto detIt = wsIndices.begin(); detIt != wsIndices.end(); detIt++) { for( size_t i = 0; i < inWS->blocksize(); ++i ) { @@ -131,7 +136,7 @@ namespace Algorithms } // Using the first detector X values - outWS->dataX(groupIndex) = inWS->dataX(detectors.front()); + outWS->dataX(groupIndex) = inWS->dataX(wsIndices.front()); outWS->getSpectrum(groupIndex)->setSpectrumNo( static_cast(groupIndex + 1) ); } diff --git a/Code/Mantid/Framework/Algorithms/test/MuonGroupDetectorsTest.h b/Code/Mantid/Framework/Algorithms/test/MuonGroupDetectorsTest.h index 0cd76a890b22..2603c3905712 100644 --- a/Code/Mantid/Framework/Algorithms/test/MuonGroupDetectorsTest.h +++ b/Code/Mantid/Framework/Algorithms/test/MuonGroupDetectorsTest.h @@ -38,6 +38,9 @@ class MuonGroupDetectorsTest : public CxxTest::TestSuite MatrixWorkspace_sptr inWS = WorkspaceCreationHelper::Create2DWorkspace123(5,3); + for ( size_t i = 0; i < inWS->getNumberHistograms(); ++i ) + inWS->getSpectrum(i)->setDetectorID( static_cast(i + 1) ); // To be consistent with how LoadMuonNexus works + TableWorkspace_sptr grouping = createDetectorGroupingTable(); MuonGroupDetectors alg; @@ -71,11 +74,11 @@ class MuonGroupDetectorsTest : public CxxTest::TestSuite TS_ASSERT_EQUALS( ws->getSpectrum(1)->getSpectrumNo(), 2); std::set d1; - d1.insert(0); d1.insert(1); + d1.insert(1); d1.insert(2); TS_ASSERT_EQUALS( ws->getSpectrum(0)->getDetectorIDs(), d1 ); std::set d2; - d2.insert(2); d2.insert(3); d2.insert(4); + d2.insert(3); d2.insert(4); d2.insert(5); TS_ASSERT_EQUALS( ws->getSpectrum(1)->getDetectorIDs(), d2 ); } @@ -92,12 +95,12 @@ class MuonGroupDetectorsTest : public CxxTest::TestSuite t->addColumn("vector_int", "Detectors"); std::vector group1; - group1.push_back(0); group1.push_back(1); + group1.push_back(1); group1.push_back(2); TableRow row1 = t->appendRow(); row1 << group1; std::vector group2; - group2.push_back(2); group2.push_back(3); group2.push_back(4); + group2.push_back(3); group2.push_back(4); group2.push_back(5); TableRow row2 = t->appendRow(); row2 << group2; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp b/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp index 04f357208c35..62afd0347ba1 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp @@ -635,7 +635,9 @@ namespace Mantid for ( auto it = begin; it != end; ++it ) { - grouping[*it].push_back( static_cast( std::distance(begin,it) ) ); + // Add detector ID to the list of group detectors. Detector ID is always + // spectra index + 1 + grouping[*it].push_back( static_cast( std::distance(begin,it) ) + 1 ); } for ( auto it = grouping.begin(); it != grouping.end(); ++it ) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h index 073681a385b8..931a036e2344 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h @@ -532,11 +532,11 @@ class LoadMuonNexus1Test : public CxxTest::TestSuite TS_ASSERT_EQUALS( e1.size(), 16); TS_ASSERT_EQUALS( e2.size(), 16); - TS_ASSERT_EQUALS( e1[0], 0 ); - TS_ASSERT_EQUALS( e1[15], 15); + TS_ASSERT_EQUALS( e1[0], 1 ); + TS_ASSERT_EQUALS( e1[15], 16); - TS_ASSERT_EQUALS( e2[0], 16 ); - TS_ASSERT_EQUALS( e2[15], 31 ); + TS_ASSERT_EQUALS( e2[0], 17 ); + TS_ASSERT_EQUALS( e2[15], 32 ); } AnalysisDataService::Instance().remove(outWSName); @@ -586,11 +586,11 @@ class LoadMuonNexus1Test : public CxxTest::TestSuite TS_ASSERT_EQUALS( e1.size(), 32); TS_ASSERT_EQUALS( e2.size(), 32); - TS_ASSERT_EQUALS( e1[0], 32 ); - TS_ASSERT_EQUALS( e1[31], 63 ); + TS_ASSERT_EQUALS( e1[0], 33 ); + TS_ASSERT_EQUALS( e1[31], 64 ); - TS_ASSERT_EQUALS( e2[0], 0 ); - TS_ASSERT_EQUALS( e2[31], 31 ); + TS_ASSERT_EQUALS( e2[0], 1 ); + TS_ASSERT_EQUALS( e2[31], 32 ); } TableWorkspace_sptr table2 = boost::dynamic_pointer_cast( detectorGrouping->getItem(1) ); @@ -608,11 +608,11 @@ class LoadMuonNexus1Test : public CxxTest::TestSuite TS_ASSERT_EQUALS( e1.size(), 32); TS_ASSERT_EQUALS( e2.size(), 32); - TS_ASSERT_EQUALS( e1[0], 32 ); - TS_ASSERT_EQUALS( e1[31], 63 ); + TS_ASSERT_EQUALS( e1[0], 33 ); + TS_ASSERT_EQUALS( e1[31], 64 ); - TS_ASSERT_EQUALS( e2[0], 0 ); - TS_ASSERT_EQUALS( e2[31], 31); + TS_ASSERT_EQUALS( e2[0], 1 ); + TS_ASSERT_EQUALS( e2[31], 32); } }