Skip to content

Commit

Permalink
refs #8589. Use rather than make transmission workspaces.
Browse files Browse the repository at this point in the history
Use rather than make a transmission workspace if the units are in wavelength.
  • Loading branch information
OwenArnold committed Dec 13, 2013
1 parent e63d50f commit 772363c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
Expand Up @@ -87,7 +87,10 @@ namespace Mantid
private:

/// Validate the transmission correction property inputs
void validateTransmissionInputs() const;
void validateSecondTransmissionInputs(const bool firstTransmissionInWavelength) const;

/// Validate the the first transmission workspace.
bool validateFirstTransmissionInputs() const;

/// Convert the monitor parts of the input workspace to wavelength
API::MatrixWorkspace_sptr toLamMonitor(const API::MatrixWorkspace_sptr& toConvert,
Expand Down
56 changes: 34 additions & 22 deletions Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOne.cpp
Expand Up @@ -98,6 +98,8 @@ namespace Mantid

const std::string multiDetectorAnalysis = "MultiDetectorAnalysis";
const std::string pointDetectorAnalysis = "PointDetectorAnalysis";
const std::string tofUnitId = "TOF";
const std::string wavelengthUnitId = "Wavelength";
}
/* End of ananomous namespace */

Expand Down Expand Up @@ -196,7 +198,7 @@ namespace Mantid

declareProperty(
new WorkspaceProperty<MatrixWorkspace>("FirstTransmissionRun", "", Direction::Input,
PropertyMode::Optional, inputValidator->clone()),
PropertyMode::Optional),
"First transmission run, or the low wavelength transmision run if SecondTransmissionRun is also provided.");
declareProperty(
new WorkspaceProperty<MatrixWorkspace>("SecondTransmissionRun", "", Direction::Input,
Expand Down Expand Up @@ -520,29 +522,39 @@ namespace Mantid
const WorkspaceIndexList detectorIndexes = createWorkspaceIndexListFromDetectorWorkspace(IvsLam,
firstTransmissionRun);

// Make the transmission run.
auto alg = this->createChildAlgorithm("CreateTransmissionWorkspace");
alg->initialize();
alg->setProperty("FirstTransmissionRun", firstTransmissionRun);
if(secondTransmissionRun.is_initialized())
// TODO if firstInputWorkspace is in wavelength, do not create the transmission workspace, just do the division.

MatrixWorkspace_sptr denominator = firstTransmissionRun;
Unit_const_sptr xUnit = firstTransmissionRun->getAxis(0)->unit();
if (xUnit->unitID() == tofUnitId)
{
alg->setProperty("SecondTransmissionRun", secondTransmissionRun.get());
const std::vector<double> params = boost::assign::list_of(stitchingStartQ.get())(stitchingDeltaQ.get())(stitchingEndQ.get()).convert_to_container<std::vector<double> >();
alg->setProperty("Params", params);
alg->setProperty("StartOverlapQ", stitchingStartOverlapQ.get());
alg->setProperty("EndOverlapQ", stitchingEndOverlapQ.get());
// Make the transmission run.
auto alg = this->createChildAlgorithm("CreateTransmissionWorkspace");
alg->initialize();
alg->setProperty("FirstTransmissionRun", firstTransmissionRun);
if (secondTransmissionRun.is_initialized())
{
alg->setProperty("SecondTransmissionRun", secondTransmissionRun.get());
const std::vector<double> params = boost::assign::list_of(stitchingStartQ.get())(
stitchingDeltaQ.get())(stitchingEndQ.get()).convert_to_container<std::vector<double> >();
alg->setProperty("Params", params);
alg->setProperty("StartOverlapQ", stitchingStartOverlapQ.get());
alg->setProperty("EndOverlapQ", stitchingEndOverlapQ.get());
}
alg->setProperty("WorkspaceIndexList", detectorIndexes);
alg->setProperty("I0MonitorIndex", i0MonitorIndex);
alg->setProperty("WavelengthMin", wavelengthInterval.get<0>());
alg->setProperty("WavelengthMax", wavelengthInterval.get<1>());
alg->setProperty("WavelengthStep", wavelengthStep);
alg->setProperty("MonitorBackgroundWavelengthMin", wavelengthMonitorBackgroundInterval.get<0>());
alg->setProperty("MonitorBackgroundWavelengthMax", wavelengthMonitorBackgroundInterval.get<1>());
alg->setProperty("MonitorIntegrationWavelengthMin",
wavelengthMonitorIntegrationInterval.get<0>());
alg->setProperty("MonitorIntegrationWavelengthMax",
wavelengthMonitorIntegrationInterval.get<1>());
alg->execute();
denominator = alg->getProperty("OutputWorkspace");
}
alg->setProperty("WorkspaceIndexList", detectorIndexes);
alg->setProperty("I0MonitorIndex", i0MonitorIndex);
alg->setProperty("WavelengthMin", wavelengthInterval.get<0>());
alg->setProperty("WavelengthMax", wavelengthInterval.get<1>());
alg->setProperty("WavelengthStep", wavelengthStep);
alg->setProperty("MonitorBackgroundWavelengthMin", wavelengthMonitorBackgroundInterval.get<0>());
alg->setProperty("MonitorBackgroundWavelengthMax", wavelengthMonitorBackgroundInterval.get<1>());
alg->setProperty("MonitorIntegrationWavelengthMin", wavelengthMonitorIntegrationInterval.get<0>());
alg->setProperty("MonitorIntegrationWavelengthMax", wavelengthMonitorIntegrationInterval.get<1>());
alg->execute();
MatrixWorkspace_sptr denominator = alg->getProperty("OutputWorkspace");

// Rebin the transmission run to be the same as the input.
auto rebinToWorkspaceAlg = this->createChildAlgorithm("RebinToWorkspace");
Expand Down
37 changes: 35 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
Expand Up @@ -216,17 +216,47 @@ namespace Mantid
return MinMax(min, max);
}

/**
* Check the first transmission run units.
*
* @return True only if the units of the first transmission run are in wavelength.
*
*/
bool ReflectometryWorkflowBase::validateFirstTransmissionInputs() const
{
WorkspaceUnitValidator tofValidator("TOF");
WorkspaceUnitValidator wavelengthValidator("Wavelength");
MatrixWorkspace_sptr firstTransmissionRun = this->getProperty("FirstTransmissionRun");
if (!tofValidator.isValid(firstTransmissionRun).empty()
&& !wavelengthValidator.isValid(firstTransmissionRun).empty())
{
throw std::invalid_argument("FirstTransmissionRun must be either in TOF or Wavelength");
}

const bool bInWavelength = (!wavelengthValidator.isValid(firstTransmissionRun).empty());
return bInWavelength;
}

/**
* Validate the transmission workspace inputs when a second transmission run is provided.
* Throws if any of the property values do not make sense.
* @param firstTransmissionInWavelength: Indicates that the first transmission run is in units of wavlength.
*/
void ReflectometryWorkflowBase::validateTransmissionInputs() const
void ReflectometryWorkflowBase::validateSecondTransmissionInputs(const bool firstTransmissionInWavelength) const
{
// Verify that all the required inputs for the second transmission run are now given.
if (isPropertyDefault("FirstTransmissionRun"))
{
throw std::invalid_argument(
"A SecondTransmissionRun is only valid if a FirstTransmissionRun is provided.");
if (firstTransmissionInWavelength)
{
this->g_log.warning(
"The first transmission run is in wavelength so is assumed to be correctly stitched in wavelength. "
"The second transmission run and associated inputs will be ignored."
"Run CreateTransmissionWorkspace to create a transmission workspace from TOF runs.");
return;
}
}
if (isPropertyDefault("Params"))
{
Expand Down Expand Up @@ -283,16 +313,19 @@ namespace Mantid
OptionalDouble& stitchingDeltaQ, OptionalDouble& stitchingEndQ,
OptionalDouble& stitchingStartOverlapQ, OptionalDouble& stitchingEndOverlapQ) const
{
bool bFirstTransInWavelength = false;
if (!isPropertyDefault("FirstTransmissionRun"))
{
bFirstTransInWavelength = validateFirstTransmissionInputs();

MatrixWorkspace_sptr temp = this->getProperty("FirstTransmissionRun");
firstTransmissionRun = temp;
}

if (!isPropertyDefault("SecondTransmissionRun"))
{
// Check that the property values provided make sense together.
validateTransmissionInputs();
validateSecondTransmissionInputs(bFirstTransInWavelength);

// Set the values.
{
Expand Down
Expand Up @@ -36,7 +36,7 @@ def test_check_input_workpace_not_tof_throws(self):
alg.set_InputWorkspace(self.__not_tof)
self.assertRaises(ValueError, alg.execute)

def test_check_first_transmission_workspace_not_tof_throws(self):
def test_check_first_transmission_workspace_not_tof_or_wavelength_throws(self):
alg = self.construct_standard_algorithm()
alg.set_FirstTransmissionRun(self.__not_tof)
self.assertRaises(ValueError, alg.execute)
Expand Down

0 comments on commit 772363c

Please sign in to comment.