24using Types::Core::DateAndTime;
36 :
m_offSet(static_cast<double>(offSet.totalNanoseconds()) * 1e-9) {}
37 MantidVec::value_type
operator()(
const MantidVec::value_type &absTNanoSec) {
return (absTNanoSec * 1e-9) -
m_offSet; }
45 "An input workspace containing TOF events.");
48 "A comma separated list of first bin boundary, width, last "
49 "bin boundary. Optionally\n"
50 "this can be followed by a comma and more widths and last "
51 "boundary pairs. Values are in seconds since run start.");
55 "An output workspace.");
65 if (!std::dynamic_pointer_cast<EventWorkspace>(inWS)) {
66 const std::string algName = this->
name();
67 throw std::invalid_argument(algName +
" Algorithm requires an EventWorkspace as an input.");
71 const std::vector<double> inParams =
getProperty(
"Params");
72 std::vector<double> rebinningParams;
75 const auto histnumber =
static_cast<int>(inWS->getNumberHistograms());
77 const auto nanoSecondsInASecond =
static_cast<uint64_t
>(1e9);
78 const DateAndTime runStartTime = inWS->run().startTime();
82 if (inParams.size() >= 3) {
85 const DateAndTime startTime = runStartTime + inParams[0];
86 const DateAndTime endTime = runStartTime + inParams[2];
88 rebinningParams.emplace_back(
static_cast<double>(startTime.totalNanoseconds()));
89 tStep = inParams[1] * nanoSecondsInASecond;
90 rebinningParams.emplace_back(tStep);
91 rebinningParams.emplace_back(
static_cast<double>(endTime.totalNanoseconds()));
92 }
else if (inParams.size() == 1) {
93 const uint64_t xmin =
getMinX(inWS);
94 const uint64_t xmax =
getMaxX(inWS);
96 rebinningParams.emplace_back(
static_cast<double>(xmin));
97 tStep = inParams[0] * nanoSecondsInASecond;
98 rebinningParams.emplace_back(tStep);
99 rebinningParams.emplace_back(
static_cast<double>(xmax));
104 throw std::invalid_argument(
"Cannot have a timestep less than or equal to zero.");
108 Progress prog(
this, 0.0, 1.0, histnumber);
117 MantidVec OutXValues_scaled(XValues_new->size());
118 std::transform(XValues_new->begin(), XValues_new->end(), OutXValues_scaled.begin(), transformToRelativeT);
121 DataObjects::create<DataObjects::Workspace2D>(*inWS, histnumber, HistogramData::BinEdges(*XValues_new));
124 for (
int i = 1; i < inWS->axes(); i++) {
125 outputWS->replaceAxis(i, std::unique_ptr<Axis>(inWS->getAxis(i)->clone(outputWS.get())));
126 outputWS->getAxis(i)->unit() = inWS->getAxis(i)->unit();
130 outputWS->getAxis(0)->unit() = std::make_shared<Units::Time>();
133 for (
int i = 1; i < outputWS->axes(); ++i) {
134 outputWS->getAxis(i)->unit() = inWS->getAxis(i)->unit();
136 outputWS->setYUnit(inWS->YUnit());
137 outputWS->setYUnitLabel(inWS->YUnitLabel());
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.
const std::string name() const override=0
function to return a name of the algorithm, must be overridden in all algorithms
Helper class for reporting progress from algorithms.
A property class for workspaces.
Helper method to transform a MantidVector containing absolute times in nanoseconds to relative times ...
MantidVec::value_type operator()(const MantidVec::value_type &absTNanoSec)
ConvertToRelativeTime(const DateAndTime &offSet)
void exec() override
execute.
void init() override
Initialization method.
virtual void doHistogramming(Mantid::API::IEventWorkspace_sptr inWS, Mantid::API::MatrixWorkspace_sptr outputWS, Mantid::MantidVecPtr &XValues_new, Mantid::MantidVec &OutXValues_scaled, Mantid::API::Progress &prog)=0
Do the algorithm specific histogramming.
virtual uint64_t getMinX(Mantid::API::IEventWorkspace_sptr ws) const =0
Get the maximum x across all spectra in workspace.
virtual uint64_t getMaxX(Mantid::API::IEventWorkspace_sptr ws) const =0
Get the minimum x across all spectra in workspace.
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Implements a copy on write data template.
DataType & access()
Access function.
std::shared_ptr< IEventWorkspace > IEventWorkspace_sptr
shared pointer to Mantid::API::IEventWorkspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
int MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
@ Input
An input workspace.
@ Output
An output workspace.