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 +
11
12using namespace Mantid::API;
13using namespace Mantid::Geometry;
14using namespace Mantid::Kernel;
15
26void adjustUpSampleAndSourcePositions(const double L0, const V3D &newSampPos, ComponentInfo &componentInfo) {
27
28 if (L0 <= 0)
29 throw std::runtime_error("L0 is negative, must be positive.");
30
31 const V3D &oldSourceToSampleDir = componentInfo.samplePosition() - componentInfo.sourcePosition();
32 const double oldL1 = componentInfo.l1();
33
34 V3D samplePos = componentInfo.samplePosition();
35 if (samplePos != newSampPos) {
36 componentInfo.setPosition(componentInfo.sample(), newSampPos);
37 }
38
39 double scalee = L0 / oldL1;
40 V3D newSourcePos = newSampPos - oldSourceToSampleDir * scalee;
41
42 componentInfo.setPosition(componentInfo.source(), newSourcePos);
43}
44
63void adjustBankPositionsAndSizes(const std::vector<std::string> &bankNames, const Instrument &newInstrument,
64 const V3D &pos, const Quat &rot, const double detWScale, const double detHtScale,
65 ComponentInfo &componentInfo) {
66 std::shared_ptr<ParameterMap> pmap = newInstrument.getParameterMap();
67
68 for (const auto &bankName : bankNames) {
69 const size_t bankComponentIndex = componentInfo.indexOfAny(bankName);
70 const size_t parentIndex = componentInfo.parent(bankComponentIndex);
71
72 Quat relRot = componentInfo.relativeRotation(bankComponentIndex);
73 Quat parentRot = componentInfo.rotation(parentIndex);
74 Quat newRot = parentRot * rot * relRot;
75
76 componentInfo.setRotation(bankComponentIndex, newRot);
77
78 V3D rotatedPos = V3D(pos);
79 parentRot.rotate(rotatedPos);
80
81 componentInfo.setPosition(bankComponentIndex, rotatedPos + componentInfo.position(bankComponentIndex));
82
83 const std::string &resolvedBankName = componentInfo.name(bankComponentIndex);
84 std::vector<double> oldScalex = pmap->getDouble(resolvedBankName, std::string("scalex"));
85 std::vector<double> oldScaley = pmap->getDouble(resolvedBankName, std::string("scaley"));
86
87 double scalex, scaley;
88 if (!oldScalex.empty())
89 scalex = oldScalex[0] * detWScale;
90 else
91 scalex = detWScale;
92
93 if (!oldScaley.empty())
94 scaley = oldScaley[0] * detHtScale;
95 else
96 scaley = detHtScale;
97
98 auto *bankComponentID = const_cast<IComponent *>(componentInfo.componentID(bankComponentIndex));
99 pmap->addDouble(bankComponentID, std::string("scalex"), scalex);
100 pmap->addDouble(bankComponentID, std::string("scaley"), scaley);
101
102 if (detWScale != 1.0 || detHtScale != 1.0)
103 applyRectangularDetectorScaleToComponentInfo(componentInfo, bankComponentID, detWScale, detHtScale);
104 }
105}
106
107} // namespace Mantid::Crystal::CalibrationHelpers
ComponentInfo : Provides a component centric view on to the instrument.
size_t indexOfAny(const std::string &name) const
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
const IComponent * componentID(const size_t componentIndex) const
const std::string & name(const size_t componentIndex) const
Kernel::Quat relativeRotation(const size_t componentIndex) const
void setPosition(size_t componentIndex, const Kernel::V3D &newPosition)
base class for Geometric IComponent
Definition IComponent.h:53
Base Instrument Class.
Definition Instrument.h:49
std::shared_ptr< ParameterMap > getParameterMap() const
Pointer to the NOT const ParameterMap holding the parameters of the modified instrument components.
Class for quaternions.
Definition Quat.h:39
void rotate(V3D &) const
Rotate a vector.
Definition Quat.cpp:397
Class for 3D vectors.
Definition V3D.h:34
MANTID_API_DLL void applyRectangularDetectorScaleToComponentInfo(Geometry::ComponentInfo &componentInfo, Geometry::IComponent *componentId, 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 Geometry::Instrument &newInstrument, const Kernel::V3D &pos, const Kernel::Quat &rot, const double detWScale, const double detHtScale, Geometry::ComponentInfo &componentInfo)
Updates ComponentInfo for newInstrument to reflect the changes in the associated panel information.
Generate a tableworkspace to store the calibration results.
adjust instrument component position and orientation
: detector size scale at y-direction