18std::string
const CHECK_SORTING{
"CheckSortedX"};
19std::string
const COMPARISON_WS{
"ComparisonWorkspace"};
20std::string
const INPUT_WS{
"InputWorkspace"};
21std::string
const MASK_PARTIAL{
"MaskPartiallyOverlapping"};
22std::string
const OUTPUT_WS{
"OutputWorkspace"};
23std::string
const RAGGEDNESS{
"RaggedInputs"};
27std::string
const CHECK{
"Check"};
28std::string
const RAGGED{
"Ragged"};
29std::string
const NONRAGGED{
"Common Bins"};
37 auto const &Xs = ws.
x(i);
38 if (!std::is_sorted(Xs.cbegin(), Xs.cend())) {
49 size_t backBeginIndex;
54 bool const maskPartial,
size_t const histogramIndex) {
55 auto const &Xs = ws.
x(histogramIndex);
56 auto const &comparisonXs = comparisonWS.
x(histogramIndex);
58 auto const startX = comparisonXs.front();
59 auto const endX = comparisonXs.back();
62 auto frontEnd = std::lower_bound(Xs.cbegin(), Xs.cend() - 1, startX);
63 if (!maskPartial && frontEnd != Xs.cbegin() && *frontEnd != startX) {
66 auto backBegin = std::lower_bound(frontEnd, Xs.cend() - 1, endX);
67 if (maskPartial && backBegin != Xs.cbegin() && *backBegin > endX) {
71 limits.frontEndIndex =
static_cast<size_t>(std::distance(Xs.cbegin(), frontEnd));
72 limits.backBeginIndex =
static_cast<size_t>(std::distance(Xs.cbegin(), backBegin));
78 auto const xSize = ws.
x(histogramIndex).size();
79 for (
size_t binIndex = 0; binIndex < limits.frontEndIndex; ++binIndex) {
82 for (
size_t binIndex = limits.backBeginIndex; binIndex < xSize - 1; ++binIndex) {
102 return "Marks bins in InputWorkspace which are out of the X range of the "
113 "A workspace to mask.");
115 "The masked workspace.");
117 "A workspace to compare the InputWorkspace's binning to.");
118 declareProperty(Prop::MASK_PARTIAL,
false,
"If true, mask also bins that overlap only partially.");
119 std::vector<std::string>
const options{Raggedness::CHECK, Raggedness::RAGGED, Raggedness::NONRAGGED};
120 auto raggednessOptions = std::make_shared<Kernel::ListValidator<std::string>>(options);
121 declareProperty(Prop::RAGGEDNESS, Raggedness::CHECK, raggednessOptions,
122 "Choose whether the input workspaces have common bins, are "
123 "ragged, or if the algorithm should check.");
125 "If true, the algorithm ensures that both workspaces have X sorted in "
131 std::map<std::string, std::string> issues;
135 issues[Prop::INPUT_WS] =
"The " + Prop::INPUT_WS +
" must be a MatrixWorkspace.";
138 issues[Prop::COMPARISON_WS] =
"The " + Prop::COMPARISON_WS +
" must be a MatrixWorkspace.";
140 if (!issues.empty()) {
143 if (inputWS->getNumberHistograms() != comparisonWS->getNumberHistograms()) {
144 issues[Prop::COMPARISON_WS] =
"The number of histogams mismatches with " + Prop::INPUT_WS;
146 if (!inputWS->isHistogramData()) {
147 issues[Prop::INPUT_WS] =
"The workspace contains point data, not histograms.";
149 if (!comparisonWS->isHistogramData()) {
150 issues[Prop::COMPARISON_WS] =
"The workspace contains point data, not histograms.";
152 auto const inputAxis = inputWS->getAxis(0);
153 auto const comparisonAxis = comparisonWS->getAxis(0);
154 if (inputAxis && comparisonAxis) {
155 if (*(inputAxis->unit()) != *(comparisonAxis->unit())) {
156 issues[Prop::COMPARISON_WS] =
"X units do not match with " + Prop::INPUT_WS;
167 if (inputWS != outputWS) {
168 outputWS = inputWS->clone();
183 bool const checkSorting =
getProperty(Prop::CHECK_SORTING);
185 if (!isXSorted(inputWS)) {
186 throw std::invalid_argument(Prop::INPUT_WS +
" has unsorted X.");
188 if (!isXSorted(comparisonWS)) {
189 throw std::invalid_argument(Prop::COMPARISON_WS +
" has unsorted X.");
197 std::string
const choice =
getProperty(Prop::RAGGEDNESS);
198 if (choice == Raggedness::CHECK) {
201 return choice == Raggedness::NONRAGGED;
208 bool const maskPartial =
getProperty(Prop::MASK_PARTIAL);
213 for (
size_t histogramIndex = 0; histogramIndex < nHist; ++histogramIndex) {
214 auto const limits = maskingLimits(inputWS, comparisonWS, maskPartial, histogramIndex);
215 maskBinsWithinLimits(outputWS, histogramIndex, limits);
216 progress.report(
"Masking nonoverlapping bins");
224 bool const maskPartial =
getProperty(Prop::MASK_PARTIAL);
227 auto const limits = maskingLimits(inputWS, comparisonWS, maskPartial, 0);
228 for (
size_t histogramIndex = 0; histogramIndex < nHist; ++histogramIndex) {
229 maskBinsWithinLimits(outputWS, histogramIndex, limits);
230 progress.report(
"Masking nonoverlapping bins");
#define DECLARE_ALGORITHM(classname)
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Base MatrixWorkspace Abstract Class.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
const HistogramData::HistogramX & x(const size_t index) const
void flagMasked(const size_t &index, const size_t &binIndex, const double &weight=1.0)
Writes the masking weight to m_masks (doesn't alter y-values).
virtual bool isCommonBins() const
Returns true if the workspace contains common X bins.
Helper class for reporting progress from algorithms.
A property class for workspaces.
MaskNonOverlappingBins : Compares the X ranges of two workspace and masks the non-overlapping bins in...
void exec() override
Execute the algorithm.
void processNonRagged(API::MatrixWorkspace const &inputWS, API::MatrixWorkspace const &comparisonWS, API::MatrixWorkspace &outputWS)
Mask only workspace with same X in all histograms.
std::string const summary() const override
Algorithm's summary for use in the GUI and help.
std::vector< std::string > const seeAlso() const override
Return a list of the names of related algorithms.
void checkXSorting(API::MatrixWorkspace const &inputWS, API::MatrixWorkspace const &comparisonWS)
Throw if the workspaces don't have sorted X.
bool isCommonBins(API::MatrixWorkspace const &inputWS, API::MatrixWorkspace const &comparisonWS)
Return true if the workspaces should be considered as having common bins.
std::map< std::string, std::string > validateInputs() override
Returns a map from property name to message in case of invalid values.
std::string const category() const override
Algorithm's category for identification.
void processRagged(API::MatrixWorkspace const &inputWS, API::MatrixWorkspace const &comparisonWS, API::MatrixWorkspace &outputWS)
Mask all types of workspaces, ragged or nonragged.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
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.
String constants for algorithm's properties.
Constants for the RaggedInputs property.
Eigen::Matrix< size_t, 1, static_cast< int >(ND)> BinIndices
@ Input
An input workspace.
@ Output
An output workspace.