-
Notifications
You must be signed in to change notification settings - Fork 121
/
CopyDetectorMapping.cpp
70 lines (53 loc) · 2.61 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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/CopyDetectorMapping.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/SpectrumDetectorMapping.h"
namespace Mantid::Algorithms {
DECLARE_ALGORITHM(CopyDetectorMapping)
using namespace Kernel;
using namespace API;
void CopyDetectorMapping::init() {
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("WorkspaceToMatch", "", Direction::Input));
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("WorkspaceToRemap", "", Direction::InOut));
declareProperty(std::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, 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 Mantid::Algorithms