Mantid
Loading...
Searching...
No Matches
ApplyCalibration.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 +
13#include "MantidKernel/Logger.h"
14
15namespace Mantid::Algorithms {
16
17namespace {
18Kernel::Logger logger("ApplyCalibration");
19}
20
21DECLARE_ALGORITHM(ApplyCalibration)
22
23using namespace Kernel;
24using namespace API;
25
28
30 "The name of the input workspace to apply the calibration to");
31
33 "CalibrationTable", "", Direction::Input, PropertyMode::Optional),
34 "The name of the table workspace containing the new "
35 "positions of detectors");
36
39 "Deprecated: Use Property 'CalibrationTable'");
40}
41
49 // Get pointers to the workspace, parameter map and table
50 API::MatrixWorkspace_sptr inputWS = getProperty("Workspace");
51 API::ITableWorkspace_sptr CalTable = getProperty("CalibrationTable");
52 API::ITableWorkspace_sptr PosTable = getProperty("PositionTable");
53
54 // Elucidate if using property PositionTable table instead of CalibrationTable
55 if (!CalTable && !PosTable) {
56 throw std::runtime_error("Either CalibrationTable or PositionTable must be supplied");
57 }
58 if (PosTable && !CalTable) {
59 logger.notice("Property 'PositionTable' has been deprecated. Please use "
60 "'CalibrationTable' in its place\n");
61 CalTable = PosTable;
62 }
63
64 // initialize variables common to all calibrations
65 std::vector<std::string> columnNames = CalTable->getColumnNames();
66 size_t numDetector = CalTable->rowCount();
67 ColumnVector<int> detectorID = CalTable->getVector("Detector ID");
68
69 // Default calibration
70 if (std::find(columnNames.begin(), columnNames.end(), "Detector Position") != columnNames.end()) {
71 auto &detectorInfo = inputWS->mutableDetectorInfo();
72 ColumnVector<V3D> detPos = CalTable->getVector("Detector Position");
73 // PARALLEL_FOR_NO_WSP_CHECK()
74 for (size_t i = 0; i < numDetector; ++i) {
75 const auto index = detectorInfo.indexOf(detectorID[i]);
76 detectorInfo.setPosition(index, detPos[i]);
77 }
78 }
79
80 // Bar scan calibration: pixel Y-coordinate
81 if (std::find(columnNames.begin(), columnNames.end(), "Detector Y Coordinate") != columnNames.end()) {
82 // the detectorInfo index of a particular pixel detector is the same as the
83 // componentInfo index for the same pixel detector
84 auto &detectorInfo = inputWS->mutableDetectorInfo();
85 ColumnVector<double> yCoordinate = CalTable->getVector("Detector Y Coordinate");
86 // PARALLEL_FOR_NO_WSP_CHECK()
87 for (size_t i = 0; i < numDetector; ++i) {
88 const auto index = detectorInfo.indexOf(detectorID[i]);
89 V3D xyz = detectorInfo.position(index);
90 detectorInfo.setPosition(index, V3D(xyz.X(), yCoordinate[i], xyz.Z()));
91 }
92 }
93
94 // Apparent tube width calibration along X-coordinate
95 if (std::find(columnNames.begin(), columnNames.end(), "Detector Width") != columnNames.end()) {
96 auto &detectorInfo = inputWS->detectorInfo();
97 auto &componentInfo = inputWS->mutableComponentInfo();
98 ColumnVector<double> widths = CalTable->getVector("Detector Width");
99 // PARALLEL_FOR_NO_WSP_CHECK()
100 for (size_t i = 0; i < numDetector; ++i) {
101 const auto index = detectorInfo.indexOf(detectorID[i]);
102 double nominalWidth = componentInfo.shape(index).getBoundingBox().width().X();
103 V3D oldScaleFactor = componentInfo.scaleFactor(index);
104 componentInfo.setScaleFactor(index, V3D(widths[i] / nominalWidth, oldScaleFactor.Y(), oldScaleFactor.Z()));
105 }
106 }
107
108 // Bar scan calibration: pixel height
109 if (std::find(columnNames.begin(), columnNames.end(), "Detector Height") != columnNames.end()) {
110 // the detectorInfo index of a particular pixel detector is the same as the
111 // componentInfo index for the same pixel detector
112 auto &detectorInfo = inputWS->mutableDetectorInfo();
113 auto &componentInfo = inputWS->mutableComponentInfo();
114 ColumnVector<double> height = CalTable->getVector("Detector Height");
115 // PARALLEL_FOR_NO_WSP_CHECK()
116 for (size_t i = 0; i < numDetector; ++i) {
117 const auto index = detectorInfo.indexOf(detectorID[i]);
118 // update pixel height along Y coordinate
119 double nominalHeight = componentInfo.shape(index).getBoundingBox().width().Y();
120 V3D oldScaleFactor = componentInfo.scaleFactor(index);
121 componentInfo.setScaleFactor(index, V3D(oldScaleFactor.X(), height[i] / nominalHeight, oldScaleFactor.Z()));
122 }
123 }
124}
125
126} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double height
Definition: GetAllEi.cpp:155
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
ColumnVector gives access to the column elements without alowing its resizing.
A property class for workspaces.
void exec() override
Overwrites Algorithm method.
void init() override
Overwrites Algorithm method. Does nothing at present.
Class for 3D vectors.
Definition: V3D.h:34
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53