26using namespace Kernel;
28using namespace Geometry;
29using DataObjects::EventWorkspace;
37 : m_inputWS(), m_inputEvWS(), m_DIFCref(0.), m_K(0.), m_Tmin(0.), m_wavelengthMin(0.), m_numberOfSpectra(0),
38 m_outputLowResTOF(false) {}
50 auto wsValidator = std::make_shared<CompositeValidator>();
57 "A workspace with x values in units of TOF and y values in counts");
59 "The name of the workspace to be created as the output of the algorithm");
62 "The name of the optional output workspace that contains low resolution "
63 "TOF which are removed "
64 "from input workspace.");
66 auto validator = std::make_shared<BoundedValidator<double>>();
67 validator->setLower(0.01);
71 "Some arbitrary number whose default "
72 "is 3.22 for reasons that I don't "
76 "The minimum time-of-flight of the frame (in microseconds). "
77 "If not set the data range will be used.");
79 "The minimum wavelength for measurement. This overides all "
80 "other parameters if specified.");
91 const auto &spectrumInfo =
m_inputWS->spectrumInfo();
100 if (!lowreswsname.empty())
124 for (
size_t workspaceIndex = 0; workspaceIndex <
m_numberOfSpectra; workspaceIndex++) {
126 const double tofMin = this->
calcTofMin(workspaceIndex, spectrumInfo);
128 auto last = std::lower_bound(
X.cbegin(),
X.cend(), tofMin);
131 const size_t endBin = last -
X.begin();
134 for (
size_t i = 0; i < endBin; i++) {
135 outputWS->maskBin(workspaceIndex, i);
146 auto outW = std::dynamic_pointer_cast<EventWorkspace>(matrixOutW);
153 auto lowW = std::dynamic_pointer_cast<EventWorkspace>(matrixLowResW);
156 <<
" microseconds\n";
158 std::size_t numEventsOrig = outW->getNumberEvents();
166 size_t numClearedEventLists = 0;
167 size_t numClearedEvents = 0;
170 for (
size_t workspaceIndex = 0; workspaceIndex <
m_numberOfSpectra; workspaceIndex++) {
171 if (outW->getSpectrum(workspaceIndex).getNumberEvents() > 0) {
172 double tmin = this->
calcTofMin(workspaceIndex, spectrumInfo);
175 g_log.
warning() <<
"tmin for workspaceIndex " << workspaceIndex <<
" is nan. Clearing out data. "
176 <<
"There are " << outW->getSpectrum(workspaceIndex).getNumberEvents() <<
" of it. \n";
177 numClearedEventLists += 1;
178 numClearedEvents += outW->getSpectrum(workspaceIndex).getNumberEvents();
179 outW->getSpectrum(workspaceIndex).clear(
false);
182 lowW->getSpectrum(workspaceIndex).clear(
false);
183 }
else if (tmin > 0.) {
185 outW->getSpectrum(workspaceIndex).maskTof(0., tmin);
186 if (outW->getSpectrum(workspaceIndex).getNumberEvents() == 0)
187 numClearedEventLists += 1;
190 double tmax = lowW->getSpectrum(workspaceIndex).getTofMax();
192 g_log.
warning() <<
"tmax for workspaceIndex " << workspaceIndex <<
" is nan. Clearing out data. \n";
193 lowW->getSpectrum(workspaceIndex).clear(
false);
197 if (tmax + DBL_MIN > tmin)
198 lowW->getSpectrum(workspaceIndex).maskTof(tmin, tmax + DBL_MIN);
205 lowW->getSpectrum(workspaceIndex).clear(
false);
210 g_log.
information() <<
"Went from " << numEventsOrig <<
" events to " << outW->getNumberEvents() <<
" events ("
211 << (
static_cast<double>(numEventsOrig - outW->getNumberEvents()) * 100. /
212 static_cast<double>(numEventsOrig))
214 if (numClearedEventLists > 0)
216 <<
" had all data removed. The number of removed events is " << numClearedEvents <<
".\n";
217 g_log.
debug() <<
"TOF range is now " << outW->getTofMin() <<
" to " << outW->getTofMax() <<
" microseconds\n";
223 const double l1 = spectrumInfo.
l1();
233 tmin = sqrtdmin * sqrtdmin / dspmap;
235 g_log.
warning() <<
"tmin is nan because dspmap = " << dspmap <<
".\n";
238 const double l2 = spectrumInfo.
l2(workspaceIndex);
242 std::vector<double>
X(1), temp(1);
244 wavelength->toTOF(
X, temp, l1, 0, {{UnitParams::l2,
l2}});
248 g_log.
debug() <<
"tmin[" << workspaceIndex <<
"] " << tmin <<
"\n";
269 throw std::runtime_error(
"Cannot have minimum time less than zero");
#define DECLARE_ALGORITHM(classname)
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.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
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.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
double difcUncalibrated(const size_t index) const
Calculate average uncalibrated DIFC value of detectors associated with this spectrum.
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
double l1() const
Returns L1 (distance from source to sample).
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
API::MatrixWorkspace_const_sptr m_inputWS
Pointer to the input workspace.
std::unique_ptr< API::Progress > m_progress
Progress reporting.
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
double calcTofMin(const std::size_t, const API::SpectrumInfo &spectrumInfo)
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
double m_wavelengthMin
The minimum wavelength accessible in the frame.
double m_DIFCref
The reference value for DIFC to filter with.
std::size_t m_numberOfSpectra
The number of spectra in the workspace.
void getTminData(const bool)
double m_Tmin
The start of the time-of-flight frame.
DataObjects::EventWorkspace_const_sptr m_inputEvWS
Pointer to the input event workspace.
void execEvent(const API::SpectrumInfo &spectrumInfo)
Remove low resolution TOF from an EventWorkspace.
void exec() override
Virtual method - must be overridden by concrete algorithm.
int version() const override
Algorithm's version for identification overriding a virtual method.
void init() override
Virtual method - must be overridden by concrete algorithm.
double m_K
Mystery variable that I'm not sure what it is for.
bool m_outputLowResTOF
Flag to generate low resolution TOF workspace.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning 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::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.