24using Mantid::HistogramData::Frequencies;
25using Mantid::HistogramData::FrequencyStandardDeviations;
26using Mantid::HistogramData::Histogram;
45 return "Creates a workspace of background data from a user-supplied set of "
46 "points. This workspace can then be subtracted from the original "
56 "Input workspace containing data and background");
58 "Table containing user-defined background points");
61 "Workspace containing background to be subtracted");
90 std::vector<size_t> blankRows;
91 const auto isZero = [](
const double n) {
return !(
fabs(
n) > std::numeric_limits<double>::epsilon()); };
92 for (
size_t i = table->rowCount() - 1; i > 0; i--) {
98 }
else if (isZero(
y)) {
99 blankRows.emplace_back(i);
102 for (
const auto &row : blankRows) {
103 table->removeRow(row);
107 std::vector<std::pair<std::string, bool>> sortArgs;
108 sortArgs.emplace_back(table->getColumn(0)->name(),
true);
109 table->sort(sortArgs);
120 const auto &xPoints = data->points(0);
129 const size_t endIndex =
background->rowCount() - 1;
130 if (
background->Double(endIndex, 0) < xPoints.back()) {
147 auto outputWS = data->clone();
149 const auto &xPoints = outputWS->points(0);
150 const auto &xBinEdges = outputWS->binEdges(0);
151 std::vector<double> yBackground;
152 std::vector<double> eBackground(xPoints.size(), 0);
156 for (
const auto &
x : xPoints) {
157 const double y = lerp.value(
x);
158 yBackground.emplace_back(
y);
161 auto histogram = outputWS->histogram(0);
162 if (histogram.yMode() == Histogram::YMode::Frequencies) {
163 histogram.setFrequencies(yBackground);
164 histogram.setFrequencyStandardDeviations(eBackground);
166 if (data->isHistogramData() &&
170 histogram.setCounts(Frequencies(yBackground), xBinEdges);
171 histogram.setCountStandardDeviations(FrequencyStandardDeviations(eBackground), xBinEdges);
173 histogram.setCounts(yBackground);
174 histogram.setCountStandardDeviations(eBackground);
179 for (
size_t spec = 0; spec < outputWS->getNumberHistograms(); spec++) {
181 outputWS->setHistogram(spec, histogram);
202 const auto xColumn =
background->getColumn(0);
203 const auto yColumn =
background->getColumn(1);
204 for (
size_t i = 0; i <
background->rowCount(); i++) {
205 double x = xColumn->cell<
double>(i);
206 double y = yColumn->cell<
double>(i);
221 std::map<std::string, std::string> errors;
223 const static std::string pointsProp =
"BackgroundPoints", inputProp =
"InputWorkspace";
226 if (pointsTable->columnCount() != 2) {
227 errors[pointsProp] =
"Table of points must have two columns (X, Y)";
229 for (
size_t col = 0; col < pointsTable->columnCount(); col++) {
230 const std::string colType = pointsTable->getColumn(col)->type();
231 if (colType !=
"double" && colType !=
"int") {
232 errors[pointsProp] =
"Table of points must have numeric columns";
235 if (pointsTable->rowCount() < 2) {
236 errors[pointsProp] =
"Table of points must contain at least two points";
242 if (inputWS->getNumberHistograms() == 0 || inputWS->blocksize() < 2) {
243 errors[inputProp] =
"Input workspace must contain some data";
245 if (!inputWS->isCommonBins()) {
246 errors[inputProp] =
"Input workspace must have common bins";
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
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.
TableRow represents a row in a TableWorkspace.
double & Double(size_t col)
Returns a reference to the element in position col if its type is double.
A property class for workspaces.
CreateUserDefinedBackground : Given an input workspace containing data with a background and a table ...
void init() override
Declare properties and initialise algorithm.
API::MatrixWorkspace_sptr createBackgroundWorkspace(const API::ITableWorkspace_const_sptr &background, const API::MatrixWorkspace_const_sptr &data) const
Create new background workspace with data interpolated from table.
const std::string category() const override
Category algorithm belongs to.
void exec() override
Execute algorithm.
static const std::string AUTODISTRIBUTIONKEY
Key name for "normalize histogram to bin width" option on plots.
void cleanUpTable(API::ITableWorkspace_sptr &table) const
Sort table and remove blank rows.
void extendBackgroundToData(API::ITableWorkspace_sptr &background, const API::MatrixWorkspace_const_sptr &data) const
Extend background to cover range of data.
std::map< std::string, std::string > validateInputs() override
Verify input properties and return errors.
const std::string summary() const override
Description of algorithm.
int version() const override
Version number.
Kernel::Interpolation getInterpolator(const API::ITableWorkspace_const_sptr &background, const API::MatrixWorkspace_const_sptr &workspace) const
Set up and return an interpolator object ready for use.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Provide interpolation over a series of points.
void setMethod(const std::string &method)
set interpolation method
void setXUnit(const std::string &unit)
set x-axis unit
void setYUnit(const std::string &unit)
set y-axis unit
void addPoint(const double &xx, const double &yy)
add data point
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
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
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.