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 std::shared_ptr<const IComponent> bank1 = newInstrument.getComponentByName(bankName);
70 std::shared_ptr<const Geometry::RectangularDetector> bank =
71 std::dynamic_pointer_cast<const RectangularDetector>(bank1);
72
73 Quat relRot = bank->getRelativeRot();
74 Quat parentRot = bank->getParent()->getRotation();
75 Quat newRot = parentRot * rot * relRot;
76
77 const auto bankComponentIndex = componentInfo.indexOf(bank->getComponentID());
78 componentInfo.setRotation(bankComponentIndex, newRot);
79
80 V3D rotatedPos = V3D(pos);
81 bank->getParent()->getRotation().rotate(rotatedPos);
82
83 componentInfo.setPosition(bankComponentIndex, rotatedPos + bank->getPos());
84
85 std::vector<double> oldScalex = pmap->getDouble(bank->getName(), std::string("scalex"));
86 std::vector<double> oldScaley = pmap->getDouble(bank->getName(), std::string("scaley"));
87
88 double scalex, scaley;
89 if (!oldScalex.empty())
90 scalex = oldScalex[0] * detWScale;
91 else
92 scalex = detWScale;
93
94 if (!oldScaley.empty())
95 scaley = oldScaley[0] * detHtScale;
96 else
97 scaley = detHtScale;
98
99 pmap->addDouble(bank.get(), std::string("scalex"), scalex);
100 pmap->addDouble(bank.get(), std::string("scaley"), scaley);
101
102 if (detWScale != 1.0 || detHtScale != 1.0)
103 applyRectangularDetectorScaleToComponentInfo(componentInfo, bank->getComponentID(), detWScale, detHtScale);
104 }
105}
106
107} // namespace Mantid::Crystal::CalibrationHelpers
std::shared_ptr< const IComponent > getComponentByName(const std::string &cname, int nlevels=0) const override
Returns a pointer to the first component of assembly encountered with the given name.
ComponentInfo : Provides a component centric view on to the instrument.
Definition: ComponentInfo.h:40
void setRotation(size_t componentIndex, const Kernel::Quat &newRotation)
size_t indexOf(Geometry::IComponent *id) const
Kernel::V3D sourcePosition() const
void setPosition(size_t componentIndex, const Kernel::V3D &newPosition)
Kernel::V3D samplePosition() const
Base Instrument Class.
Definition: Instrument.h:47
std::shared_ptr< ParameterMap > getParameterMap() const
Pointer to the NOT const ParameterMap holding the parameters of the modified instrument components.
Definition: Instrument.cpp:137
Class for quaternions.
Definition: Quat.h:39
std::vector< double > getRotation(bool check_normalisation=false, bool throw_on_errors=false) const
returns the rotation matrix defined by this quaternion as an 9-point
Definition: Quat.cpp:453
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