14#include "MantidHistogramData/Histogram.h"
19using namespace Kernel;
21using namespace Geometry;
22using namespace DataObjects;
23using namespace HistogramData;
28 auto wsVal = std::make_shared<CompositeValidator>();
33 "Name of the input workspace to be split.");
35 "Name for the WorkspaceGroup that will be created.");
37 declareProperty(
"Step", 20000.0);
38 declareProperty(
"NChops", 5);
39 declareProperty(
"IntegrationRangeLower",
EMPTY_DBL());
40 declareProperty(
"IntegrationRangeUpper",
EMPTY_DBL());
41 declareProperty(
"MonitorWorkspaceIndex",
EMPTY_INT());
50 const double rLower =
getProperty(
"IntegrationRangeLower");
51 const double rUpper =
getProperty(
"IntegrationRangeUpper");
52 const int monitorWi =
getProperty(
"MonitorWorkspaceIndex");
53 const auto nHist =
static_cast<int>(inputWS->getNumberHistograms());
54 const size_t nBins = inputWS->blocksize();
55 const double maxX = inputWS->readX(0)[nBins];
56 std::map<int, double> intMap;
58 std::vector<MatrixWorkspace_sptr> workspaces;
62 throw std::invalid_argument(
"Step value provided larger than size of workspace.");
67 progress = std::make_unique<Progress>(
this, 0.0, 1.0, chops * 2);
72 MatrixWorkspace_sptr monitorWS = create<MatrixWorkspace>(*inputWS, 1, inputWS->histogram(monitorWi));
77 for (
int i = 0; i < chops; i++) {
81 integ->setProperty<
double>(
"RangeLower", i * step + rLower);
82 integ->setProperty<
double>(
"RangeUpper", i * step + rUpper);
85 intMap[i] = integR->y(0)[0];
87 if (intMap[i] < intMap[lowest]) {
94 auto nlow = intMap.find(lowest - 1);
95 if (nlow != intMap.end() && intMap[lowest] < (0.1 * nlow->second)) {
99 progress = std::make_unique<Progress>(
this, 0.0, 1.0, chops);
104 for (
int i = 0; i < chops; i++) {
105 const double stepDiff = (i * step);
107 size_t indexLow, indexHigh;
110 indexLow = inputWS->yIndexOfX(stepDiff);
111 if (indexLow < (nBins + 1)) {
114 }
catch (std::out_of_range &) {
123 indexHigh = inputWS->yIndexOfX((i + 1) * step);
124 }
catch (std::out_of_range &) {
128 size_t nbins = indexHigh - indexLow;
134 for (
int j = 0; j < nHist; j++) {
136 auto edges = inputWS->binEdges(j);
140 workspace->mutableX(j).assign(edges.cbegin() + indexLow, edges.cbegin() + indexLow + nbins + 1);
144 workspace->mutableY(j).assign(inputWS->y(j).cbegin() + indexLow, inputWS->y(j).cbegin() + indexLow + nbins);
146 workspace->mutableE(j).assign(inputWS->e(j).cbegin() + indexLow, inputWS->e(j).cbegin() + indexLow + nbins);
152 std::stringstream
name;
153 name << output <<
"_" << wsCounter;
154 std::string wsname =
name.str();
166 auto wsgroup = std::make_shared<WorkspaceGroup>();
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
#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.
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A validator which checks whether the input workspace has the Spectra number in the axis.
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
For use in TOSCA reduction.
const std::string name() const override
void exec() override
Executes the algorithm.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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.