Newer
Older
#include "MantidAlgorithms/ChangeBinOffset.h"
Federico Montesino Pouzols
committed
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAlgorithms/EventWorkspaceAccess.h"
#include "MantidAlgorithms/MatrixWorkspaceAccess.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/BoundedValidator.h"
namespace Mantid {
namespace Algorithms {
using namespace Kernel;
using namespace API;
using namespace DataObjects;
// Register the class into the algorithm factory
DECLARE_ALGORITHM(ChangeBinOffset)
void ChangeBinOffset::init() {
declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>(
"InputWorkspace", "", Direction::Input),
declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>(
"OutputWorkspace", "", Direction::Output),
"Name of the output workspace");
auto isDouble = boost::make_shared<BoundedValidator<double>>();
declareProperty("Offset", 0.0, isDouble,
"The amount to change each time bin by");
declareWorkspaceIndexSetProperties();
}
void ChangeBinOffset::exec() {
const MatrixWorkspace_sptr inputW = getProperty("InputWorkspace");
MatrixWorkspace_sptr outputW = getProperty("OutputWorkspace");
if (outputW != inputW) {
setProperty("OutputWorkspace", outputW);
}
double offset = getProperty("Offset");
EventWorkspace_sptr eventWS =
boost::dynamic_pointer_cast<EventWorkspace>(outputW);
if (eventWS) {
this->for_each<Indices::FromProperty>(
*eventWS, std::make_tuple(EventWorkspaceAccess::eventList),
[=](EventList &eventList) { eventList.addTof(offset); });
this->for_each<Indices::FromProperty>(
*outputW, std::make_tuple(MatrixWorkspaceAccess::x),
[=](std::vector<double> &dataX) {
for (auto &x : dataX)
x += offset;
});
} // namespace Mantid