28using namespace DataObjects;
29using namespace Geometry;
46 "An output workspace.");
47 const std::string docString =
"A comma separated list of first bin boundary, width, last bin boundary. "
49 "this can be followed by a comma and more widths and last boundary "
51 "Negative width values indicate logarithmic binning.";
52 auto rebinValidator = std::make_shared<RebinParamsValidator>();
56 "Flag to turn on the using the fractional area tracking RebinnedOutput "
60 "Run the Transpose algorithm on the resulting matrix.");
71 throw std::invalid_argument(
"Vertical axis is not a numeric axis, cannot rebin. "
72 "If it is a spectra axis try running ConvertSpectrumAxis first.");
75 const auto &oldXEdges = inputWS->binEdges(0);
76 const size_t numXBins = inputWS->blocksize();
77 const size_t numYBins = inputWS->getNumberHistograms();
84 BinEdges newXBins(oldXEdges.size());
85 BinEdges newYBins(oldXEdges.size());
92 bool useFractionalArea =
getProperty(
"UseFractionalArea");
93 auto inputHasFA = std::dynamic_pointer_cast<const RebinnedOutput>(inputWS);
95 if (useFractionalArea && !inputHasFA) {
96 g_log.
warning(
"Fractional area tracking was requested but input workspace does "
97 "not have calculated bin fractions. Assuming bins are exact "
98 "(fractions are unity). The results may not be accurate if this "
99 "workspace was previously rebinned.");
103 if (inputHasFA && !useFractionalArea) {
104 g_log.
warning(
"Input workspace has bin fractions (e.g. from a "
105 "parallelpiped rebin like SofQW3). To give accurate results, "
106 "fractional area tracking has been turn on.");
107 useFractionalArea =
true;
111 auto outputRB = std::dynamic_pointer_cast<RebinnedOutput>(outputWS);
114 const auto nreports(
static_cast<size_t>(numYBins));
115 m_progress = std::make_unique<API::Progress>(
this, 0.0, 1.0, nreports);
118 for (int64_t i = 0; i < static_cast<int64_t>(numYBins); ++i) {
121 m_progress->report(
"Computing polygon intersections");
122 const double vlo = oldYEdges[i];
123 const double vhi = oldYEdges[i + 1];
125 for (
size_t j = 0; j < numXBins; ++j) {
128 const double x_j = oldXEdges[j];
129 const double x_jp1 = oldXEdges[j + 1];
131 if (!useFractionalArea) {
141 if (useFractionalArea) {
143 outputRB->finalize(
true);
151 alg->setProperty(
"InputWorkspace", outputWS);
152 alg->setPropertyValue(
"OutputWorkspace",
"__anonymous");
154 outputWS = alg->getProperty(
"OutputWorkspace");
171 BinEdges &newYBins,
const bool useFractionalArea)
const {
174 auto &newY = newYBins.mutableRawData();
179 HistogramData::BinEdges binEdges(newXBins);
181 if (!useFractionalArea) {
182 outputWS = create<Workspace2D>(*parent, newYSize - 1, binEdges);
184 outputWS = create<RebinnedOutput>(*parent, newYSize - 1, binEdges);
186 auto verticalAxis = std::make_unique<BinEdgeAxis>(newY);
188 verticalAxis->unit() = parent->getAxis(1)->unit();
189 verticalAxis->title() = parent->getAxis(1)->title();
190 outputWS->replaceAxis(1, std::move(verticalAxis));
#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.
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.
Class to represent a numeric axis of a workspace.
virtual std::vector< double > createBinBoundaries() const
Create bin boundaries from the point values.
A property class for workspaces.
void exec() override
Run the algorithm.
std::unique_ptr< API::Progress > m_progress
Progress reporter.
void init() override
Initialise the properties.
API::MatrixWorkspace_sptr createOutputWorkspace(const API::MatrixWorkspace_const_sptr &parent, HistogramData::BinEdges &newXBins, HistogramData::BinEdges &newYBins, const bool useFractionalArea) const
Setup the output workspace.
This algorithm "transposes" the bins of the input workspace into a single spectra.
A ConvexPolygon with only 4 vertices.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
The concrete, templated class for properties.
Validator to check the format of a vector providing the rebin parameters to an algorithm.
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
MANTID_DATAOBJECTS_DLL void normaliseOutput(const API::MatrixWorkspace_sptr &outputWS, const API::MatrixWorkspace_const_sptr &inputWS, API::Progress *progress=nullptr)
Compute sqrt of errors and put back in bin width division if necessary.
MANTID_DATAOBJECTS_DLL void rebinToFractionalOutput(const Geometry::Quadrilateral &inputQ, const API::MatrixWorkspace_const_sptr &inputWS, const size_t i, const size_t j, DataObjects::RebinnedOutput &outputWS, const std::vector< double > &verticalAxis, const DataObjects::RebinnedOutput_const_sptr &inputRB=nullptr)
Rebin the input quadrilateral to to output grid.
MANTID_DATAOBJECTS_DLL void rebinToOutput(const Geometry::Quadrilateral &inputQ, const API::MatrixWorkspace_const_sptr &inputWS, const size_t i, const size_t j, API::MatrixWorkspace &outputWS, const std::vector< double > &verticalAxis)
Rebin the input quadrilateral to to output grid.
MANTID_DATAOBJECTS_DLL void finalizeFractionalRebin(DataObjects::RebinnedOutput &outputWS)
Set finalize flag after fractional rebinning loop.
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
int MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
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.
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.