-
Notifications
You must be signed in to change notification settings - Fork 122
/
ChangeBinOffset.cpp
58 lines (50 loc) · 1.92 KB
/
ChangeBinOffset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "MantidAlgorithms/ChangeBinOffset.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidAlgorithms/MatrixWorkspaceAccess.h"
#include "MantidAlgorithms/EventWorkspaceAccess.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),
"Name of the input workspace");
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) {
outputW = inputW->clone();
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); });
} else {
this->for_each<Indices::FromProperty>(
*outputW, std::make_tuple(MatrixWorkspaceAccess::x),
[=](std::vector<double> &dataX) {
for (auto &x : dataX)
x += offset;
});
}
}
} // namespace Algorithm
} // namespace Mantid