diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Qhelper.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Qhelper.h index 4413a497cf3253aaeb10c6cab7570af8b60d0f9a..2055094cfabc498f8a6799b3190ffb1428c79b83 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Qhelper.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Qhelper.h @@ -44,6 +44,9 @@ public: size_t waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS, const double RCut, const double WCut, const size_t specInd) const; + + void outputParts(API::Algorithm* alg, API::MatrixWorkspace_sptr sumOfCounts, + API::MatrixWorkspace_sptr sumOfNormFactors); private: /// the experimental workspace with counts across the detector /* API::MatrixWorkspace_const_sptr m_dataWS; diff --git a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp index 6cdc058cd7317ca69a8be96f427b325c3136b64e..1dc7ab867afa9d0d1f774964dcf81f2e321eae51 100644 --- a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp @@ -69,6 +69,11 @@ void Q1D2::init() declareProperty("WaveCut", 0.0, mustBePositive, "To increase resolution by starting to remove some wavelengths below this" "freshold (angstrom)"); + declareProperty("OutputParts", false, + "Set to true to output two additional workspaces which will have the names OutputWorkspace_sumOfCounts " + "OutputWorkspace_sumOfNormFactors. The division of _sumOfCounts and _sumOfNormFactors equals the workspace" + " returned by the property OutputWorkspace " + "(default is false)." ); } /** @ throw invalid_argument if the workspaces are not mututially compatible @@ -194,6 +199,27 @@ void Q1D2::exec() } PARALLEL_CHECK_INTERUPT_REGION + bool doOutputParts = getProperty("OutputParts"); + if (doOutputParts) + { + MatrixWorkspace_sptr ws_sumOfCounts = WorkspaceFactory::Instance().create(outputWS); + for (size_t i = 0; i < ws_sumOfCounts->dataY(0).size(); i++) + { + ws_sumOfCounts->dataY(0)[i] = outputWS->dataY(0)[i]; + ws_sumOfCounts->dataE(0)[i] = sqrt(outputWS->dataE(0)[i]); + } + + MatrixWorkspace_sptr ws_sumOfNormFactors = WorkspaceFactory::Instance().create(outputWS); + for (size_t i = 0; i < ws_sumOfNormFactors->dataY(0).size(); i++) + { + ws_sumOfNormFactors->dataY(0)[i] = normSum[i]; + ws_sumOfNormFactors->dataE(0)[i] = sqrt(normError2[i]); + } + + helper.outputParts(this, ws_sumOfCounts, ws_sumOfNormFactors); + } + + progress.report("Normalizing I(Q)"); //finally divide the number of counts in each output Q bin by its weighting normalize(normSum, normError2, YOut, EOutTo2); diff --git a/Code/Mantid/Framework/Algorithms/src/Qhelper.cpp b/Code/Mantid/Framework/Algorithms/src/Qhelper.cpp index 0035ecfb80f02d87b147efa9b42b480bf4a269f4..6a147e8d46945b031dfc325a1c94e0c67bde4177 100644 --- a/Code/Mantid/Framework/Algorithms/src/Qhelper.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Qhelper.cpp @@ -132,6 +132,28 @@ size_t Qhelper::waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS, const d return std::lower_bound(Xs.begin(), Xs.end(), WMin) - Xs.begin(); } + +void Qhelper::outputParts(API::Algorithm* alg, API::MatrixWorkspace_sptr sumOfCounts, + API::MatrixWorkspace_sptr sumOfNormFactors) +{ + std::string baseName = alg->getPropertyValue("OutputWorkspace"); + + alg->declareProperty( + new API::WorkspaceProperty<API::MatrixWorkspace>("SumOfCounts","",Kernel::Direction::Output), + "The name of the MatrixWorkspace to store sum of counts" ); + alg->setPropertyValue("SumOfCounts",baseName+"_sumOfCounts"); + + alg->setProperty("SumOfCounts", sumOfCounts); + + + alg->declareProperty( + new API::WorkspaceProperty<API::MatrixWorkspace>("sumOfNormFactors","",Kernel::Direction::Output), + "The name of the MatrixWorkspace to store sum of normalising factors" ); + alg->setPropertyValue("sumOfNormFactors",baseName+"_sumOfNormFactors"); + + alg->setProperty("sumOfNormFactors", sumOfNormFactors); +} + } // namespace Algorithms } // namespace Mantid diff --git a/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h b/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h index f1ffa844c05c36538cc86d704c889a07bab78dcc..c4f0279a5f125223cf9b4c88a378106477e6dca8 100644 --- a/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h +++ b/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h @@ -80,6 +80,60 @@ public: Mantid::API::AnalysisDataService::Instance().remove(outputWS); } + void testOutputParts() + { + Mantid::Algorithms::Q1D2 Q1D2; + Q1D2.initialize(); + + const std::string outputWS("Q1D2Test_OutputParts"); + TS_ASSERT_THROWS_NOTHING( + Q1D2.setProperty("DetBankWorkspace", m_inputWS); + Q1D2.setProperty("WavelengthAdj", m_wavNorm); + Q1D2.setPropertyValue("OutputWorkspace",outputWS); + Q1D2.setPropertyValue("OutputBinning","0,0.02,0.5"); + Q1D2.setProperty("OutputParts", true); + + // The property PixelAdj is undefined but that shouldn't cause this to throw + Q1D2.execute() + ) + + TS_ASSERT( Q1D2.isExecuted() ) + + Mantid::API::MatrixWorkspace_sptr result; + TS_ASSERT_THROWS_NOTHING( result = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> + (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)) ) + + Mantid::API::MatrixWorkspace_sptr sumOfCounts; + TS_ASSERT_THROWS_NOTHING( sumOfCounts = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> + (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS+"_sumOfCounts")) ) + + Mantid::API::MatrixWorkspace_sptr sumOfNormFactors; + TS_ASSERT_THROWS_NOTHING( sumOfNormFactors = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> + (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS+"_sumOfNormFactors")) ) + + + TS_ASSERT_DELTA( result->readY(0)[1], 1131778.3299, 0.01 ) + TS_ASSERT_DELTA( sumOfCounts->readY(0)[1], 1016.8990, 0.01 ) + TS_ASSERT_DELTA( sumOfNormFactors->readY(0)[1], 0.00089849, 0.01 ) + + TS_ASSERT_DELTA( result->readE(0)[1], 57964.04, 0.01 ) + TS_ASSERT_DELTA( sumOfCounts->readE(0)[1], 31.888, 0.01 ) + TS_ASSERT_DELTA( sumOfNormFactors->readE(0)[1], 3.6381851288154988e-005, 0.01 ) + + TS_ASSERT_EQUALS( result->getNumberHistograms(), 1 ) + TS_ASSERT_EQUALS( sumOfCounts->getNumberHistograms(), 1 ) + TS_ASSERT_EQUALS( sumOfNormFactors->getNumberHistograms(), 1 ) + + TS_ASSERT_EQUALS( result->dataY(0).size(), 25 ) + TS_ASSERT_EQUALS( sumOfCounts->dataY(0).size(), 25 ) + //TS_ASSERT_EQUALS( sumOfNormFactors->getNumberHistograms(), 1 ) + + + Mantid::API::AnalysisDataService::Instance().remove(outputWS); + Mantid::API::AnalysisDataService::Instance().remove(outputWS+"_sumOfCounts"); + Mantid::API::AnalysisDataService::Instance().remove(outputWS+"_sumOfNormFactors"); + } + void testPixelAdj() { Mantid::Algorithms::Q1D2 Q1D;