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) {
41 auto wsValidator = std::make_shared<CompositeValidator>();
48 "Contains numbers counts against time of flight (TOF).");
50 "This workspace will be in the units of time of flight. (See "
51 "http://docs.mantidproject.org/concepts/UnitFactory)");
53 auto validator = std::make_shared<BoundedValidator<double>>();
54 validator->setLower(0.01);
56 "A distance at which it is possible to deduce if a particle "
57 "is from the current or a past frame based on its arrival "
58 "time. This time criterion can be set with the property "
59 "below e.g. correct when arrival time < Tmin.");
60 validator->setLower(0.01);
62 "With LRef this defines the maximum speed expected for "
63 "particles. For each count or time bin the mean particle "
64 "speed is calculated and if this is greater than LRef/Tmin "
65 "its TOF is corrected.");
66 validator->setLower(0.01);
68 "The maximum time of flight of the data used for the width "
69 "of the frame. If not set the maximum time of flight of the "
73 const double TOFisinMicroseconds = 1e6;
74 const double toAngstroms = 1e10;
117 const auto &spectrumInfo =
m_inputWS->spectrumInfo();
118 const double L1 = spectrumInfo.l1();
121 for (
int workspaceIndex = 0; workspaceIndex <
m_numberOfSpectra; workspaceIndex++) {
123 if (!spectrumInfo.hasDetectors(workspaceIndex)) {
125 g_log.
debug() <<
"Detector information for workspace index " << workspaceIndex <<
" is not available.\n";
126 outputWS->setSharedX(workspaceIndex,
m_inputWS->sharedX(workspaceIndex));
127 outputWS->mutableY(workspaceIndex) = 0.0;
128 outputWS->mutableE(workspaceIndex) = 0.0;
130 const double Ld = L1 + spectrumInfo.l2(workspaceIndex);
132 std::vector<double> timeBins;
134 outputWS->setBinEdges(workspaceIndex, std::move(timeBins));
139 auto &yIn =
m_inputWS->y(workspaceIndex);
140 auto &yOut = outputWS->mutableY(workspaceIndex);
142 auto lengthFirstPartY = std::distance(yIn.begin() + pivot, yIn.end());
143 std::copy(yIn.begin() + pivot, yIn.end(), yOut.begin());
144 std::copy(yIn.begin(), yIn.begin() + pivot, yOut.begin() + lengthFirstPartY);
147 auto &eIn =
m_inputWS->e(workspaceIndex);
148 auto &eOut = outputWS->mutableE(workspaceIndex);
150 auto lengthFirstPartE = std::distance(eIn.begin() + pivot, eIn.end());
151 std::copy(eIn.begin() + pivot, eIn.end(), eOut.begin());
152 std::copy(eIn.begin(), eIn.begin() + pivot, eOut.begin() + lengthFirstPartE);
170 auto outW = std::dynamic_pointer_cast<EventWorkspace>(matrixOutW);
181 const auto &spectrumInfo =
m_inputWS->spectrumInfo();
182 const double L1 = spectrumInfo.l1();
185 for (
int workspaceIndex = 0; workspaceIndex <
m_numberOfSpectra; workspaceIndex++) {
186 std::size_t
numEvents = outW->getSpectrum(workspaceIndex).getNumberEvents();
188 if (spectrumInfo.hasDetectors(workspaceIndex))
189 Ld = L1 + spectrumInfo.l2(workspaceIndex);
191 if (outW->x(0).size() > 2) {
192 std::vector<double> time_bins;
194 outW->setBinEdges(workspaceIndex, std::move(time_bins));
196 outW->setSharedX(workspaceIndex,
m_inputWS->sharedX(workspaceIndex));
200 outW->getSpectrum(workspaceIndex).getTofs(times);
203 if (times[j] < filterVal)
208 outW->getSpectrum(workspaceIndex).setTofs(times);
219 std::vector<double> tempX_L;
222 std::vector<double> tempX_U;
229 for (
int bin = 0; bin <
m_XSize; ++bin) {
232 const double tof = datain[bin];
233 if (tof < filterVal) {
237 if (specialBin < bin)
240 tempX_U.emplace_back(tof);
246 dataout.insert(dataout.begin(), tempX_U.begin(), tempX_U.end());
247 dataout.insert(dataout.end(), tempX_L.begin(), tempX_L.end());
248 assert(datain.size() == dataout.size());
269 m_inputWS->getXMinMax(dataTmin, dataTmax);
286 throw std::runtime_error(
"Cannot have Tmin less than zero");
288 throw std::runtime_error(
"Have case of Tmin > Tmax");
291 <<
"Angstrom, Frame width is: " <<
m_frameWidth <<
"microseconds\n";
299 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.
void deprecatedDate(const std::string &)
The date the algorithm was deprecated on.
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 Nexus::NexusDescriptor &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.