25using HistogramData::HistogramE;
26using HistogramData::HistogramX;
27using HistogramData::HistogramY;
33using namespace Kernel;
34using API::MatrixWorkspace;
37using API::WorkspaceProperty;
41 auto wsVal = std::make_shared<CompositeValidator>();
45 "The input workspace.");
47 "The result of regrouping.");
50 "The new approximate bin boundaries in the form: x1,dx1,x2,dx2,...,xn");
57 std::vector<double> rb_params =
getProperty(
"Params");
62 const bool dist = inputW->isDistribution();
64 const auto histnumber =
static_cast<int>(inputW->getNumberHistograms());
65 auto &XValues_old = inputW->x(0);
66 std::vector<int> xoldIndex;
68 std::vector<double> xAxisTmp;
69 int ntcnew =
newAxis(rb_params, XValues_old.rawData(), xAxisTmp, xoldIndex);
70 HistogramData::BinEdges XValues_new(std::move(xAxisTmp));
76 int progress_step = histnumber / 100;
77 if (progress_step == 0)
79 for (
int hist = 0; hist < histnumber; hist++) {
81 auto &XValues = inputW->x(hist);
82 auto &YValues = inputW->y(hist);
83 auto &YErrors = inputW->e(hist);
86 auto &YValues_new = outputW->mutableY(hist);
87 auto &YErrors_new = outputW->mutableE(hist);
90 rebin(XValues, YValues, YErrors, xoldIndex, YValues_new, YErrors_new, dist);
92 outputW->setBinEdges(hist, XValues_new);
94 if (hist % progress_step == 0) {
100 outputW->setDistribution(dist);
103 if (outputW->getAxis(0)->unit().get())
104 outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit();
106 if (inputW->getAxis(1)->unit().get())
107 outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit();
128void Regroup::rebin(
const HistogramX &xold,
const HistogramY &yold,
const HistogramE &eold,
129 const std::vector<int> &xoldIndex, HistogramY &ynew, HistogramE &enew,
bool distribution) {
131 for (
int i = 0; i < int(xoldIndex.size() - 1); i++) {
133 int n = xoldIndex[i];
134 int m = xoldIndex[i + 1];
135 double width = xold[
m] - xold[
n];
139 throw std::runtime_error(
"Zero bin width");
148 for (
int j =
n; j <
m; j++) {
149 double wdt = xold[j + 1] - xold[j];
150 ynew[i] += yold[j] * wdt;
151 enew[i] += eold[j] * eold[j] * wdt * wdt;
154 enew[i] = sqrt(enew[i]) / width;
159 for (
int j =
n; j <
m; j++) {
161 enew[i] += eold[j] * eold[j];
163 enew[i] = sqrt(enew[i]);
177int Regroup::newAxis(
const std::vector<double> ¶ms,
const std::vector<double> &xold, std::vector<double> &xnew,
178 std::vector<int> &xoldIndex) {
180 int ibound(2), istep(1), inew(0);
181 auto ibounds =
static_cast<int>(params.size());
182 int isteps = ibounds - 1;
185 using std::placeholders::_1;
186 auto iup = std::find_if(xold.cbegin(), xold.cend(), std::bind(std::greater_equal<double>(), _1, xcurr));
187 if (iup != xold.end()) {
189 xnew.emplace_back(xcurr);
190 xoldIndex.emplace_back(inew);
195 while ((ibound <= ibounds) && (istep <= isteps)) {
197 if (params[istep] >= 0.0)
200 xs = xcurr *
fabs(params[istep]);
205 iup = std::find_if(xold.begin(), xold.end(), std::bind(std::greater_equal<double>(), _1, xcurr + xs));
206 if (iup != xold.end()) {
207 if (*iup <= params[ibound]) {
209 xnew.emplace_back(xcurr);
210 xoldIndex.emplace_back(inew);
#define DECLARE_ALGORITHM(classname)
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.
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
A validator which provides a TENTATIVE check that a workspace contains common bins in each spectrum.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A property class for workspaces.
void rebin(const HistogramData::HistogramX &xold, const HistogramData::HistogramY &yold, const HistogramData::HistogramE &eold, const std::vector< int > &xoldIndex, HistogramData::HistogramY &ynew, HistogramData::HistogramE &enew, bool distribution)
Regroup the data according to new output X array.
void exec() override
Executes the regroup algorithm.
void init() override
Initialisation method. Declares properties to be used in algorithm.
int newAxis(const std::vector< double > ¶ms, const std::vector< double > &xold, std::vector< double > &xnew, std::vector< int > &xoldIndex)
Creates a new output X array according to specific boundary defnitions.
Support for a property that holds an array of values.
Exception for index errors.
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.
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
Helper class which provides the Collimation Length for SANS instruments.
@ Input
An input workspace.
@ Output
An output workspace.