34const std::string INPUT_WKSP(
"InputWorkspace");
35const std::string OUTPUT_WKSP(
"OutputWorkspace");
36const std::string
TYPE(
"Type");
39const std::string TOF_SCD(
"SingleCrystalTOF");
40const std::string TOF_PD(
"PowderTOF");
65 "Input workspace to correct in Wavelength.");
68 "An output workspace.");
69 const std::vector<std::string> correction_types{TOF_SCD, TOF_PD};
70 declareProperty(PropertyNames::TYPE, correction_types[0], std::make_shared<StringListValidator>(correction_types),
71 "Type of Lorentz correction to do");
75 std::map<std::string, std::string> result;
79 if (processingType == TOF_SCD) {
82 result[PropertyNames::INPUT_WKSP] =
"The workspace must be a MatrixWorkspace.";
86 const auto unit = wksp->getAxis(0)->unit();
87 if ((!unit) || (unit->unitID().compare(
"Wavelength"))) {
88 result[PropertyNames::INPUT_WKSP] =
"The workspace must have units of Wavelength";
102 cloneAlg->initialize();
103 cloneAlg->setProperty(
"InputWorkspace", inWS);
104 cloneAlg->setPropertyValue(
"OutputWorkspace", this->
getPropertyValue(PropertyNames::OUTPUT_WKSP));
109 Progress prog(
this, 0.1, 1.0, inWS->getNumberHistograms());
112 if (processingType == TOF_SCD)
114 else if (processingType == TOF_PD)
117 std::stringstream msg;
118 msg <<
"Do not understand know how to process Type=\"" << processingType
119 <<
"\" - developer forgot to fill in if/else tree";
120 throw std::runtime_error(msg.str());
123 this->
setProperty(PropertyNames::OUTPUT_WKSP, outWS);
127 const int64_t numHistos =
static_cast<int64_t
>(wksp->getNumberHistograms());
128 const auto &spectrumInfo = wksp->spectrumInfo();
131 for (int64_t i = 0; i < numHistos; ++i) {
137 const double sinTheta_v = sinTheta(spectrumInfo, i);
138 const double sinThetaSq = sinTheta_v * sinTheta_v;
140 auto &outY = wksp->mutableY(i);
141 auto &outE = wksp->mutableE(i);
142 const auto points = wksp->points(i);
143 const auto num_points = points.size();
144 const auto pos = std::find(cbegin(points), cend(points), 0.0);
145 if (pos != cend(points)) {
146 std::stringstream buffer;
147 buffer <<
"Cannot have zero values Wavelength. At workspace index: " << pos - cbegin(points);
148 throw std::runtime_error(buffer.str());
150 for (
size_t j = 0; j < num_points; ++j) {
151 double weight = sinThetaSq / (points[j] * points[j] * points[j] * points[j]);
164 const int64_t numHistos =
static_cast<int64_t
>(wksp->getNumberHistograms());
165 const auto &spectrumInfo = wksp->spectrumInfo();
168 bool isEvent = bool(wkspEvent);
171 for (int64_t i = 0; i < numHistos; ++i) {
177 const double sinTheta_v = sinTheta(spectrumInfo, i);
179 const auto points = wksp->points(i);
180 const auto pos = std::find(cbegin(points), cend(points), 0.0);
181 if (pos != cend(points)) {
182 std::stringstream buffer;
183 buffer <<
"Cannot have zero values Wavelength. At workspace index: " << pos - cbegin(points);
184 throw std::runtime_error(buffer.str());
188 wkspEvent->getSpectrum(i) *= sinTheta_v;
190 wksp->mutableY(i) *= sinTheta_v;
191 wksp->mutableE(i) *= sinTheta_v;
#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.
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.
Helper class for reporting progress from algorithms.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
bool hasDetectors(const size_t index) const
Returns true if the spectrum is associated with detectors in the instrument.
double twoTheta(const size_t index) const
Returns the scattering angle 2 theta in radians (angle w.r.t.
A property class for workspaces.
void processTOF_PD(Mantid::API::MatrixWorkspace_sptr &wksp, Mantid::API::Progress &prog)
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void processTOF_SCD(Mantid::API::MatrixWorkspace_sptr &wksp, Mantid::API::Progress &prog)
int version() const override
Algorithm's version for identification.
void exec() override
Execute the algorithm.
const std::string name() const override
function to return a name of the algorithm, must be overridden in all algorithms
const std::string category() const override
Algorithm's category for identification.
void init() override
Initialize the algorithm's properties.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
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< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace 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.
@ Input
An input workspace.
@ Output
An output workspace.