10#include "MantidAPI/Algorithm.tcc"
14#include "MantidHistogramData/Slice.h"
15#include "MantidIndexing/Extract.h"
16#include "MantidIndexing/IndexInfo.h"
24const double xBoundaryTolerance = 1.0e-15;
29using namespace Kernel;
31using namespace DataObjects;
32using namespace HistogramData;
33using Types::Event::TofEvent;
49 return "Extracts a list of spectra from a workspace and places them in a new "
55 std::map<std::string, std::string> helpMessages;
60 helpMessages[
"XMin"] =
"XMin must be less than XMax";
61 helpMessages[
"XMax"] =
"XMax must be greater than XMin";
72 "Name of the output workspace");
75 "An X value that is within the first "
76 "(lowest X value) bin that will be "
78 "(default: workspace min)");
80 "An X value that is in the highest X "
81 "value bin to be retained (default: max "
83 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
84 mustBePositive->setLower(0);
86 "The index number of the first entry in the Workspace that "
88 "(default: first entry in the Workspace)");
92 "The index number of the last entry in the Workspace to be loaded\n"
93 "(default: last entry in the Workspace)");
95 "A comma-separated list of individual workspace indices to "
96 "read. Only used if\n"
97 "explicitly set. The WorkspaceIndexList is only used if the "
98 "DetectorList is empty.");
101 "A comma-separated list of individual detector IDs to read. "
103 "explicitly set. When specifying the WorkspaceIndexList and "
104 "DetectorList property,\n"
105 "the latter is being selected.");
124 auto extract = std::make_shared<ExtractSpectra2>();
126 extract->setWorkspaceInputProperties(
147 Progress prog(
this, 0.0, 1.0, size);
148 for (
int i = 0; i < size; ++i) {
161template <
class T>
struct eventFilter {
164 bool operator()(
const T &
value) {
165 const double tof =
value.tof();
166 return !(tof <= maxValue && tof >=
minValue);
173template <
class T>
void filterEventsHelper(std::vector<T> &events,
const double xmin,
const double xmax) {
174 events.erase(std::remove_if(events.begin(), events.end(), eventFilter<T>(xmin, xmax)), events.end());
186 minX_val =
eventW->getTofMin();
188 maxX_val =
eventW->getTofMax();
190 BinEdges binEdges(2);
193 binEdges = BinEdges(oldX.begin() +
m_minX, oldX.begin() +
m_maxX);
197 binEdges = {minX_val, maxX_val};
204 for (
int i = 0; i < static_cast<int>(
eventW->getNumberHistograms()); ++i) {
208 switch (el.getEventType()) {
210 filterEventsHelper(el.getEvents(), minX_val, maxX_val);
214 filterEventsHelper(el.getWeightedEvents(), minX_val, maxX_val);
218 filterEventsHelper(el.getWeightedEventsNoTime(), minX_val, maxX_val);
226 const auto oldDx = el.pointStandardDeviations();
227 el.setHistogram(binEdges);
243 for (
const auto &mask :
workspace.maskedBins(i)) {
244 const size_t maskIndex = mask.first;
246 filteredMask[maskIndex -
m_minX] = mask.second;
248 if (filteredMask.size() > 0)
249 workspace.setMaskedBins(i, filteredMask);
269 throw std::out_of_range(
"XMin must be less than XMax");
294 int minSpec_i =
getProperty(
"StartWorkspaceIndex");
295 auto minSpec =
static_cast<size_t>(minSpec_i);
298 auto maxSpec =
static_cast<size_t>(maxSpec_i);
300 maxSpec = numberOfSpectra - 1;
301 if (maxSpec < minSpec) {
302 g_log.
error(
"StartWorkspaceIndex must be less than or equal to "
303 "EndWorkspaceIndex");
304 throw std::out_of_range(
"StartWorkspaceIndex must be less than or equal "
305 "to EndWorkspaceIndex");
307 if (maxSpec - minSpec + 1 != numberOfSpectra) {
309 for (
size_t i = minSpec; i <= maxSpec; ++i)
329 std::stringstream msg;
330 msg <<
"XMin is greater than the largest X value (" << minX_val <<
" > " <<
X.back() <<
")";
331 throw std::out_of_range(msg.str());
335 minX_val -= std::abs(minX_val * xBoundaryTolerance);
336 xIndex = std::lower_bound(
X.begin(),
X.end(), minX_val) -
X.begin();
349 size_t xIndex =
X.size();
354 std::stringstream msg;
355 msg <<
"XMax is less than the smallest X value (" << maxX_val <<
" < " <<
X.front() <<
")";
356 throw std::out_of_range(msg.str());
360 maxX_val += std::abs(maxX_val * xBoundaryTolerance);
361 xIndex = std::upper_bound(
X.begin(),
X.end(), maxX_val) -
X.begin();
373 const size_t size =
Y.size();
377 for (
size_t i = 0; i < startX; ++i) {
384 for (
size_t i = endX; i < size; ++i) {
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
IPeaksWorkspace_sptr workspace
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.
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.
bool isDefault(const std::string &name) const
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
void setupAsChildAlgorithm(const Algorithm_sptr &algorithm, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true)
Setup algorithm as child algorithm.
Base MatrixWorkspace Abstract Class.
std::map< size_t, double > MaskList
Masked bins for each spectrum are stored as a set of pairs containing <bin index, weight>
Helper class for reporting progress from algorithms.
A property class for workspaces.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
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.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.