19#include "MantidTypes/SpectrumDefinition.h"
23using namespace Kernel;
25using namespace DataObjects;
34 :
API::
Algorithm(), m_progress(
nullptr), m_algFactor(1.0), m_parname(), m_combine(false), m_binOp(), m_wi_min(-1),
42 "Name of the input workspace");
44 "Name of the output workspace");
45 auto isDouble = std::make_shared<BoundedValidator<double>>();
47 "The value by which to scale the X-axis of the input "
48 "workspace. Default is 1.0");
49 std::vector<std::string> op(2);
52 declareProperty(
"Operation",
"Multiply", std::make_shared<StringListValidator>(op),
53 "Whether to multiply by, or add factor");
54 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
55 mustBePositive->setLower(0);
57 "The workspace index of the first spectrum to scale. Only "
58 "used if IndexMax is set.");
60 "The workspace index of the last spectrum to scale. Only "
61 "used if explicitly set.");
65 "The name of an instrument parameter whose value is used to "
66 "scale as the input factor");
68 "If true, combine the value given in the Factor property with the value "
69 "obtained from the instrument parameter. The factors are combined using "
70 "the operation specified "
71 "in the Operation parameter");
84 throw std::invalid_argument(
"Combine behaviour requested but the "
85 "InstrumentParameter argument is blank.");
91 auto histnumber =
static_cast<int>(inputW->getNumberHistograms());
92 m_progress = std::make_unique<API::Progress>(
this, 0.0, 1.0, histnumber + 1);
100 if ((
m_wi_min <= tempwi_min) && (tempwi_min <= tempwi_max) && (tempwi_max <=
m_wi_max)) {
104 g_log.
error(
"Invalid Workspace Index min/max properties");
105 throw std::invalid_argument(
"Inconsistent properties defined");
109 const bool multiply = (op ==
"Multiply");
111 m_binOp = std::multiplies<double>();
117 if (eventWS !=
nullptr) {
124 for (
int i = 0; i < histnumber; ++i) {
128 outputW->setHistogram(i, inputW->histogram(i));
130 auto &outX = outputW->mutableX(i);
131 auto &outY = outputW->mutableY(i);
132 auto &outE = outputW->mutableE(i);
134 const auto &inX = inputW->x(i);
139 using std::placeholders::_1;
140 std::transform(inX.begin(), inX.end(), outX.begin(), std::bind(
m_binOp, _1, factor));
142 if (multiply && factor < 0.0) {
143 std::reverse(outX.begin(), outX.end());
144 std::reverse(outY.begin(), outY.end());
145 std::reverse(outE.begin(), outE.end());
156 if (outputW->getAxis(0)->unit().get())
157 outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit();
159 if (inputW->getAxis(1)->unit().get())
160 outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit();
173 if (matrixOutputWS != matrixInputWS) {
174 matrixOutputWS = matrixInputWS->clone();
177 auto outputWS = std::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
180 auto numHistograms =
static_cast<int>(outputWS->getNumberHistograms());
182 for (
int i = 0; i < numHistograms; ++i) {
187 if (op ==
"Multiply") {
188 outputWS->getSpectrum(i).scaleTof(factor);
190 outputWS->getSpectrum(i).reverse();
192 }
else if (op ==
"Add") {
193 outputWS->getSpectrum(i).addTof(factor);
200 outputWS->clearMRU();
206 if (input != output) {
227 const auto &spectrumInfo = inputWS->spectrumInfo();
228 if (!spectrumInfo.hasDetectors(
index)) {
232 const auto &detectorInfo = inputWS->detectorInfo();
233 const auto detIndex = spectrumInfo.spectrumDefinition(
index)[0].first;
234 const auto &det = detectorInfo.detector(detIndex);
235 const auto &
pmap = inputWS->constInstrumentParameters();
236 auto par =
pmap.getRecursive(det.getComponentID(),
m_parname);
239 return par->value<
double>();
243 std::ostringstream os;
244 os <<
"Spectrum at index '" <<
index <<
"' has no parameter named '" <<
m_parname <<
"'\n";
245 throw std::runtime_error(os.str());
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#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.
Base class from which all concrete algorithm classes should be derived.
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.
A property class for workspaces.
Takes a workspace and adjusts all the time bin values by the same multiplicative factor.
boost::function< double(double, double)> m_binOp
Function defining request operation.
double m_algFactor
Scaling factor.
int m_wi_min
Start workspace index.
int m_wi_max
Stop workspace index.
void exec() override
Executes the algorithm.
API::MatrixWorkspace_sptr createOutputWS(const API::MatrixWorkspace_sptr &input)
Create output workspace.
void execEvent()
Execute algorithm for EventWorkspaces.
void init() override
Initialisation method.
double getScaleFactor(const API::MatrixWorkspace_const_sptr &inputWS, const size_t index)
Get the scale factor for the given spectrum.
std::string m_parname
instrument parameter name
bool m_combine
Flag whether we are combining input parameters.
std::unique_ptr< API::Progress > m_progress
The progress reporting object.
Exception for index errors.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
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< 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
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.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Generate a tableworkspace to store the calibration results.
@ Input
An input workspace.
@ Output
An output workspace.