Mantid
Loading...
Searching...
No Matches
CalibrationHelpers.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 +
10
11using namespace Mantid::API;
12using namespace Mantid::Geometry;
13using namespace Mantid::Kernel;
14
25void adjustUpSampleAndSourcePositions(const double L0, const V3D &newSampPos, ComponentInfo &componentInfo) {
26
27 if (L0 <= 0)
28 throw std::runtime_error("L0 is negative, must be positive.");
29
30 const V3D &oldSourceToSampleDir = componentInfo.samplePosition() - componentInfo.sourcePosition();
31 const double oldL1 = componentInfo.l1();
32
33 V3D samplePos = componentInfo.samplePosition();
34 if (samplePos != newSampPos) {
35 componentInfo.setPosition(componentInfo.sample(), newSampPos);
36 }
37
38 double scalee = L0 / oldL1;
39 V3D newSourcePos = newSampPos - oldSourceToSampleDir * scalee;
40
41 componentInfo.setPosition(componentInfo.source(), newSourcePos);
42}
43
59void adjustBankPositionsAndSizes(const std::vector<std::string> &bankNames, const V3D &pos, const Quat &rot,
60 const double detWScale, const double detHtScale, ComponentInfo &componentInfo) {
61 for (const auto &bankName : bankNames) {
62 const size_t bankComponentIndex = componentInfo.indexOfAny(bankName);
63 const size_t parentIndex = componentInfo.parent(bankComponentIndex);
64
65 Quat relRot = componentInfo.relativeRotation(bankComponentIndex);
66 Quat parentRot = componentInfo.rotation(parentIndex);
67 Quat newRot = parentRot * rot * relRot;
68
69 componentInfo.setRotation(bankComponentIndex, newRot);
70
71 V3D rotatedPos = V3D(pos);
72 parentRot.rotate(rotatedPos);
73
74 componentInfo.setPosition(bankComponentIndex, rotatedPos + componentInfo.position(bankComponentIndex));
75
76 std::vector<double> oldScalex = componentInfo.getNumberParameter(bankComponentIndex, "scalex", false);
77 std::vector<double> oldScaley = componentInfo.getNumberParameter(bankComponentIndex, "scaley", false);
78
79 double scalex, scaley;
80 if (!oldScalex.empty())
81 scalex = oldScalex[0] * detWScale;
82 else
83 scalex = detWScale;
84
85 if (!oldScaley.empty())
86 scaley = oldScaley[0] * detHtScale;
87 else
88 scaley = detHtScale;
89
90 componentInfo.addDouble(bankComponentIndex, "scalex", scalex);
91 componentInfo.addDouble(bankComponentIndex, "scaley", scaley);
92
93 if (detWScale != 1.0 || detHtScale != 1.0)
94 applyRectangularDetectorScaleToComponentInfo(componentInfo, bankComponentIndex, detWScale, detHtScale);
95 }
96}
97
98} // namespace Mantid::Crystal::CalibrationHelpers
ComponentInfo : Provides a component centric view on to the instrument.
size_t indexOfAny(const std::string &name) const
The first component with this name in a breadth-first search, as Instrument::getComponentByName() fin...
void setRotation(size_t componentIndex, const Kernel::Quat &newRotation)
size_t parent(const size_t componentIndex) const
Kernel::Quat rotation(const size_t componentIndex) const
Kernel::V3D position(const size_t componentIndex) const
std::vector< double > getNumberParameter(const size_t componentIndex, const std::string &name, bool recursive=true) const
Kernel::Quat relativeRotation(const size_t componentIndex) const
void setPosition(size_t componentIndex, const Kernel::V3D &newPosition)
void addDouble(const size_t componentIndex, const std::string &name, double value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add or replace a named double parameter at a specific component index.
Class for quaternions.
Definition Quat.h:38
void rotate(V3D &) const
Rotate a vector.
Definition Quat.cpp:397
Class for 3D vectors.
Definition V3D.h:35
MANTID_API_DLL void applyRectangularDetectorScaleToComponentInfo(Geometry::ComponentInfo &componentInfo, const size_t componentIndex, const double scaleX, const double scaleY)
Helpers for resizing RectangularDetectors.
CalibrationHelpers : This contains helper methods to move source, sample and detector positions/rotat...
MANTID_CRYSTAL_DLL void adjustUpSampleAndSourcePositions(double const L0, const Kernel::V3D &newSampPos, Geometry::ComponentInfo &componentInfo)
Updates the ComponentInfo for the workspace containing newInstrument to reflect the position of the s...
MANTID_CRYSTAL_DLL void adjustBankPositionsAndSizes(const std::vector< std::string > &bankNames, const Kernel::V3D &pos, const Kernel::Quat &rot, const double detWScale, const double detHtScale, Geometry::ComponentInfo &componentInfo)
Updates ComponentInfo to reflect the changes in the associated panel information.
adjust instrument component position and orientation
: detector size scale at y-direction