Mantid
Loading...
Searching...
No Matches
ChangeBinOffset.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
13
14namespace Mantid::Algorithms {
15
16using namespace Kernel;
17using namespace API;
18using namespace DataObjects;
19
20// Register the class into the algorithm factory
21DECLARE_ALGORITHM(ChangeBinOffset)
22
23void ChangeBinOffset::init() {
24 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
25 "Name of the input workspace");
26 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
27 "Name of the output workspace");
28 auto isDouble = std::make_shared<BoundedValidator<double>>();
29 declareProperty("Offset", 0.0, isDouble, "The amount to adjust the time bins. Usually in microseconds");
30 declareWorkspaceIndexSetProperties();
31}
32
34 MatrixWorkspace_const_sptr inputW = getProperty("InputWorkspace");
35 MatrixWorkspace_sptr outputW = getProperty("OutputWorkspace");
36 if (outputW != inputW) {
37 outputW = inputW->clone();
38 setProperty("OutputWorkspace", outputW);
39 }
40
41 const double offset = getProperty("Offset");
42 EventWorkspace_sptr eventWS = std::dynamic_pointer_cast<EventWorkspace>(outputW);
43 if (eventWS) {
44 this->for_each<Indices::FromProperty>(*eventWS, std::make_tuple(EventWorkspaceAccess::eventList),
45 [offset](EventList &eventList) { eventList.addTof(offset); });
46 } else {
47 this->for_each<Indices::FromProperty>(
48 *outputW, std::make_tuple(MatrixWorkspaceAccess::x), [offset](std::vector<double> &dataX) {
49 std::transform(dataX.begin(), dataX.end(), dataX.begin(), [offset](double x) { return x + offset; });
50 });
51 }
52}
53
54} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
Takes a workspace and adjusts all the time bin values by the same amount.
void exec() override
Executes the algorithm.
A class for holding :
Definition: EventList.h:56
void addTof(const double offset) override
Add an offset to the TOF of each event in the list.
Definition: EventList.cpp:2491
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
static decltype(std::mem_fn((DataObjects::EventList &(DataObjects::EventWorkspace::*)(const std::size_t)) &DataObjects::EventWorkspace::getSpectrum)) eventList
static decltype(std::mem_fn((std::vector< double > &(API::MatrixWorkspace::*)(const std::size_t)) &API::MatrixWorkspace::dataX)) x
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54