22using namespace HistogramData;
28using namespace Kernel;
29using API::MatrixWorkspace;
31using API::WorkspaceProperty;
38 "The input workspace");
40 "The result of rebinning");
42 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
43 mustBePositive->setLower(1);
44 declareProperty(
"NBunch", 1, mustBePositive,
"The number of bins that will be summed in each bunch");
58 bool dist = inputW->isDistribution();
61 auto histnumber =
static_cast<int>(inputW->size() / inputW->blocksize());
63 auto size_x =
static_cast<int>(inputW->x(0).size());
64 auto size_y =
static_cast<int>(inputW->y(0).size());
67 int ny = (size_y / n_bunch);
68 if (size_y % n_bunch > 0)
73 if (size_x == size_y) {
82 int progress_step = histnumber / 100;
83 if (progress_step == 0)
86 for (
int hist = 0; hist < histnumber; hist++) {
90 rebunch_point(inputW->x(hist), inputW->y(hist), inputW->e(hist), outputW->mutableX(hist), outputW->mutableY(hist),
91 outputW->mutableE(hist), n_bunch);
94 outputW->mutableY(hist), outputW->mutableE(hist), n_bunch);
96 rebunch_hist_counts(inputW->x(hist), inputW->y(hist), inputW->e(hist), outputW->mutableX(hist),
97 outputW->mutableY(hist), outputW->mutableE(hist), n_bunch);
100 if (hist % progress_step == 0) {
101 progress(
double(hist) / histnumber);
107 outputW->setDistribution(dist);
110 if (outputW->getAxis(0)->unit().get())
111 outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit();
113 if (inputW->getAxis(1)->unit().get())
114 outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit();
136 HistogramX &xnew, HistogramY &ynew, HistogramE &enew,
const size_t n_bunch) {
137 size_t size_x = xold.size();
138 size_t size_y = yold.size();
141 size_t hi_index = size_x - 1;
142 size_t wbins = size_y / n_bunch;
143 size_t rem = size_y % n_bunch;
151 for (i = 1; i <= n_bunch; i++) {
153 esum += eold[i_in] * eold[i_in];
158 enew[j] = sqrt(esum);
164 for (i = 1; i <= rem; i++) {
166 esum += eold[i_in] * eold[i_in];
170 enew[j] = sqrt(esum);
176 for (i = n_bunch; i < hi_index; i += n_bunch) {
180 xnew[j] = xold[hi_index];
196 HistogramX &xnew, HistogramY &ynew, HistogramE &enew,
const size_t n_bunch) {
198 size_t size_x = xold.size();
199 size_t size_y = yold.size();
202 size_t hi_index = size_x - 1;
203 size_t wbins = size_y / n_bunch;
204 size_t rem = size_y % n_bunch;
212 for (i = 1; i <= n_bunch; i++) {
213 width = xold[i_in + 1] - xold[i_in];
214 ysum += yold[i_in] * width;
215 esum += eold[i_in] * eold[i_in] * width * width;
220 enew[j] = sqrt(esum);
226 for (i = 1; i <= rem; i++) {
227 width = xold[i_in + 1] - xold[i_in];
228 ysum += yold[i_in] * width;
229 esum += eold[i_in] * eold[i_in] * width * width;
233 enew[j] = sqrt(esum);
239 for (i = n_bunch; i < hi_index; i += n_bunch) {
243 xnew[j] = xold[hi_index];
245 for (i = 0; i < ynew.size(); i++) {
246 width = xnew[i + 1] - xnew[i];
247 ynew[i] = ynew[i] / width;
248 enew[i] = enew[i] / width;
265 HistogramY &ynew, HistogramE &enew,
const size_t n_bunch) {
267 size_t size_y = yold.size();
268 double xsum, ysum, esum;
269 size_t wbins = size_y / n_bunch;
270 size_t rem = size_y % n_bunch;
279 for (i = 1; i <= n_bunch; i++) {
282 esum += eold[i_in] * eold[i_in];
286 xnew[j] = xsum /
static_cast<double>(n_bunch);
287 ynew[j] = ysum /
static_cast<double>(n_bunch);
288 enew[j] = sqrt(esum) /
static_cast<double>(n_bunch);
295 for (i = 1; i <= rem; i++) {
298 esum += eold[i_in] * eold[i_in];
301 xnew[j] = xsum /
static_cast<double>(rem);
302 ynew[j] = ysum /
static_cast<double>(rem);
303 enew[j] = sqrt(esum) /
static_cast<double>(rem);
#define DECLARE_ALGORITHM(classname)
#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.
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 property class for workspaces.
void rebunch_hist_counts(const HistogramData::HistogramX &xold, const HistogramData::HistogramY &yold, const HistogramData::HistogramE &eold, HistogramData::HistogramX &xnew, HistogramData::HistogramY &ynew, HistogramData::HistogramE &enew, const size_t n_bunch)
Rebunches histogram data data according to n_bunch input.
void init() override
Initialisation method.
void rebunch_hist_frequencies(const HistogramData::HistogramX &xold, const HistogramData::HistogramY &yold, const HistogramData::HistogramE &eold, HistogramData::HistogramX &xnew, HistogramData::HistogramY &ynew, HistogramData::HistogramE &enew, const size_t n_bunch)
Rebunches histogram data data according to n_bunch input.
void rebunch_point(const HistogramData::HistogramX &xold, const HistogramData::HistogramY &yold, const HistogramData::HistogramE &eold, HistogramData::HistogramX &xnew, HistogramData::HistogramY &ynew, HistogramData::HistogramE &enew, const size_t n_bunch)
Rebunches point data data according to n_bunch input.
void exec() override
Executes the rebin algorithm.
Exception for index errors.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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
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.
Helper class which provides the Collimation Length for SANS instruments.
@ Input
An input workspace.
@ Output
An output workspace.