13#include "MantidHistogramData/Rebin.h"
18using DataObjects::EventWorkspace;
20using HistogramData::Counts;
21using HistogramData::CountStandardDeviations;
35 std::make_unique<API::HistogramValidator>()),
36 "The workspace on which to perform the algorithm "
37 "This must be a Histogram workspace, not Point data. "
38 "If this is a problem try ConvertToHistogram.");
40 std::make_unique<API::HistogramValidator>()),
41 "The workspace to match the bin boundaries against. "
42 "This must be a Histogram workspace, not Point data. "
43 "If this is a problem try ConvertToHistogram.");
45 "The name of the workspace to be created as the output of the algorithm");
46 declareProperty(
"PreserveEvents",
true,
47 "Keep the output workspace as an EventWorkspace, if the "
48 "input has events (default). "
49 "If the input and output EventWorkspace names are the same, "
50 "only the X bins are set, which is very quick. "
51 "If false, then the workspace gets converted to a "
52 "Workspace2D histogram.");
65 const size_t numHist =
left->getNumberHistograms();
66 if (numHist != rght->getNumberHistograms())
70 for (
size_t i = 0; i < numHist; ++i) {
71 if (
left->getSpectrum(i).x() != rght->getSpectrum(i).x()) {
87 m_isEvents = bool(std::dynamic_pointer_cast<const EventWorkspace>(toRebin));
94 this->
rebin(toRebin, toMatch);
97 g_log.
information(
"WorkspaceToRebin and WorkspaceToMatch already have matched binning");
100 const bool inPlace = (toRebin == outputWS);
102 outputWS = toRebin->clone();
112 const bool inPlace = (toRebin == outputWS);
114 outputWS = toRebin->clone();
116 auto outputWSEvents = std::dynamic_pointer_cast<EventWorkspace>(outputWS);
118 const auto numHist =
static_cast<int>(toRebin->getNumberHistograms());
119 Progress prog(
this, 0.5, 1.0, numHist);
122 const bool matchingX = (toRebin->getNumberHistograms() != toMatch->getNumberHistograms());
126 for (
int i = 0; i < numHist; ++i) {
128 const auto &edges = matchingX ? toMatch->histogram(0).binEdges() : toMatch->histogram(i).binEdges();
130 outputWSEvents->getSpectrum(i).setHistogram(edges);
132 outputWS->setHistogram(i, HistogramData::rebin(toRebin->histogram(i), edges));
145 const auto &inputWS = std::dynamic_pointer_cast<const EventWorkspace>(toRebin);
146 const auto numHist =
static_cast<int>(toRebin->getNumberHistograms());
148 const bool matchingX = (toRebin->getNumberHistograms() != toMatch->getNumberHistograms());
150 auto outputWS = DataObjects::create<API::HistoWorkspace>(*toRebin);
151 Progress prog(
this, 0.25, 1.0, numHist);
155 for (
int i = 0; i < numHist; ++i) {
157 const auto &edges = matchingX ? toMatch->histogram(0).binEdges() : toMatch->histogram(i).binEdges();
160 const auto &eventlist = inputWS->getSpectrum(i);
161 MantidVec y_data(edges.size() - 1), e_data(edges.size() - 1);
162 eventlist.generateHistogram(edges.rawData(), y_data, e_data);
164 outputWS->setHistogram(i, edges, Counts(std::move(y_data)), CountStandardDeviations(std::move(e_data)));
170 setProperty(
"OutputWorkspace", std::move(outputWS));
173Parallel::ExecutionMode
178 if (storageModes.at(
"WorkspaceToMatch") != Parallel::StorageMode::Cloned)
179 throw std::runtime_error(
"WorkspaceToMatch must have " + Parallel::toString(Parallel::StorageMode::Cloned));
180 return Parallel::getCorrespondingExecutionMode(storageModes.at(
"WorkspaceToRebin"));
#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.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Helper class for reporting progress from algorithms.
A property class for workspaces.
Rebins a workspace so that the binning, for all its spectra, match that of the first spectrum of a se...
Parallel::ExecutionMode getParallelExecutionMode(const std::map< std::string, Parallel::StorageMode > &storageModes) const override
Get correct execution mode based on input storage modes for an MPI run.
void exec() override
Execution code.
void histogram(API::MatrixWorkspace_sptr &toRebin, API::MatrixWorkspace_sptr &toMatch)
void rebin(API::MatrixWorkspace_sptr &toRebin, API::MatrixWorkspace_sptr &toMatch)
bool needToRebin(const API::MatrixWorkspace_sptr &left, const API::MatrixWorkspace_sptr &rght)
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information 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::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
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.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
@ Input
An input workspace.
@ Output
An output workspace.