Mantid
Loading...
Searching...
No Matches
CorelliCalibrationApply.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 +
7
17#include "MantidKernel/Logger.h"
18
19namespace Mantid::Algorithms {
20
21using namespace Kernel;
22using namespace API;
23using namespace DataObjects;
24namespace {
25Logger logger("CorelliCalibrationApply");
26}
27
28DECLARE_ALGORITHM(CorelliCalibrationApply)
29
30
35
36 // InputWorkspace
37 // [Input, Required, MatrixWorkspace or EventsWorkspace]
38 // workspace to which the calibration should be applied
39 auto wsValidator = std::make_shared<InstrumentValidator>();
40 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("Workspace", "", Direction::InOut,
41 PropertyMode::Mandatory, wsValidator),
42 "CORELLI workspace to calibrate");
43
44 // CalibrationTable
45 // [Input, Mandatory, TableWorkspace]
46 // workspace resulting from uploading
47 declareProperty(std::make_unique<WorkspaceProperty<TableWorkspace>>("CalibrationTable", "", Direction::Input,
49 "TableWorkspace containing calibration table");
50}
51
57std::map<std::string, std::string> CorelliCalibrationApply::validateInputs() {
58 std::map<std::string, std::string> issues;
59 ws = getProperty("Workspace");
60
61 // 1_check: input workspace is from CORELLI
62 if (ws->getInstrument()->getName() != "CORELLI") {
63 issues["Workspace"] = "CORELLI only algorithm, aborting";
64 }
65
66 // 2_check: headers of calibration table
67 calTable = getProperty("CalibrationTable");
69 std::vector<std::string> colnames = calTable->getColumnNames();
70 if (colnames.size() != refCalTableHeader.size()) {
71 issues["CalibrationTable"] = "Headers of input calibration table does not match required";
72 }
73 for (size_t i = 0; i < colnames.size(); i++) {
74 if (colnames[i] != refCalTableHeader[i]) {
75 issues["CalibrationTable"] = "Header mismatch at " + std::to_string(i);
76 break;
77 }
78 }
79
80 return issues;
81}
82
88 g_log.notice() << "Start applying CORELLI calibration\n";
89
90 // Parse input arguments
91 ws = getProperty("Workspace");
92 auto wsName = ws->getName();
93
94 calTable = getProperty("CalibrationTable");
95 const auto componentNames = calTable->getColumn(0);
96 const auto x_poss = calTable->getColumn(1);
97 const auto y_poss = calTable->getColumn(2);
98 const auto z_poss = calTable->getColumn(3);
99 const auto rotxs = calTable->getColumn(4);
100 const auto rotys = calTable->getColumn(5);
101 const auto rotzs = calTable->getColumn(6);
102 const auto rotangs = calTable->getColumn(7); // unit: degrees
103
117 g_log.notice() << "Translating each component using given Calibration table";
118 auto moveAlg = createChildAlgorithm("MoveInstrumentComponent");
119 moveAlg->initialize();
120 moveAlg->setProperty("Workspace", wsName);
121 for (size_t row_num = 0; row_num < calTable->rowCount(); row_num++) {
122 moveAlg->setProperty("ComponentName", componentNames->cell<std::string>(row_num));
123 moveAlg->setProperty("X", x_poss->cell<double>(row_num));
124 moveAlg->setProperty("Y", y_poss->cell<double>(row_num));
125 moveAlg->setProperty("Z", z_poss->cell<double>(row_num));
126 // [IMPORTANT]
127 // The position data from calibration table are ABSOLUTE values (lab frame)
128 moveAlg->setProperty("RelativePosition", false);
129 moveAlg->execute();
130 }
131
157 g_log.notice() << "Rotating each component using given Calibration table";
158 auto rotateAlg = createChildAlgorithm("RotateInstrumentComponent");
159 rotateAlg->initialize();
160 rotateAlg->setProperty("Workspace", wsName);
161 for (size_t row_num = 0; row_num < calTable->rowCount(); row_num++) {
162 if (std::abs(rotangs->cell<double>(row_num)) < 1e-8) {
163 continue;
164 }
165 rotateAlg->setProperty("ComponentName", componentNames->cell<std::string>(row_num));
166 rotateAlg->setProperty("X", rotxs->cell<double>(row_num));
167 rotateAlg->setProperty("Y", rotys->cell<double>(row_num));
168 rotateAlg->setProperty("Z", rotzs->cell<double>(row_num));
169 rotateAlg->setProperty("Angle", rotangs->cell<double>(row_num));
170 // [IMPORTANT]
171 // The rotation required here has to be the RELATIVE rotation angle in
172 // degrees
173 rotateAlg->setProperty("RelativeRotation", false);
174 rotateAlg->execute();
175 }
176
177 // Config output
178 setProperty("Workspace", ws);
179
180 g_log.notice() << "Finished applying CORELLI calibration\n";
181}
182
183} // 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
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
Kernel::Logger & g_log
Definition: Algorithm.h:451
A property class for workspaces.
Apply calibration table for Corelli Powder Diffraction.
std::map< std::string, std::string > validateInputs() override
Private validator for inputs.
void exec() override
Overwrites Algorithm method.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
static const std::vector< std::string > calibrationTableColumnNames
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53