Skip to content

Commit

Permalink
Refs #4814. Got rid of the hack converting the output workspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Feb 21, 2012
1 parent c410162 commit 5089062
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace Mantid
/// Mask the outlier values to get a better median value
int maskOutliers(const double median, API::MatrixWorkspace_sptr countsWS);
/// Do the tests and mask those that fail
int doDetectorTests(const API::MatrixWorkspace_sptr countsWS, const double median);
int doDetectorTests(const API::MatrixWorkspace_sptr countsWS, const double median, API::MatrixWorkspace_sptr maskWS);

/// Input workspace
API::MatrixWorkspace_sptr m_inputWS;
Expand Down
31 changes: 8 additions & 23 deletions Code/Mantid/Framework/Algorithms/src/MedianDetectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ namespace Mantid
MatrixWorkspace_sptr countsWS = integrateSpectra(m_inputWS, m_minSpec, m_maxSpec,
m_rangeLower, m_rangeUpper, true);

// Make sure the output is simple
countsWS->setYUnit("");
countsWS->instrumentParameters();
MatrixWorkspace_sptr maskWS = this->generateEmptyMask(countsWS);

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

numFailed += doDetectorTests(countsWS, median);
numFailed += doDetectorTests(countsWS, median, maskWS);
g_log.information() << "Median test results:\n"
<< "\tNumber of failures - " << numFailed << "\n";

setProperty("NumberOfFailures", numFailed);

// extract and set the mask result
IAlgorithm_sptr childAlg = createSubAlgorithm("ExtractMask");
childAlg->setProperty( "InputWorkspace", countsWS );
childAlg->executeAsSubAlg();
MatrixWorkspace_sptr maskWS = childAlg->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", maskWS);
}

Expand Down Expand Up @@ -247,7 +239,7 @@ namespace Mantid
* @return The number of detectors that failed the tests, not including those skipped
*/
int MedianDetectorTest::doDetectorTests(const API::MatrixWorkspace_sptr countsWS,
const double median)
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,
Expand All @@ -258,7 +250,7 @@ namespace Mantid
const int numSpec(m_maxSpec - m_minSpec);
const int progStep = static_cast<int>(ceil(numSpec/30.0));

const double live_value(1.0);
const double deadValue(1.0);
int numFailed(0);

bool checkForMask = false;
Expand All @@ -268,7 +260,7 @@ namespace Mantid
checkForMask = ((instrument->getSource() != NULL) && (instrument->getSample() != NULL));
}

PARALLEL_FOR1(countsWS)
PARALLEL_FOR2(countsWS, maskWS)
for (int i = 0; i <= numSpec; ++i)
{
PARALLEL_START_INTERUPT_REGION
Expand All @@ -284,21 +276,20 @@ namespace Mantid
const std::set<detid_t>& detids = countsWS->getSpectrum(i)->getDetectorIDs();
if (instrument->isDetectorMasked(detids))
{
countsWS->dataY(i)[0] = 0.0;
maskWS->dataY(i)[0] = deadValue;
continue;
}
if (instrument->isMonitor(detids))
{
// Don't include in calculation but don't mask it
countsWS->dataY(i)[0] = live_value;
}
}

const double signal = countsWS->dataY(i)[0];
// Mask out NaN and infinite
if( boost::math::isinf(signal) || boost::math::isnan(signal) )
{
countsWS->maskWorkspaceIndex(i);
maskWS->dataY(i)[0] = deadValue;
PARALLEL_ATOMIC
++numFailed;
continue;
Expand All @@ -309,16 +300,10 @@ namespace Mantid
if( (signal < median*m_loFrac && (signal-median < -error)) ||
(signal > median*m_hiFrac && (signal-median > error)) )
{
countsWS->maskWorkspaceIndex(i);
maskWS->dataY(i)[0] = deadValue;
PARALLEL_ATOMIC
++numFailed;
}
else
{
// Reaching here passes the tests
countsWS->dataY(i)[0] = live_value;
}


PARALLEL_END_INTERUPT_REGION
}
Expand Down

0 comments on commit 5089062

Please sign in to comment.