37 std::make_shared<WorkspaceUnitValidator>(
"TOF")),
38 "An input workspace.");
40 "An output workspace.");
42 auto validator = std::make_shared<BoundedValidator<double>>();
43 validator->setLower(0.0);
45 "The width of the time of flight (in microseconds) to remove from the data.");
47 "The frequency of the source (in Hz) used to calculate the minimum time of flight to filter.");
50 "Minimum time of flight. "
51 "Execution will be faster if this is specified, but the value will be determined from the workspace if not.");
54 "Minimum time of flight. "
55 "Execution will be faster if this is specified, but the value will be determined from the workspace if not.");
67 }
catch (
const std::invalid_argument &) {
74 const auto timerStart = std::chrono::high_resolution_clock::now();
81 const bool findTmin =
isEmpty(tmin);
82 const bool findTmax =
isEmpty(tmax);
84 if (findTmin && findTmax) {
85 if (
const auto eventWksp = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(wksp)) {
86 eventWksp->getEventXMinMax(tmin, tmax);
88 std::tie(tmin, tmax) = wksp->getXMinMax();
90 }
else if (findTmin) {
91 if (
const auto eventWksp = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(wksp)) {
92 tmin = eventWksp->getEventXMin();
94 tmin = wksp->getXMin();
96 }
else if (findTmax) {
97 if (
const auto eventWksp = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(wksp)) {
98 tmax = eventWksp->getEventXMax();
100 tmax = wksp->getXMax();
105 addTimer(
"getTofRange", timerStart, std::chrono::high_resolution_clock::now());
114 throw std::runtime_error(
"Failed to specify \'Width\' parameter");
122 if (this->
isEmpty(frequency)) {
124 if (this->
isEmpty(frequency)) {
125 throw std::runtime_error(
"Failed to determine the frequency");
129 double period = 1000000. / frequency;
135 g_log.
information() <<
"Data tmin=" << tmin <<
", tmax=" << tmax <<
", period=" << period <<
" microseconds\n";
139 if (pulseTimes.empty()) {
140 g_log.
notice() <<
"Not applying filter since prompt pulse is not in data "
143 setProperty(
"OutputWorkspace", std::const_pointer_cast<MatrixWorkspace>(inputWS));
147 for (
double pulseTime : pulseTimes)
154 for (
const double &pulseTime : pulseTimes) {
155 const double right = pulseTime + width;
157 g_log.
notice() <<
"Filtering tmin=" << pulseTime <<
", tmax=" <<
right <<
" microseconds\n";
161 algo->setProperty<
MatrixWorkspace_sptr>(
"InputWorkspace", std::const_pointer_cast<MatrixWorkspace>(outputWS));
163 algo->setProperty<
MatrixWorkspace_sptr>(
"InputWorkspace", std::const_pointer_cast<MatrixWorkspace>(inputWS));
168 algo->setProperty<
double>(
"XMin", pulseTime);
169 algo->setProperty<
double>(
"XMax",
right);
170 algo->executeAsChildAlg();
173 outputWS = algo->getProperty(
"OutputWorkspace");
183 if (!(this->
isEmpty(candidate)))
187 if (!(this->
isEmpty(candidate)))
191 if (!(this->
isEmpty(candidate)))
208 const double width) {
209 std::vector<double> times;
212 if (tmin > 0 && tmin < width)
213 times.emplace_back(time);
219 while (time < tmax) {
220 times.emplace_back(time);
#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.
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.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
void addTimer(const std::string &name, const Kernel::time_point_ns &begin, const Kernel::time_point_ns &end)
bool hasProperty(const std::string &name) const
Does the property exist on the object.
double getPropertyAsSingleValue(const std::string &name, Kernel::Math::StatisticType statistic=Kernel::Math::Mean) const
Returns a property as a single double value from its name.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
const std::string name() const override
Algorithm's name for identification.
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
double getFrequency(const API::Run &run)
Try to get the frequency from a given name.
std::vector< double > calculatePulseTimes(const double tmin, const double tmax, const double period, const double width)
Calculate when all prompt pulses might be between the supplied times.
void getTofRange(const API::MatrixWorkspace_const_sptr &wksp, double &tmin, double &tmax)
void exec() override
Run the algorithm.
void init() override
Sets documentation strings for this algorithm.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void information(const std::string &msg)
Logs at information level.
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
double getMedian(Range const &data)
There are enough special cases in determining the median where it useful to put it in a single functi...
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.