Skip to content

Commit

Permalink
Refs #8550. Use detector IDs for grouping instead of spectra indices.
Browse files Browse the repository at this point in the history
This is consistent to how GroupDetectors works and how information
is stored in the files.
  • Loading branch information
arturbekasov committed Dec 9, 2013
1 parent 958d00f commit 9176350
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
17 changes: 11 additions & 6 deletions Code/Mantid/Framework/Algorithms/src/MuonGroupDetectors.cpp
Expand Up @@ -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<int>& detectors = table->cell< std::vector<int> >(*rowIt, 0);

// Group index in the output workspace
size_t groupIndex = static_cast<size_t>( std::distance(nonEmptyRows.begin(), rowIt) );

std::vector<int>& detectorIDs = table->cell< std::vector<int> >(*rowIt, 0);

// Recieve detector IDs, but need workspace indices to group, so convert
std::vector<size_t> 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 )
{
Expand All @@ -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<specid_t>(groupIndex + 1) );
}
Expand Down
11 changes: 7 additions & 4 deletions Code/Mantid/Framework/Algorithms/test/MuonGroupDetectorsTest.h
Expand Up @@ -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<detid_t>(i + 1) ); // To be consistent with how LoadMuonNexus works

TableWorkspace_sptr grouping = createDetectorGroupingTable();

MuonGroupDetectors alg;
Expand Down Expand Up @@ -71,11 +74,11 @@ class MuonGroupDetectorsTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( ws->getSpectrum(1)->getSpectrumNo(), 2);

std::set<detid_t> d1;
d1.insert(0); d1.insert(1);
d1.insert(1); d1.insert(2);
TS_ASSERT_EQUALS( ws->getSpectrum(0)->getDetectorIDs(), d1 );

std::set<detid_t> 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 );
}

Expand All @@ -92,12 +95,12 @@ class MuonGroupDetectorsTest : public CxxTest::TestSuite
t->addColumn("vector_int", "Detectors");

std::vector<int> 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<int> 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;

Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp
Expand Up @@ -635,7 +635,9 @@ namespace Mantid

for ( auto it = begin; it != end; ++it )
{
grouping[*it].push_back( static_cast<int>( 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<int>( std::distance(begin,it) ) + 1 );
}

for ( auto it = grouping.begin(); it != grouping.end(); ++it )
Expand Down
24 changes: 12 additions & 12 deletions Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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<TableWorkspace>( detectorGrouping->getItem(1) );
Expand All @@ -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);

}
}
Expand Down

0 comments on commit 9176350

Please sign in to comment.