From 772363c95337f00ef53729b5d829d304b4f445d0 Mon Sep 17 00:00:00 2001 From: Owen Arnold Date: Fri, 13 Dec 2013 09:35:31 +0000 Subject: [PATCH] refs #8589. Use rather than make transmission workspaces. Use rather than make a transmission workspace if the units are in wavelength. --- .../ReflectometryWorkflowBase.h | 5 +- .../src/ReflectometryReductionOne.cpp | 56 +++++++++++-------- .../src/ReflectometryWorkflowBase.cpp | 37 +++++++++++- .../ReflectometryReductionOneTest.py | 2 +- 4 files changed, 74 insertions(+), 26 deletions(-) diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ReflectometryWorkflowBase.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ReflectometryWorkflowBase.h index 6b0e685f0ddc..ca6e49198da5 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ReflectometryWorkflowBase.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ReflectometryWorkflowBase.h @@ -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, diff --git a/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOne.cpp b/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOne.cpp index 06847c2de3f8..d3fd6bc6b641 100644 --- a/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOne.cpp +++ b/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOne.cpp @@ -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 */ @@ -196,7 +198,7 @@ namespace Mantid declareProperty( new WorkspaceProperty("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("SecondTransmissionRun", "", Direction::Input, @@ -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 params = boost::assign::list_of(stitchingStartQ.get())(stitchingDeltaQ.get())(stitchingEndQ.get()).convert_to_container >(); - 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 params = boost::assign::list_of(stitchingStartQ.get())( + stitchingDeltaQ.get())(stitchingEndQ.get()).convert_to_container >(); + 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"); diff --git a/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp b/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp index be9f0895a3b3..572767cb77b6 100644 --- a/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp +++ b/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp @@ -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")) { @@ -283,8 +313,11 @@ 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; } @@ -292,7 +325,7 @@ namespace Mantid if (!isPropertyDefault("SecondTransmissionRun")) { // Check that the property values provided make sense together. - validateTransmissionInputs(); + validateSecondTransmissionInputs(bFirstTransInWavelength); // Set the values. { diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/ReflectometryReductionOneTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/ReflectometryReductionOneTest.py index 7c52ef825e47..150cab2109a2 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/ReflectometryReductionOneTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/ReflectometryReductionOneTest.py @@ -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)