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 HistogramData::BinEdges XValues_new(0);
66 auto &XValues_old = inputW->x(0);
67 std::vector<int> xoldIndex;
69 int ntcnew =
newAxis(rb_params, XValues_old.rawData(), XValues_new.mutableRawData(), xoldIndex);
75 int progress_step = histnumber / 100;
76 if (progress_step == 0)
78 for (
int hist = 0; hist < histnumber; hist++) {
80 auto &XValues = inputW->x(hist);
81 auto &YValues = inputW->y(hist);
82 auto &YErrors = inputW->e(hist);
85 auto &YValues_new = outputW->mutableY(hist);
86 auto &YErrors_new = outputW->mutableE(hist);
89 rebin(XValues, YValues, YErrors, xoldIndex, YValues_new, YErrors_new, dist);
91 outputW->setBinEdges(hist, XValues_new);
93 if (hist % progress_step == 0) {
99 outputW->setDistribution(dist);
102 if (outputW->getAxis(0)->unit().get())
103 outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit();
105 if (inputW->getAxis(1)->unit().get())
106 outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit();
127void Regroup::rebin(
const HistogramX &xold,
const HistogramY &yold,
const HistogramE &eold,
128 const std::vector<int> &xoldIndex, HistogramY &ynew, HistogramE &enew,
bool distribution) {
130 for (
int i = 0; i < int(xoldIndex.size() - 1); i++) {
132 int n = xoldIndex[i];
133 int m = xoldIndex[i + 1];
134 double width = xold[
m] - xold[
n];
138 throw std::runtime_error(
"Zero bin width");
147 for (
int j =
n; j <
m; j++) {
148 double wdt = xold[j + 1] - xold[j];
149 ynew[i] += yold[j] * wdt;
150 enew[i] += eold[j] * eold[j] * wdt * wdt;
153 enew[i] = sqrt(enew[i]) / width;
158 for (
int j =
n; j <
m; j++) {
160 enew[i] += eold[j] * eold[j];
162 enew[i] = sqrt(enew[i]);
176int Regroup::newAxis(
const std::vector<double> ¶ms,
const std::vector<double> &xold, std::vector<double> &xnew,
177 std::vector<int> &xoldIndex) {
179 int ibound(2), istep(1), inew(0);
180 auto ibounds =
static_cast<int>(params.size());
181 int isteps = ibounds - 1;
184 using std::placeholders::_1;
185 auto iup = std::find_if(xold.cbegin(), xold.cend(), std::bind(std::greater_equal<double>(), _1, xcurr));
186 if (iup != xold.end()) {
188 xnew.emplace_back(xcurr);
189 xoldIndex.emplace_back(inew);
194 while ((ibound <= ibounds) && (istep <= isteps)) {
196 if (params[istep] >= 0.0)
199 xs = xcurr *
fabs(params[istep]);
204 iup = std::find_if(xold.begin(), xold.end(), std::bind(std::greater_equal<double>(), _1, xcurr + xs));
205 if (iup != xold.end()) {
206 if (*iup <= params[ibound]) {
208 xnew.emplace_back(xcurr);
209 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.