-
Notifications
You must be signed in to change notification settings - Fork 122
/
CopyDetectorMapping.cpp
72 lines (55 loc) · 2.36 KB
/
CopyDetectorMapping.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/CopyDetectorMapping.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/SpectrumDetectorMapping.h"
namespace Mantid {
namespace Algorithms {
DECLARE_ALGORITHM(CopyDetectorMapping)
using namespace Kernel;
using namespace API;
void CopyDetectorMapping::init() {
declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>(
"WorkspaceToMatch", "", Direction::Input));
declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>(
"WorkspaceToRemap", "", Direction::InOut));
declareProperty(
make_unique<PropertyWithValue<bool>>("IndexBySpectrumNumber", false,
Direction::Input),
"Will use mapping indexed by spectrum number rather than the default of"
"Workspace Index (recommended when both workspaces have a vertical axis "
"in spectrum number).");
}
void CopyDetectorMapping::exec() {
MatrixWorkspace_const_sptr wsToMatch = getProperty("WorkspaceToMatch");
MatrixWorkspace_sptr wsToRemap = getProperty("WorkspaceToRemap");
bool indexBySpecNumber = getProperty("IndexBySpectrumNumber");
// Copy detector mapping
SpectrumDetectorMapping detMap(wsToMatch.get(), indexBySpecNumber);
wsToRemap->updateSpectraUsing(detMap);
setProperty("WorkspaceToRemap", wsToRemap);
}
std::map<std::string, std::string> CopyDetectorMapping::validateInputs() {
std::map<std::string, std::string> issues;
MatrixWorkspace_sptr wsToMatch = getProperty("WorkspaceToMatch");
MatrixWorkspace_sptr wsToRemap = getProperty("WorkspaceToRemap");
// Check that the workspaces actually are MatrixWorkspaces
bool validWorkspaces = true;
if (wsToMatch == nullptr) {
issues["WorkspaceToMatch"] = "Must be a MatrixWorkspace";
validWorkspaces = false;
}
if (wsToRemap == nullptr) {
issues["WorkspaceToRemap"] = "Must be a MatrixWorkspace";
validWorkspaces = false;
}
// Check histohram counts match (assuming both are MatrixWorkspaces)
if (validWorkspaces &&
wsToMatch->getNumberHistograms() != wsToRemap->getNumberHistograms())
issues["WorkspaceToRemap"] =
"Number of histograms must match WorkspaceToMatch";
return issues;
}
} // namespace Algorithms
} // namespace Mantid