27using namespace Kernel;
29using DataObjects::EventWorkspace;
34 : m_conversionConstant(0.), m_inputWS(), m_inputEvWS(), m_LRef(0.), m_Tmin(0.), m_Tmax(0.), m_frameWidth(0.),
35 m_numberOfSpectra(0), m_XSize(0) {}
39 auto wsValidator = std::make_shared<CompositeValidator>();
46 "Contains numbers counts against time of flight (TOF).");
48 "This workspace will be in the units of time of flight. (See "
49 "http://www.mantidproject.org/Units)");
51 auto validator = std::make_shared<BoundedValidator<double>>();
52 validator->setLower(0.01);
54 "A distance at which it is possible to deduce if a particle "
55 "is from the current or a past frame based on its arrival "
56 "time. This time criterion can be set with the property "
57 "below e.g. correct when arrival time < Tmin.");
58 validator->setLower(0.01);
60 "With LRef this defines the maximum speed expected for "
61 "particles. For each count or time bin the mean particle "
62 "speed is calculated and if this is greater than LRef/Tmin "
63 "its TOF is corrected.");
64 validator->setLower(0.01);
66 "The maximum time of flight of the data used for the width "
67 "of the frame. If not set the maximum time of flight of the "
71 const double TOFisinMicroseconds = 1e6;
72 const double toAngstroms = 1e10;
115 const auto &spectrumInfo =
m_inputWS->spectrumInfo();
116 const double L1 = spectrumInfo.l1();
119 for (
int workspaceIndex = 0; workspaceIndex <
m_numberOfSpectra; workspaceIndex++) {
121 if (!spectrumInfo.hasDetectors(workspaceIndex)) {
123 g_log.
debug() <<
"Detector information for workspace index " << workspaceIndex <<
" is not available.\n";
124 outputWS->setSharedX(workspaceIndex,
m_inputWS->sharedX(workspaceIndex));
125 outputWS->mutableY(workspaceIndex) = 0.0;
126 outputWS->mutableE(workspaceIndex) = 0.0;
128 const double Ld = L1 + spectrumInfo.l2(workspaceIndex);
130 std::vector<double> timeBins;
132 outputWS->setBinEdges(workspaceIndex, std::move(timeBins));
137 auto &yIn =
m_inputWS->y(workspaceIndex);
138 auto &yOut = outputWS->mutableY(workspaceIndex);
140 auto lengthFirstPartY = std::distance(yIn.begin() + pivot, yIn.end());
141 std::copy(yIn.begin() + pivot, yIn.end(), yOut.begin());
142 std::copy(yIn.begin(), yIn.begin() + pivot, yOut.begin() + lengthFirstPartY);
145 auto &eIn =
m_inputWS->e(workspaceIndex);
146 auto &eOut = outputWS->mutableE(workspaceIndex);
148 auto lengthFirstPartE = std::distance(eIn.begin() + pivot, eIn.end());
149 std::copy(eIn.begin() + pivot, eIn.end(), eOut.begin());
150 std::copy(eIn.begin(), eIn.begin() + pivot, eOut.begin() + lengthFirstPartE);
168 auto outW = std::dynamic_pointer_cast<EventWorkspace>(matrixOutW);
179 const auto &spectrumInfo =
m_inputWS->spectrumInfo();
180 const double L1 = spectrumInfo.l1();
183 for (
int workspaceIndex = 0; workspaceIndex <
m_numberOfSpectra; workspaceIndex++) {
184 std::size_t
numEvents = outW->getSpectrum(workspaceIndex).getNumberEvents();
186 if (spectrumInfo.hasDetectors(workspaceIndex))
187 Ld = L1 + spectrumInfo.l2(workspaceIndex);
189 std::vector<double> time_bins;
190 if (outW->x(0).size() > 2) {
192 outW->setBinEdges(workspaceIndex, std::move(time_bins));
194 outW->setSharedX(workspaceIndex,
m_inputWS->sharedX(workspaceIndex));
198 outW->getSpectrum(workspaceIndex).getTofs(times);
201 if (times[j] < filterVal)
206 outW->getSpectrum(workspaceIndex).setTofs(times);
217 std::vector<double> tempX_L;
220 std::vector<double> tempX_U;
227 for (
int bin = 0; bin <
m_XSize; ++bin) {
230 const double tof = datain[bin];
231 if (tof < filterVal) {
235 if (specialBin < bin)
238 tempX_U.emplace_back(tof);
244 dataout.insert(dataout.begin(), tempX_U.begin(), tempX_U.end());
245 dataout.insert(dataout.end(), tempX_L.begin(), tempX_L.end());
246 assert(datain.size() == dataout.size());
267 m_inputWS->getXMinMax(dataTmin, dataTmax);
284 throw std::runtime_error(
"Cannot have Tmin less than zero");
286 throw std::runtime_error(
"Have case of Tmin > Tmax");
289 <<
"Angstrom, Frame width is: " <<
m_frameWidth <<
"microseconds\n";
297 throw std::runtime_error(
"MaskDetectors Child Algorithm has not executed successfully");
#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.
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.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A validator which checks that a workspace has a valid instrument.
A validator which checks that a workspace contains raw counts in its bins.
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
double m_conversionConstant
The constant used in the conversion from TOF.
double m_Tmin
The start of the time-of-flight frame.
double m_Tmax
The end of the time-of-flight frame.
double m_frameWidth
The width of the frame cached to speed up things.
void init() override
Initialisation method.
UnwrapSNS()
Default constructor.
double m_LRef
The 'reference' flightpath.
DataObjects::EventWorkspace_const_sptr m_inputEvWS
Pointer to the input event workspace.
int unwrapX(const Mantid::HistogramData::HistogramX &, std::vector< double > &dataout, const double &Ld)
API::MatrixWorkspace_const_sptr m_inputWS
to wavelength
int m_XSize
The size of the X vectors in the input workspace.
std::unique_ptr< API::Progress > m_progress
Progress reporting.
void exec() override
Executes the algorithm.
int m_numberOfSpectra
The number of spectra in the workspace.
void getTofRangeData(const bool)
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 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< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::size_t numEvents(::NeXus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const NexusHDF5Descriptor &descriptor)
Get the number of events in the currently opened group.
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.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.