Skip to content

Commit

Permalink
Refs #11534 Initial checks for Qresolution
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Jul 28, 2015
1 parent 69189bd commit b1f26b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class Qhelper {
public:
void examineInput(API::MatrixWorkspace_const_sptr dataWS,
API::MatrixWorkspace_const_sptr binAdj,
API::MatrixWorkspace_const_sptr detectAdj);
API::MatrixWorkspace_const_sptr detectAdj,
API::MatrixWorkspace_const_sptr qResolution);

size_t waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS,
const double RCut, const double WCut,
Expand Down
9 changes: 8 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/Q1D2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ void Q1D2::init() {
declareProperty(
"ExtraLength", 0.0, mustBePositive,
"Additional length for gravity correction.");

declareProperty(
new WorkspaceProperty<>("QResolution", "", Direction::Input,
PropertyMode::Optional, dataVal),
"Workspace to calculate the Q resolution.\n");
}
/**
@ throw invalid_argument if the workspaces are not mututially compatible
Expand All @@ -95,12 +100,14 @@ void Q1D2::exec() {
MatrixWorkspace_const_sptr waveAdj = getProperty("WavelengthAdj");
MatrixWorkspace_const_sptr pixelAdj = getProperty("PixelAdj");
MatrixWorkspace_const_sptr wavePixelAdj = getProperty("WavePixelAdj");
MatrixWorkspace_const_sptr qResolution = getProperty("QResolution");

const bool doGravity = getProperty("AccountForGravity");
m_doSolidAngle = getProperty("SolidAngleWeighting");

// throws if we don't have common binning or another incompatibility
Qhelper helper;
helper.examineInput(m_dataWS, waveAdj, pixelAdj);
helper.examineInput(m_dataWS, waveAdj, pixelAdj, qResolution);
// FIXME: how to examine the wavePixelAdj?
g_log.debug() << "All input workspaces were found to be valid\n";
// normalization as a function of wavelength (i.e. centers of x-value bins)
Expand Down
24 changes: 23 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/Qhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ using namespace Geometry;
@param detectAdj (PixelAdj) passing NULL for this wont raise an error, if set
it will be checked this workspace has as many histograms as dataWS each with
one bin
@param qResolution: the QResolution workspace
@throw invalid_argument if the workspaces are not mututially compatible
*/
void Qhelper::examineInput(API::MatrixWorkspace_const_sptr dataWS,
API::MatrixWorkspace_const_sptr binAdj,
API::MatrixWorkspace_const_sptr detectAdj) {
API::MatrixWorkspace_const_sptr detectAdj,
API::MatrixWorkspace_const_sptr qResolution) {
if (dataWS->getNumberHistograms() < 1) {
throw std::invalid_argument(
"Empty data workspace passed, can not continue");
Expand Down Expand Up @@ -101,6 +103,26 @@ void Qhelper::examineInput(API::MatrixWorkspace_const_sptr dataWS,
}
}
}

// Check the compatibility of the QResolution workspace
if (qResolution) {
// We require the same number of histograms
if (detectAdj->getNumberHistograms() != dataWS->getNumberHistograms()) {
throw std::invalid_argument("The QResolution should have one spectrum"
"per spectrum of the input workspace");
}

// We require the same binning for the input workspace and the q resolution
// workspace
MantidVec::const_iterator reqX = dataWS->readX(0).begin();
MantidVec::const_iterator qResX = qResolution->readX(0).begin();
for (; reqX != dataWS->readX(0).end(); ++reqX, ++qResX) {
if (*reqX != *qResX) {
throw std::invalid_argument("The QResolution needs to have the same binning as"
"as the input workspace.");
}
}
}
}

/** Finds the first index number of the first wavelength bin that should
Expand Down

0 comments on commit b1f26b4

Please sign in to comment.