12#include "MantidHistogramData/HistogramIterator.h"
29mu::Parser makeParser(
double &y,
double &e,
double &x,
double &dx,
double &s,
const std::string &criterion) {
31 muParser.DefineVar(
"y", &y);
32 muParser.DefineVar(
"e", &e);
33 muParser.DefineVar(
"x", &x);
34 muParser.DefineVar(
"dx", &dx);
35 muParser.DefineVar(
"s", &s);
36 muParser.SetExpr(criterion);
44using namespace Kernel;
54 "An input workspace.");
55 declareProperty(
"Criterion",
"",
56 "Masking criterion as a muparser expression; y: bin count, "
57 "e: bin error, x: bin center, dx: bin center error, s: "
58 "spectrum axis value.");
60 "An output workspace.");
67 std::map<std::string, std::string> issues;
69 if (criterion.empty()) {
70 issues[
"Criterion"] =
"The criterion expression provided is empty";
72 double y = 0., e = 0.,
x = 0., dx = 0., s = 0.;
73 mu::Parser parser = makeParser(
y, e,
x, dx, s, criterion);
76 }
catch (mu::Parser::exception_type &exception) {
77 issues[
"Criterion"] =
"Invalid expression given: " + exception.GetMsg();
91 if (inputWorkspace != outputWorkspace) {
92 outputWorkspace = inputWorkspace->clone();
94 const auto verticalAxis = outputWorkspace->getAxis(1);
95 const auto numericAxis =
dynamic_cast<NumericAxis *
>(verticalAxis);
96 const auto spectrumAxis =
dynamic_cast<SpectraAxis *
>(verticalAxis);
97 const bool spectrumOrNumeric = numericAxis || spectrumAxis;
98 if (!spectrumOrNumeric) {
99 throw std::runtime_error(
"Vertical axis must be NumericAxis or SpectraAxis");
101 const auto numberHistograms =
static_cast<int64_t
>(outputWorkspace->getNumberHistograms());
102 auto progress = std::make_unique<Progress>(
this, 0., 1., numberHistograms);
107 double s = spectrumOrNumeric ? verticalAxis->getValue(
index) : 0.;
108 mu::Parser parser = makeParser(
y, e,
x, dx, s, criterion);
109 const auto &spectrum = outputWorkspace->histogram(
index);
110 const bool hasDx = outputWorkspace->hasDx(
index);
111 for (
auto it = spectrum.begin(); it != spectrum.end(); ++it) {
112 const auto bin = std::distance(spectrum.begin(), it);
115 e = it->countStandardDeviation();
116 dx = hasDx ? it->centerError() : 0.;
117 if (parser.Eval() != 0.) {
118 outputWorkspace->maskBin(
index, bin);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#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.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Class to represent a numeric axis of a workspace.
Class to represent the spectra axis of a workspace.
A property class for workspaces.
MaskBinsIf : Masks bins based on muparser expression.
void exec() override
Execute the algorithm.
std::map< std::string, std::string > validateInputs() override
Validate the inputs.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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.