From db8034aebdfa856d9f45faa4343f3efb4a35d007 Mon Sep 17 00:00:00 2001 From: Peter Peterson <petersonpf@ornl.gov> Date: Fri, 13 Apr 2012 14:15:57 -0400 Subject: [PATCH] Refs #5099. Added ability to set uncertainties to sqrt. --- .../Algorithms/src/SetUncertaintiesToZero.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Code/Mantid/Framework/Algorithms/src/SetUncertaintiesToZero.cpp b/Code/Mantid/Framework/Algorithms/src/SetUncertaintiesToZero.cpp index b6da4ca10d4..c9cc5e2d265 100644 --- a/Code/Mantid/Framework/Algorithms/src/SetUncertaintiesToZero.cpp +++ b/Code/Mantid/Framework/Algorithms/src/SetUncertaintiesToZero.cpp @@ -6,6 +6,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAlgorithms/SetUncertaintiesToZero.h" +#include "MantidKernel/ListValidator.h" #include <vector> namespace Mantid @@ -43,17 +44,26 @@ const std::string SetUncertaintiesToZero::name() const int SetUncertaintiesToZero::version() const { return (1);} +const std::string ZERO("zero"); +const std::string SQRT("sqrt"); + void SetUncertaintiesToZero::init() { declareProperty(new WorkspaceProperty<API::MatrixWorkspace>("InputWorkspace","", Direction::Input)); declareProperty(new WorkspaceProperty<API::MatrixWorkspace>("OutputWorkspace","", Direction::Output)); + std::vector<std::string> errorTypes; + errorTypes.push_back(ZERO); + errorTypes.push_back(SQRT); + declareProperty("SetError", ZERO, boost::make_shared<StringListValidator>(errorTypes), "How to reset the uncertainties"); } void SetUncertaintiesToZero::exec() { MatrixWorkspace_const_sptr inputWorkspace = getProperty("InputWorkspace"); + std::string errorType = getProperty("SetError"); + bool zeroError = (errorType.compare(ZERO) == 0); // Create the output workspace. This will copy many aspects from the input one. MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create(inputWorkspace); @@ -71,6 +81,17 @@ void SetUncertaintiesToZero::exec() outputWorkspace->dataY(i) = inputWorkspace->readY(i); outputWorkspace->dataE(i) = std::vector<double>(inputWorkspace->readE(i).size(), 0.); + if (!zeroError) + { + MantidVec& Y = outputWorkspace->dataY(i); + MantidVec& E = outputWorkspace->dataE(i); + std::size_t numE = E.size(); + for (std::size_t j = 0; j < numE; j++) + { + E[j] = sqrt(Y[j]); + } + } + prog.report(); PARALLEL_END_INTERUPT_REGION -- GitLab