Skip to content

Commit

Permalink
Refs #4814. Now runs all four dynamic detector tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Feb 24, 2012
1 parent f691dda commit 128dfd8
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace Mantid
// Overridden Algorithm methods
virtual void init();
virtual void exec();
void applyMask(API::MatrixWorkspace_sptr inputWS, API::MatrixWorkspace_sptr maskWS);

protected:
/// Get the total counts for each spectra
Expand Down
140 changes: 135 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/DetectorDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ namespace Mantid
declareProperty("LowThreshold", 0.0,
"Spectra whose total number of counts are equal to or below this value\n"
"will be marked bad (default 0)" );
this->setPropertyGroup("LowThreshold", findDetOutLimGrp); declareProperty("HighThreshold", EMPTY_DBL(),
this->setPropertyGroup("LowThreshold", findDetOutLimGrp);
declareProperty("HighThreshold", EMPTY_DBL(),
"Spectra whose total number of counts are equal to or above this value\n"
"will be marked bad (default off)" );
this->setPropertyGroup("HighThreshold", findDetOutLimGrp);
Expand Down Expand Up @@ -134,14 +135,142 @@ namespace Mantid
this->setPropertyGroup("NIgnoredCentralPixels", psdBleedMaskGrp);
setPropertySettings("NIgnoredCentralPixels", new EnabledWhenProperty(this, "MaxTubeFramerate", IS_NOT_DEFAULT));

declareProperty("NumberOfFailures", 0, Direction::Output);
}

void DetectorDiagnostic::exec()
{
// FindDetectorsOutsideLimits (always)
// MedianDetectorTest (if selected)
// DetectorEfficiencyVariation (only if two workspaces are specified)
// CreatePSDBleedMask (if selected)
// get the generic information that everybody uses
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
int minIndex = getProperty("StartWorkspaceIndex");
int maxIndex = getProperty("EndWorkspaceIndex");
const double rangeLower = getProperty("RangeLower");
const double rangeUpper = getProperty("RangeUpper");

// integrate the data once to pass to subalgorithms
m_fracDone = 0.;
MatrixWorkspace_sptr countsWS = integrateSpectra(inputWS, minIndex, maxIndex,
rangeLower, rangeUpper, true);

int numFailed(0);
MatrixWorkspace_sptr maskWS;

// FindDetectorsOutsideLimits (always)
{
// get the relavant inputs
double lowThreshold = getProperty("LowThreshold");
double highThreshold = getProperty("HighThreshold");

// run the subalgorithm
IAlgorithm_sptr alg = createSubAlgorithm("FindDetectorsOutsideLimits"); // should set progress bar
alg->setProperty("InputWorkspace", countsWS);
alg->setProperty("StartWorkspaceIndex", minIndex);
alg->setProperty("EndWorkspaceIndex", maxIndex);
alg->setProperty("RangeLower", rangeLower);
alg->setProperty("RangeUpper", rangeUpper);
alg->setProperty("LowThreshold", lowThreshold);
alg->setProperty("HighThreshold", highThreshold);
alg->executeAsSubAlg();
maskWS = alg->getProperty("OutputWorkspace");
int localFails = alg->getProperty("NumberOfFailures");
numFailed += localFails;
}

// MedianDetectorTest (if selected)
if (getProperty("RunMedianDetectorTest"))
{
// apply mask to what we are going to input
applyMask(countsWS, maskWS);

// get the relavant inputs
double significanceTest = getProperty("SignificanceTest");
double lowThreshold = getProperty("LowThresholdFraction");
double highThreshold = getProperty("HighThresholdFraction");
double lowOutlier = getProperty("LowOutlier");
double highOutlier = getProperty("HighOutlier");
bool excludeZeroes = getProperty("ExcludeZeroesFromMedian");

// run the subalgorithm
IAlgorithm_sptr alg = createSubAlgorithm("MedianDetectorTest"); // should set progress bar
alg->setProperty("InputWorkspace", countsWS);
alg->setProperty("StartWorkspaceIndex", minIndex);
alg->setProperty("EndWorkspaceIndex", maxIndex);
alg->setProperty("RangeLower", rangeLower);
alg->setProperty("RangeUpper", rangeUpper);
alg->setProperty("SignificanceTest", significanceTest);
alg->setProperty("LowThreshold", lowThreshold);
alg->setProperty("HighThreshold", highThreshold);
alg->setProperty("LowOutlier", lowOutlier);
alg->setProperty("HighOutlier", highOutlier);
alg->setProperty("ExcludeZeroesFromMedian", excludeZeroes);
alg->executeAsSubAlg();
MatrixWorkspace_sptr localMaskWS = alg->getProperty("OutputWorkspace");
maskWS += localMaskWS;
int localFails = alg->getProperty("NumberOfFailures");
numFailed += localFails;
}

// DetectorEfficiencyVariation (only if two workspaces are specified)
if (!getPropertyValue("WhiteBeamCompare").empty())
{
// apply mask to what we are going to input
applyMask(countsWS, maskWS);

// get the relavant inputs
MatrixWorkspace_sptr compareWS = getProperty("WhiteBeamCompare");
double variation = getProperty("WhiteBeamVariation");

// run the subalgorithm
IAlgorithm_sptr alg = createSubAlgorithm("DetectorEfficiencyVariation"); // should set progress bar
alg->setProperty("WhiteBeamBase", countsWS);
alg->setProperty("WhiteBeamCompare", compareWS);
alg->setProperty("StartWorkspaceIndex", minIndex);
alg->setProperty("EndWorkspaceIndex", maxIndex);
alg->setProperty("RangeLower", rangeLower);
alg->setProperty("RangeUpper", rangeUpper);
alg->setProperty("Variation", variation);
alg->executeAsSubAlg();
MatrixWorkspace_sptr localMaskWS = alg->getProperty("OutputWorkspace");
maskWS += localMaskWS;
int localFails = alg->getProperty("NumberOfFailures");
numFailed += localFails;
}

// CreatePSDBleedMask (if selected)
double maxTubeFrameRate = getProperty("MaxTubeFramerate");
g_log.notice() << "MaxTubeFramerate \"" << maxTubeFrameRate << "\"\n";
if (maxTubeFrameRate > 0.)
{
// apply mask to what we are going to input
applyMask(countsWS, maskWS);

// get the relavant inputs
int numIgnore = getProperty("NIgnoredCentralPixels");

// run the subalgorithm
IAlgorithm_sptr alg = createSubAlgorithm("CreatePSDBleedMask"); // should set progress bar
alg->setProperty("InputWorkspace", inputWS);
alg->setProperty("MaxTubeFramerate", maxTubeFrameRate);
alg->setProperty("NIgnoredCentralPixels", numIgnore);
alg->executeAsSubAlg();
MatrixWorkspace_sptr localMaskWS = alg->getProperty("OutputWorkspace");
maskWS += localMaskWS;
int localFails = alg->getProperty("NumberOfFailures");
numFailed += localFails;
}

g_log.information() << numFailed << " spectra are being masked\n";
setProperty("NumberOfFailures", numFailed);
setProperty("OutputWorkspace", maskWS);
}

void DetectorDiagnostic::applyMask(API::MatrixWorkspace_sptr inputWS,
API::MatrixWorkspace_sptr maskWS)
{
IAlgorithm_sptr maskAlg = createSubAlgorithm("MaskDetectors"); // should set progress bar
maskAlg->setProperty("Workspace", inputWS);
maskAlg->setProperty("MaskedWorkspace", maskWS);
maskAlg->executeAsSubAlg();
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -216,6 +345,7 @@ namespace Mantid
MatrixWorkspace_sptr outputWS(maskWS);
WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
outputWS->setTitle(inputWS->getTitle());
outputWS->getInstrument()->getParameterMap()->clearParametersByName("masked"); // turn off the mask bit

if (initialize) // initialize the mask as keep everything
{
Expand Down

0 comments on commit 128dfd8

Please sign in to comment.