35 std::make_shared<WorkspaceUnitValidator>(
"TOF")),
36 "An input workspace.");
38 "An output workspace.");
40 auto validator = std::make_shared<BoundedValidator<double>>();
41 validator->setLower(0.0);
43 "The width of the time of flight (in microseconds) to remove from the data.");
45 "The frequency of the source (in Hz) used to calculate the minimum time of flight to filter.");
48 "Minimum time of flight. "
49 "Execution will be faster if this is specified, but the value will be determined from the workspace if not.");
52 "Minimum time of flight. "
53 "Execution will be faster if this is specified, but the value will be determined from the workspace if not.");
65 }
catch (
const std::invalid_argument &) {
72 const auto timerStart = std::chrono::high_resolution_clock::now();
79 const bool findTmin =
isEmpty(tmin);
80 const bool findTmax =
isEmpty(tmax);
82 if (findTmin && findTmax) {
83 if (
const auto eventWksp = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(wksp)) {
84 eventWksp->getEventXMinMax(tmin, tmax);
86 wksp->getXMinMax(tmin, tmax);
88 }
else if (findTmin) {
89 if (
const auto eventWksp = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(wksp)) {
90 tmin = eventWksp->getEventXMin();
92 tmin = wksp->getXMin();
94 }
else if (findTmax) {
95 if (
const auto eventWksp = std::dynamic_pointer_cast<const DataObjects::EventWorkspace>(wksp)) {
96 tmax = eventWksp->getEventXMax();
98 tmax = wksp->getXMax();
103 addTimer(
"getTofRange", timerStart, std::chrono::high_resolution_clock::now());
112 throw std::runtime_error(
"Failed to specify \'Width\' parameter");
120 if (this->
isEmpty(frequency)) {
122 if (this->
isEmpty(frequency)) {
123 throw std::runtime_error(
"Failed to determine the frequency");
127 double period = 1000000. / frequency;
133 g_log.
information() <<
"Data tmin=" << tmin <<
", tmax=" << tmax <<
", period=" << period <<
" microseconds\n";
137 if (pulseTimes.empty()) {
138 g_log.
notice() <<
"Not applying filter since prompt pulse is not in data "
141 setProperty(
"OutputWorkspace", std::const_pointer_cast<MatrixWorkspace>(inputWS));
145 for (
double pulseTime : pulseTimes)
152 for (
const double &pulseTime : pulseTimes) {
153 const double right = pulseTime + width;
155 g_log.
notice() <<
"Filtering tmin=" << pulseTime <<
", tmax=" <<
right <<
" microseconds\n";
159 algo->setProperty<
MatrixWorkspace_sptr>(
"InputWorkspace", std::const_pointer_cast<MatrixWorkspace>(outputWS));
161 algo->setProperty<
MatrixWorkspace_sptr>(
"InputWorkspace", std::const_pointer_cast<MatrixWorkspace>(inputWS));
166 algo->setProperty<
double>(
"XMin", pulseTime);
167 algo->setProperty<
double>(
"XMax",
right);
168 algo->executeAsChildAlg();
171 outputWS = algo->getProperty(
"OutputWorkspace");
181 if (!(this->
isEmpty(candidate)))
185 if (!(this->
isEmpty(candidate)))
189 if (!(this->
isEmpty(candidate)))
206 const double width) {
207 std::vector<double> times;
210 if (tmin > 0 && tmin < width)
211 times.emplace_back(time);
217 while (time < tmax) {
218 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(const vector< TYPE > &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.