37using namespace Kernel;
38using API::MatrixWorkspace;
47 enum Kind :
char { Openning, Closing };
54 bool operator<(
const RangePoint &point)
const {
55 if (this->value == point.value) {
60 return this->kind == Openning;
62 return this->value < point.value;
70void joinOverlappingRanges(std::vector<double> &exclude) {
71 if (exclude.empty()) {
81 std::vector<RangePoint> points;
82 points.reserve(exclude.size());
83 for (
auto point = exclude.begin(); point != exclude.end(); point += 2) {
84 points.emplace_back(RangePoint{RangePoint::Openning, *point});
85 points.emplace_back(RangePoint{RangePoint::Closing, *(point + 1)});
88 std::sort(points.begin(), points.end());
95 for (
auto &point : points) {
96 if (point.kind == RangePoint::Openning) {
99 exclude.emplace_back(point.value);
106 exclude.emplace_back(point.value);
124 :
IMWDomainCreator(fit, workspacePropertyName, domainType), m_maxSize(0), m_normalise(false) {}
133 :
IMWDomainCreator(nullptr,
std::string(), domainType), m_maxSize(10), m_normalise(false) {}
147 m_maxSize =
static_cast<size_t>(maxSizeInt);
152 throw std::runtime_error(
"Exclude property has an odd number of entries. "
153 "It has to be even as each pair specifies a "
154 "start and an end of an interval to exclude.");
174 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
175 mustBePositive->setLower(0);
177 "The maximum number of values per a simple domain.");
181 "An option to normalise the histogram data (divide be the bin "
185 auto mustBeOrderedPairs = std::make_shared<ArrayOrderedPairsValidator<double>>();
187 "A list of pairs of doubles that specify ranges that "
188 "must be excluded from fit.");
194void FitMW::createDomain(std::shared_ptr<API::FunctionDomain> &domain, std::shared_ptr<API::FunctionValues> &values,
204 auto to =
X.begin() + endIndex;
210 domain.reset(seqDomain);
214 auto creator =
new FitMW;
220 creator->setRange(*(from +
m), *(from + k - 1));
232 std::vector<double>
x(
static_cast<size_t>(to - from));
234 for (
size_t i = 0; it != to; ++it, ++i) {
235 x[i] = (*it + *(it + 1)) / 2;
246 values->expand(i0 + domain->size());
252 assert(
n == domain->size());
255 if (endIndex >
Y.size()) {
256 throw std::runtime_error(
"FitMW: Inconsistent MatrixWorkspace");
268 if (shouldNormalise) {
269 double binWidth =
X[i + 1] -
X[i];
270 if (binWidth == 0.0) {
271 throw std::runtime_error(
"Zero width bin found, division by zero.");
279 }
else if (!std::isfinite(
y)) {
282 throw std::runtime_error(
"Infinte number or NaN found in input data.");
284 }
else if (!std::isfinite(
error)) {
287 throw std::runtime_error(
"Infinte number or NaN found in input data.");
288 }
else if (
error <= 0) {
292 weight = 1.0 /
error;
293 if (!std::isfinite(weight)) {
295 throw std::runtime_error(
"Error of a data point is probably too small.");
300 values->setFitData(j,
y);
301 values->setFitWeight(j, weight);
303 m_domain = std::dynamic_pointer_cast<API::FunctionDomain1D>(domain);
316 std::shared_ptr<API::FunctionDomain> domain,
317 std::shared_ptr<API::FunctionValues> values,
318 const std::string &outputWorkspacePropertyName) {
323 const auto &
X = mws.x(0);
324 std::vector<double> binWidths(
X.size());
325 std::adjacent_difference(
X.begin(),
X.end(), binWidths.begin());
326 for (
size_t ispec = 1; ispec < mws.getNumberHistograms(); ++ispec) {
327 auto &
Y = mws.mutableY(ispec);
328 std::transform(binWidths.begin() + 1, binWidths.end(),
Y.begin(),
Y.begin(), std::multiplies<double>());
329 auto &E = mws.mutableE(ispec);
330 std::transform(binWidths.begin() + 1, binWidths.end(), E.begin(), E.begin(), std::multiplies<double>());
Kind kind
The kind of the point: either openning or closing the range.
double value
The value of the point.
Specialization of FunctionDomain1DVector for spectra of MatrixWorkspaces.
A class to store values calculated by a function.
DomainType
Type of domain to create.
Kernel::IPropertyManager * m_manager
Pointer to a property manager.
bool m_ignoreInvalidData
Flag to ignore nans, infinities and zero errors.
void declareProperty(Kernel::Property *prop, const std::string &doc)
Declare a property to the algorithm.
DomainType m_domainType
Domain type.
Base MatrixWorkspace Abstract Class.
ExcludeRangeFinder : Helper clss that finds if a point should be excluded from fit.
bool isExcluded(double value)
Check if an x-value lies in an exclusion range.
Creates FunctionDomain1D form a spectrum in a MatrixWorkspace.
std::string m_excludePropertyName
Store the Exclude property name.
bool m_normalise
Option to normalise the data.
void createDomain(std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0=0) override
Create a domain from the input workspace.
void setParameters() const override
Set all parameters.
std::vector< double > m_exclude
Ranges that must be excluded from fit.
std::string m_maxSizePropertyName
Store maxSize property name.
size_t m_maxSize
Max size for seq domain.
void declareDatasetProperties(const std::string &suffix="", bool addProp=true) override
Declare properties that specify the dataset within the workspace to fit to.
FitMW(Kernel::IPropertyManager *fit, const std::string &workspacePropertyName, DomainType domainType=Simple)
Constructor.
std::string m_normalisePropertyName
Store Normalise property name.
std::shared_ptr< API::Workspace > createOutputWorkspace(const std::string &baseName, API::IFunction_sptr function, std::shared_ptr< API::FunctionDomain > domain, std::shared_ptr< API::FunctionValues > values, const std::string &outputWorkspacePropertyName) override
Create an output workspace.
A base class for domain creators taking 1D data from a spectrum of a matrix workspace.
void declareDatasetProperties(const std::string &suffix="", bool addProp=true) override
Declare properties that specify the dataset within the workspace to fit to.
void setWorkspace(std::shared_ptr< API::MatrixWorkspace > ws)
Set the workspace.
std::weak_ptr< API::FunctionDomain1D > m_domain
Store the created domain and values.
std::pair< size_t, size_t > getXInterval() const
Calculate size and starting iterator in the X array.
std::shared_ptr< API::MatrixWorkspace > m_matrixWorkspace
The input MareixWorkspace.
std::weak_ptr< API::FunctionValues > m_values
virtual void setParameters() const
Set all parameters.
size_t m_workspaceIndex
The workspace index.
std::shared_ptr< API::Workspace > createOutputWorkspace(const std::string &baseName, API::IFunction_sptr function, std::shared_ptr< API::FunctionDomain > domain, std::shared_ptr< API::FunctionValues > values, const std::string &outputWorkspacePropertyName) override
Create an output workspace.
An implementation of CompositeDomain.
void addCreator(const API::IDomainCreator_sptr &creator)
Add new domain creator.
static SeqDomain * create(API::IDomainCreator::DomainType type)
Create an instance of SeqDomain in one of two forms: either SeqDomain for sequential domain creation ...
Support for a property that holds an array of values.
Interface to PropertyManager.
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
The concrete, templated class for properties.
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< IDomainCreator > IDomainCreator_sptr
Typedef for a shared pointer to IDomainCreator.
constexpr bool operator<(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)