16#include "MantidHistogramData/Histogram.h"
39 return "Corrects the time of flight of an indirect geometry instrument by a "
40 "time offset that is linearly dependent on the wavelength of the "
41 "neutron after passing through the moderator.";
50 std::make_shared<WorkspaceUnitValidator>(
"TOF")),
51 "The name of the input workspace, containing events and/or "
52 "histogram data, in units of time-of-flight");
54 "Wavelength dependent TOF shift, units in microsec/Angstrom. "
55 "Overrides the value stored in the instrument object");
57 "TOF shift, units in microseconds. Overrides the value"
58 "stored in the instrument object");
61 "The name of the output workspace");
74 const std::vector<std::string> Emode =
m_instrument->getStringParameter(
"deltaE-mode");
77 "instrument geometry (direct "
78 "or indirect) parameter",
80 if (Emode[0] !=
"indirect")
83 g_log.
error(
"Unable to retrieve instrument geometry (direct or indirect) "
93 const std::vector<double> gradientParam =
m_instrument->getNumberParameter(
"Moderator.TimeZero.gradient");
94 const double gradientParamManual =
getProperty(
"Gradient");
95 if (gradientParam.empty() && gradientParamManual ==
EMPTY_DBL())
108 const std::vector<double> interceptParam =
m_instrument->getNumberParameter(
"Moderator.TimeZero.intercept");
109 const double interceptParamManual =
getProperty(
"Intercept");
110 if (interceptParam.empty() && interceptParamManual ==
EMPTY_DBL())
112 inputWS->getTitle());
113 if (interceptParamManual !=
EMPTY_DBL()) {
121 g_log.
error(
"Unable to retrieve Moderator Time Zero parameters (gradient "
124 "Time Zero parameters (gradient "
126 inputWS->getTitle());
131 if (eventWS !=
nullptr) {
138 if (outputWS != inputWS) {
140 outputWS = create<MatrixWorkspace>(*inputWS);
144 const auto &spectrumInfo = inputWS->spectrumInfo();
145 const size_t numHists = inputWS->getNumberHistograms();
146 Progress prog(
this, 0.0, 1.0, numHists);
148 for (
int i = 0; i < static_cast<int>(numHists); ++i) {
151 auto wsIndex =
static_cast<size_t>(i);
154 outputWS->setHistogram(i, inputWS->histogram(i));
158 const double scaling = L_i / (L_i +
m_gradient);
159 const double offset = (1 - scaling) * t_f - scaling *
m_intercept;
160 auto &outbins = outputWS->mutableX(i);
170 if (inputWS->getAxis(0)->unit()) {
171 outputWS->getAxis(0)->unit() = inputWS->getAxis(0)->unit();
174 if (inputWS->getAxis(1)->unit()) {
175 outputWS->getAxis(1)->unit() = inputWS->getAxis(1)->unit();
192 if (matrixOutputWS != matrixInputWS) {
193 matrixOutputWS = matrixInputWS->clone();
196 auto outputWS = std::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
199 const auto &spectrumInfo = matrixOutputWS->spectrumInfo();
200 const size_t numHists = outputWS->getNumberHistograms();
201 Progress prog(
this, 0.0, 1.0, numHists);
203 for (
int i = 0; i < static_cast<int>(numHists); ++i) {
204 auto wsIndex =
static_cast<size_t>(i);
206 EventList &evlist = outputWS->getSpectrum(wsIndex);
207 if (evlist.getNumberEvents() > 0)
213 const double scaling = L_i / (L_i +
m_gradient);
216 evlist.convertTof(scaling, (1 - scaling) * t_f - scaling *
m_intercept);
223 outputWS->clearMRU();
229 static const double TfError = -1.0;
241 L_i = spectrumInfo.
l1();
244 if (!wsProp.empty()) {
245 double E_f = wsProp.at(0);
246 double v_f = convFact * sqrt(E_f);
247 t_f = spectrumInfo.
l2(i) / v_f;
249 g_log.
debug() <<
"Efixed not found for detector " << i <<
'\n';
#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.
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.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
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.
Kernel::V3D sourcePosition() const
Returns the source position.
bool hasDetectors(const size_t index) const
Returns true if the spectrum is associated with detectors in the instrument.
Kernel::V3D position(const size_t index) const
Returns the position of the spectrum with given index.
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
const Geometry::IDetector & detector(const size_t index) const
Return a const reference to the detector or detector group of the spectrum with given index.
double l1() const
Returns L1 (distance from source to sample).
A property class for workspaces.
const std::string summary() const override
Summary of algorithms purpose.
void init() override
Virtual method - must be overridden by concrete algorithm.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Virtual method - must be overridden by concrete algorithm.
const std::string name() const override
Algorithm's name.
void calculateTfLi(const API::SpectrumInfo &spectrumInfo, size_t i, double &t_f, double &L_i)
ModeratorTzeroLinear()
Default constructor.
int version() const override
Algorithm's version.
Geometry::Instrument_const_sptr m_instrument
virtual std::vector< double > getNumberParameter(const std::string &pname, bool recursive=true) const =0
Get a parameter defined as a double.
Exception for index errors.
Exception for errors associated with the instrument definition.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
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.
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double meV
1 meV in Joules.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.