Skip to content

Commit

Permalink
Refs #4814. Got the test working again and modernized a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Feb 24, 2012
1 parent 1002d53 commit f691dda
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
21 changes: 20 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/MedianDetectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ namespace Mantid
MatrixWorkspace_sptr countsWS = integrateSpectra(m_inputWS, m_minSpec, m_maxSpec,
m_rangeLower, m_rangeUpper, true);

MatrixWorkspace_sptr maskWS = this->generateEmptyMask(countsWS);

// 1. Calculate the median
const bool excludeZeroes = getProperty("ExcludeZeroesFromMedian");
Expand All @@ -107,6 +106,7 @@ namespace Mantid
median = calculateMedian(countsWS, excludeZeroes);
g_log.information() << "Median value with outliers removed = " << median << "\n";

MatrixWorkspace_sptr maskWS = this->generateEmptyMask(countsWS);
numFailed += doDetectorTests(countsWS, median, maskWS);
g_log.information() << "Median test results:\n"
<< "\tNumber of failures - " << numFailed << "\n";
Expand Down Expand Up @@ -208,10 +208,25 @@ namespace Mantid
const int64_t nhist = static_cast<int64_t>(countsWS->getNumberHistograms());
int numFailed(0);

bool checkForMask = false;
Geometry::Instrument_const_sptr instrument = countsWS->getInstrument();
if (instrument != NULL)
{
checkForMask = ((instrument->getSource() != NULL) && (instrument->getSample() != NULL));
}

PARALLEL_FOR1(countsWS)
for(int64_t i = 0; i < nhist; ++i)
{
const double value = countsWS->readY(i)[0];
if ((value == 0.) && checkForMask)
{
const std::set<detid_t>& detids = countsWS->getSpectrum(i)->getDetectorIDs();
if (instrument->isDetectorMasked(detids))
{
numFailed -= 1; // it was already masked
}
}
if( (value < out_lo*median) && (value > 0.0) )
{
countsWS->maskWorkspaceIndex(i);
Expand All @@ -225,6 +240,8 @@ namespace Mantid
++numFailed;
}
}
PARALLEL_CHECK_INTERUPT_REGION

return numFailed;
}

Expand All @@ -242,6 +259,7 @@ namespace Mantid
const double median, API::MatrixWorkspace_sptr maskWS)
{
g_log.debug("Applying the criteria to find failing detectors");

// A spectra can't fail if the statistics show its value is consistent with the mean value,
// check the error and how many errorbars we are away
const double minSigma = getProperty("SignificanceTest");
Expand Down Expand Up @@ -282,6 +300,7 @@ namespace Mantid
if (instrument->isMonitor(detids))
{
// Don't include in calculation but don't mask it
continue;
}
}

Expand Down
56 changes: 21 additions & 35 deletions Code/Mantid/Framework/Algorithms/test/MedianDetectorTestTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ using namespace Mantid::API;
using namespace Mantid::Algorithms;
using namespace Mantid::DataObjects;

const int THEMASKED(40);
const int SAVEDBYERRORBAR(143);
const int Nhist(144);

//these values must match the values in MedianDetectorTest.h
const double BAD_VAL(1.);
const double GOOD_VAL(0.);

class MedianDetectorTestTest : public CxxTest::TestSuite
{
public:
Expand Down Expand Up @@ -57,8 +65,8 @@ class MedianDetectorTestTest : public CxxTest::TestSuite
MatrixWorkspace_const_sptr input;
input = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(m_IWSName);
TS_ASSERT(input);
TS_ASSERT(input->getInstrument()->getDetector(THEMASKED).get()->isMasked());
//TS_ASSERT(input->getInstrument()->isDetectorMasked(input->getSpectrum(THEMASKED)->getDetectorIDs()));

MatrixWorkspace_sptr outputMat = boost::dynamic_pointer_cast<MatrixWorkspace>(output);;
TS_ASSERT( outputMat );
TS_ASSERT_EQUALS( outputMat->YUnit(), "" );
Expand All @@ -72,32 +80,18 @@ class MedianDetectorTestTest : public CxxTest::TestSuite
// the numbers below are threshold values that were found by trial and error running these tests
const int firstGoodSpec = 36;
const int lastGoodSpec = 95;
for (int lHist = 1; lHist < firstGoodSpec; lHist++)
{
TS_ASSERT_EQUALS(outputMat->readY(lHist).front(), BAD_VAL )
}
for (int lHist=firstGoodSpec; lHist < THEMASKED-1; lHist++)
{
TS_ASSERT_EQUALS(
outputMat->readY(lHist).front(), GOOD_VAL );
}
TS_ASSERT_EQUALS(outputMat->readY(THEMASKED-1).front(), BAD_VAL )
for (int lHist=THEMASKED; lHist <= lastGoodSpec; lHist++)
{
TS_ASSERT_EQUALS(
outputMat->readY(lHist).front(), GOOD_VAL )
}
for (int lHist = lastGoodSpec+1; lHist < SAVEDBYERRORBAR; lHist++)
for (int lHist=0; lHist < Nhist; lHist++)
{
TS_ASSERT_EQUALS(
outputMat->readY(lHist).front(), BAD_VAL )
// std::cout << " " << lHist << " " << outputMat->readY(lHist).front() << std::endl;
double expected = BAD_VAL;
if (lHist >= firstGoodSpec && lHist <= lastGoodSpec)
expected = GOOD_VAL;
if (lHist == THEMASKED)
expected = BAD_VAL;
else if (lHist == SAVEDBYERRORBAR)
expected = GOOD_VAL;
TS_ASSERT_EQUALS(outputMat->readY(lHist).front(), expected );
}
for (int lHist = SAVEDBYERRORBAR; lHist < Nhist; lHist++)
{
TS_ASSERT_EQUALS(
outputMat->readY(lHist).front(), GOOD_VAL )
}

}

MedianDetectorTestTest() : m_IWSName("MedianDetectorTestInput")
Expand Down Expand Up @@ -165,11 +159,7 @@ class MedianDetectorTestTest : public CxxTest::TestSuite
m_2DWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");

// mask the detector
Geometry::ParameterMap* m_Pmap = &(m_2DWS->instrumentParameters());
boost::shared_ptr<const Instrument> instru = m_2DWS->getInstrument();
IDetector_const_sptr toMask = instru->getDetector(THEMASKED);
TS_ASSERT(toMask)
m_Pmap->addBool(toMask.get(), "masked", true);
m_2DWS->maskWorkspaceIndex(THEMASKED);
}

private:
Expand All @@ -188,10 +178,6 @@ class MedianDetectorTestTest : public CxxTest::TestSuite
std::string m_IWSName, m_OFileName;
Workspace2D_sptr m_2DWS;
double m_YSum;
enum spectraIndexConsts{ THEMASKED = 40, SAVEDBYERRORBAR = 143, Nhist = 144 };
//these values must match the values in MedianDetectorTest.h
enum FLAGS{ BAD_VAL = 1, GOOD_VAL = 0 };

};

#endif /*WBVMEDIANTESTTEST_H_*/

0 comments on commit f691dda

Please sign in to comment.