28std::string
const FILENAME(
"Filename");
29std::string
const OUTPUT_WORKSPACE(
"OutputWorkspace");
30std::string
const START_X(
"StartSpectrum");
31std::string
const END_X(
"EndSpectrum");
32std::string
const EXCLUDE(
"ExcludeSpectra");
33std::string
const BACKGROUND(
"Background");
34std::string
const CENTRAL_PIXEL(
"CentralPixelSpectrum");
35std::string
const RANGE_LOWER(
"RangeLower");
36std::string
const RANGE_UPPER(
"RangeUpper");
40double const VERY_BIG_VALUE = 1.0e200;
41std::map<std::string, std::string>
const funMap{{
"Linear",
"name=LinearBackground"}, {
"Quadratic",
"name=Quadratic"}};
53 return "Algorithm to create a flood correction workspace for reflectometry "
67 std::vector<std::string> exts = defaultFacility.
extensions();
69 declareProperty(std::make_unique<MultipleFileProperty>(Prop::FILENAME, exts),
70 "The name of the flood run file(s) to read. Multiple runs "
71 "can be loaded and added together, e.g. INST10+11+12+13.ext");
84 std::vector<std::string> allowedValues;
85 allowedValues.reserve(funMap.size());
86 std::transform(funMap.cbegin(), funMap.cend(), std::back_inserter(allowedValues),
87 [](
const auto &i) { return i.first; });
88 auto backgroundValidator = std::make_shared<ListValidator<std::string>>(allowedValues);
89 declareProperty(Prop::BACKGROUND,
"Linear", backgroundValidator,
"Background function.");
92 "The flood correction workspace.");
98 alg->setProperty(
"Filename", fileName);
99 if (alg->existsProperty(
"LoadMonitors")) {
100 alg->setProperty(
"LoadMonitors",
false);
102 alg->setProperty(
"OutputWorkspace",
"dummy");
105 auto input = std::dynamic_pointer_cast<MatrixWorkspace>(ws);
107 throw std::invalid_argument(
"Loaded files do not produce a single MatrixWorkspace as expected.");
116 alg->setProperty(
"InputWorkspace", ws);
117 alg->setProperty(
"OutputWorkspace",
"dummy");
119 alg->setProperty(
"RangeLower",
static_cast<double>(
getProperty(Prop::RANGE_LOWER)));
122 alg->setProperty(
"RangeUpper",
static_cast<double>(
getProperty(Prop::RANGE_UPPER)));
125 return alg->getProperty(
"OutputWorkspace");
130 alg->setProperty(
"InputWorkspace", ws);
131 alg->setProperty(
"OutputWorkspace",
"dummy");
133 return alg->getProperty(
"OutputWorkspace");
147 auto const &
x = fitWS->x(0);
152 std::vector<double> excludeFromFit;
156 excludeFromFit.emplace_back(
x.front());
157 excludeFromFit.emplace_back(startX);
162 excludeFromFit.emplace_back(endX);
163 excludeFromFit.emplace_back(
x.back());
168 excludeFromFit.emplace_back(i);
169 excludeFromFit.emplace_back(i);
176 alg->setProperty(
"Function", function);
177 alg->setProperty(
"InputWorkspace", fitWS);
178 alg->setProperty(
"WorkspaceIndex", 0);
179 if (!excludeFromFit.empty()) {
180 alg->setProperty(
"Exclude", excludeFromFit);
182 alg->setProperty(
"Output",
"fit");
187 for (
size_t i = 0; i < func->nParams(); ++i) {
188 g_log.
information() <<
" " << func->parameterName(i) <<
": " << func->getParameter(i) <<
'\n';
194 auto const &bkg = bkgWS->y(1);
195 auto const nHisto =
static_cast<int>(ws->getNumberHistograms());
197 for (
int i = 0; i < nHisto; ++i) {
199 auto const xVal =
x[i];
201 ws->mutableY(i)[0] = VERY_BIG_VALUE;
202 ws->mutableE(i)[0] = 0.0;
203 }
else if (xVal >= startX && xVal <= endX) {
204 auto const background = bkg[i];
205 if (background <= 0.0) {
206 throw std::runtime_error(
"Background is expected to be positive, found value " +
std::to_string(background) +
209 ws->mutableY(i)[0] /= background;
210 ws->mutableE(i)[0] /= background;
212 ws->mutableY(i)[0] = 1.0;
213 ws->mutableE(i)[0] = 0.0;
220 ws->setSharedRun(make_cow<Run>());
226 int const centralSpectrum =
getProperty(Prop::CENTRAL_PIXEL);
227 auto const nHisto =
static_cast<int>(ws->getNumberHistograms());
228 if (centralSpectrum >= nHisto) {
229 throw std::invalid_argument(
"Spectrum index " +
std::to_string(centralSpectrum) +
" passed to property " +
230 Prop::CENTRAL_PIXEL +
" is outside the range 0-" +
std::to_string(nHisto - 1));
232 auto const spectraMap = ws->getSpectrumToWorkspaceIndexMap();
233 auto const centralIndex = spectraMap.at(centralSpectrum);
234 auto const scaleFactor = ws->y(centralIndex).front();
235 g_log.
information() <<
"Scale to central pixel, factor = " << scaleFactor <<
'\n';
236 if (scaleFactor <= 0.0) {
237 throw std::runtime_error(
"Scale factor muhst be > 0, found " +
std::to_string(scaleFactor));
239 auto const axis = ws->getAxis(1);
240 auto const sa =
dynamic_cast<const SpectraAxis *
>(axis);
244 for (
int i = 0; i < nHisto; ++i) {
246 auto const spec = ws->getSpectrum(i).getSpectrumNo();
248 ws->mutableY(i)[0] = VERY_BIG_VALUE;
249 ws->mutableE(i)[0] = 0.0;
250 }
else if (spec >= startX && spec <= endX) {
251 ws->mutableY(i)[0] /= scaleFactor;
252 ws->mutableE(i)[0] /= scaleFactor;
254 ws->mutableY(i)[0] = 1.0;
255 ws->mutableE(i)[0] = 0.0;
#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.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
bool isDefault(const std::string &name) const
Class to represent the spectra axis of a workspace.
A property class for workspaces.
Algorithm to create a flood correction workspace for reflectometry data reduction.
API::MatrixWorkspace_sptr getInputWorkspace()
API::MatrixWorkspace_sptr removeBackground(API::MatrixWorkspace_sptr ws)
API::MatrixWorkspace_sptr transpose(const API::MatrixWorkspace_sptr &ws)
void exec() override
Execute the algorithm.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso algorithms related to this algorithm.
const std::string summary() const override
function returns a summary message that will be displayed in the default GUI, and in the help.
bool isExcludedSpectrum(double spec) const
int version() const override
function to return a version of the algorithm, must be overridden in all algorithms
void collectExcludedSpectra()
std::string getBackgroundFunction()
bool shouldRemoveBackground()
API::MatrixWorkspace_sptr integrate(const API::MatrixWorkspace_sptr &ws)
void init() override
Initialize the algorithm's properties.
API::MatrixWorkspace_sptr scaleToCentralPixel(API::MatrixWorkspace_sptr ws)
const std::string category() const override
function to return a category of the algorithm.
std::vector< double > m_excludedSpectra
Support for a property that holds an array of values.
A class that holds information about a facility.
const std::vector< std::string > extensions() const
Returns a list of file extensions.
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.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
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.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
String constants for algorithm's properties.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Output
An output workspace.