26using namespace Kernel;
33const std::string ZERO(
"zero");
34const std::string
SQRT(
"sqrt");
35const std::string ONE_IF_ZERO(
"oneIfZero");
36const std::string SQRT_OR_ONE(
"sqrtOrOne");
37const std::string CUSTOM(
"custom");
40 explicit SetError(
const double setTo,
const double ifEqualTo,
const double tolerance)
43 double operator()(
const double error) {
45 if (deviation < tolerance && deviation >= 0) {
58 explicit SqrtError(
const double constant) :
zeroSqrtValue(constant) {}
60 double operator()(
const double intensity) {
61 const double localIntensity =
fabs(intensity);
63 return sqrt(localIntensity);
80 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
81 auto mustBePositiveInt = std::make_shared<BoundedValidator<int>>();
82 mustBePositive->setLower(0);
83 mustBePositiveInt->setLower(0);
86 std::vector<std::string> errorTypes = {ZERO, SQRT, SQRT_OR_ONE, ONE_IF_ZERO, CUSTOM};
87 declareProperty(
"SetError", ZERO, std::make_shared<StringListValidator>(errorTypes),
88 "How to reset the uncertainties");
89 declareProperty(
"SetErrorTo", 1.000, mustBePositive,
"The error value to set when using custom mode");
93 "Which error values in the input workspace should be "
94 "replaced when using custom mode");
98 "How many decimal places of ``IfEqualTo`` are taken into "
99 "account for matching when using custom mode");
105 auto inputEventWorkspace = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(inputWorkspace);
108 bool zeroError = (errorType == ZERO);
109 bool takeSqrt = ((errorType == SQRT) || (errorType == SQRT_OR_ONE));
110 bool resetOne = ((errorType == ONE_IF_ZERO) || (errorType == SQRT_OR_ONE));
111 bool customError = (errorType == CUSTOM);
116 double tolerance = resetOne ? 1E-10 : std::pow(10.0, -1. * precision);
121 const int64_t numHists =
static_cast<int64_t
>(inputWorkspace->getNumberHistograms());
122 if (inputEventWorkspace) {
123 if (inputWorkspace == outputWorkspace && errorType == SQRT &&
131 for (int64_t i = 0; i < numHists; ++i) {
134 outputWorkspace->setSharedX(i, inputWorkspace->sharedX(i));
135 outputWorkspace->setSharedY(i, inputWorkspace->sharedY(i));
136 outputWorkspace->setSharedE(i, inputWorkspace->sharedE(i));
140 }
else if (inputWorkspace != outputWorkspace) {
141 outputWorkspace = inputWorkspace->clone();
144 const auto &spectrumInfo = inputWorkspace->spectrumInfo();
145 Progress prog(
this, 0.0, 1.0, numHists);
147 for (int64_t i = 0; i < numHists; ++i) {
150 if (errorType == ONE_IF_ZERO || customError) {
152 outputWorkspace->mutableE(i) = 0.0;
155 if ((!zeroError) && (!(spectrumInfo.hasDetectors(i) && spectrumInfo.isMasked(i)))) {
156 auto &E = outputWorkspace->mutableE(i);
158 const auto &
Y = outputWorkspace->y(i);
159 std::transform(
Y.begin(),
Y.end(), E.begin(), SqrtError(resetOne ? 1. : 0.));
#define DECLARE_ALGORITHM(classname)
const int64_t TOLERANCE(1000000)
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Execution code.
int version() const override
Algorithm's version.
const std::string name() const override
Algorithm's name.
void init() override
Initialisation code.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
@ Input
An input workspace.
@ Output
An output workspace.