17#include "MantidHistogramData/Histogram.h"
40 return "Corrects the time of flight of an indirect geometry instrument by a "
41 "time offset that is linearly dependent on the wavelength of the "
42 "neutron after passing through the moderator.";
51 std::make_shared<WorkspaceUnitValidator>(
"TOF")),
52 "The name of the input workspace, containing events and/or "
53 "histogram data, in units of time-of-flight");
55 "Wavelength dependent TOF shift, units in microsec/Angstrom. "
56 "Overrides the value stored in the instrument object");
58 "TOF shift, units in microseconds. Overrides the value"
59 "stored in the instrument object");
62 "The name of the output workspace");
75 const std::vector<std::string> Emode =
m_instrument->getStringParameter(
"deltaE-mode");
78 "instrument geometry (direct "
79 "or indirect) parameter",
81 if (Emode[0] !=
"indirect")
84 g_log.
error(
"Unable to retrieve instrument geometry (direct or indirect) "
94 const std::vector<double> gradientParam =
m_instrument->getNumberParameter(
"Moderator.TimeZero.gradient");
95 const double gradientParamManual =
getProperty(
"Gradient");
96 if (gradientParam.empty() && gradientParamManual ==
EMPTY_DBL())
109 const std::vector<double> interceptParam =
m_instrument->getNumberParameter(
"Moderator.TimeZero.intercept");
110 const double interceptParamManual =
getProperty(
"Intercept");
111 if (interceptParam.empty() && interceptParamManual ==
EMPTY_DBL())
113 inputWS->getTitle());
114 if (interceptParamManual !=
EMPTY_DBL()) {
122 g_log.
error(
"Unable to retrieve Moderator Time Zero parameters (gradient "
125 "Time Zero parameters (gradient "
127 inputWS->getTitle());
132 if (eventWS !=
nullptr) {
139 if (outputWS != inputWS) {
141 outputWS = create<MatrixWorkspace>(*inputWS);
145 const auto &spectrumInfo = inputWS->spectrumInfo();
146 auto const &componentInfo = inputWS->componentInfo();
147 const size_t numHists = inputWS->getNumberHistograms();
148 Progress prog(
this, 0.0, 1.0, numHists);
150 for (
int i = 0; i < static_cast<int>(numHists); ++i) {
153 auto wsIndex =
static_cast<size_t>(i);
154 calculateTfLi(spectrumInfo, componentInfo, wsIndex, t_f, L_i);
156 outputWS->setHistogram(i, inputWS->histogram(i));
160 const double scaling = L_i / (L_i +
m_gradient);
161 const double offset = (1 - scaling) * t_f - scaling *
m_intercept;
162 auto &outbins = outputWS->mutableX(i);
172 if (inputWS->getAxis(0)->unit()) {
173 outputWS->getAxis(0)->unit() = inputWS->getAxis(0)->unit();
176 if (inputWS->getAxis(1)->unit()) {
177 outputWS->getAxis(1)->unit() = inputWS->getAxis(1)->unit();
194 if (matrixOutputWS != matrixInputWS) {
195 matrixOutputWS = matrixInputWS->clone();
198 auto outputWS = std::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
201 const auto &spectrumInfo = matrixOutputWS->spectrumInfo();
202 auto const &componentInfo = matrixOutputWS->componentInfo();
203 const size_t numHists = outputWS->getNumberHistograms();
204 Progress prog(
this, 0.0, 1.0, numHists);
206 for (
int i = 0; i < static_cast<int>(numHists); ++i) {
207 auto wsIndex =
static_cast<size_t>(i);
209 EventList &evlist = outputWS->getSpectrum(wsIndex);
210 if (evlist.getNumberEvents() > 0)
214 calculateTfLi(spectrumInfo, componentInfo, wsIndex, t_f, L_i);
216 const double scaling = L_i / (L_i +
m_gradient);
219 evlist.convertTof(scaling, (1 - scaling) * t_f - scaling *
m_intercept);
226 outputWS->clearMRU();
231 size_t i,
double &t_f,
double &L_i) {
233 static const double TfError = -1.0;
245 L_i = spectrumInfo.
l1();
250 : std::vector<double>{};
251 if (!wsProp.empty()) {
252 double E_f = wsProp.at(0);
253 double v_f = convFact * sqrt(E_f);
254 t_f = spectrumInfo.
l2(i) / v_f;
256 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.
size_t firstDetectorIndex(const size_t index) const
Returns the detector index of the first detector of the spectrum with given index.
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).
bool hasUniqueDetector(const size_t index) const
Returns true if the spectrum is associated with exactly one detector.
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, Geometry::ComponentInfo const &componentInfo, 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
ComponentInfo : Provides a component centric view on to the instrument.
std::vector< double > getNumberParameter(const size_t componentIndex, const std::string &name, bool recursive=true) const
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.