Mantid
Loading...
Searching...
No Matches
GravitySANSHelper.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
11#include <cmath>
12
13namespace Mantid::Algorithms {
14using Kernel::V3D;
15
23 const double extraLength)
24 : m_samplePos(spectrumInfo.samplePosition()), m_beamLine(m_samplePos - spectrumInfo.sourcePosition()),
25 m_beamLineNorm(2.0 * spectrumInfo.l1()), m_dropPerAngstrom2(-1), m_cachedDrop(0) {
26 // this is the LineOfSight assuming no drop, the drop is added (and
27 // subtracted) later in the code when required
29 // the drop is proportional to the wave length squared and using this to do
30 // the full calculation only once increases the speed a lot
31 m_dropPerAngstrom2 = gravitationalDrop(spectrumInfo.l2(index), 1e-10, extraLength);
32}
38double GravitySANSHelper::calcSinTheta(const double wavAngstroms) const {
39 getDetLoc(wavAngstroms);
40 return calcSinTheta();
41}
49double GravitySANSHelper::calcComponents(const double wavAngstroms, double &xFrac, double &yFrac) const {
50 const V3D &detPos = getDetLoc(wavAngstroms);
51
52 const double phi = atan2(detPos.Y(), detPos.X());
53 xFrac = cos(phi);
54 yFrac = sin(phi);
55 return calcSinTheta();
56}
63const V3D &GravitySANSHelper::getDetLoc(const double wav) const {
64 // Calculate the drop
65 const double drop = gravitationalDrop(wav);
66 // I'm fairly confident that Y is up! Using the previous drop to allow the
67 // same V3D to be modified many times
69 m_cachedDrop = drop;
70 // must return a member variable, not a local!
72}
78 // This is 0.5*cos(2theta)
80 // This is sin(theta)
81 return sqrt(0.5 - halfcosTheta);
82}
83
96double GravitySANSHelper::gravitationalDrop(const double l2, const double waveLength, const double extraLength) const {
97 using namespace PhysicalConstants;
99 static const double gm2_OVER_2h2 = g * NeutronMass * NeutronMass / (2.0 * h * h);
100
101 // Perform a path length correction if an Lextra is specified.
102 // The correction is Lcorr^2 = (L + Lextra)^2 -(LExtra)^2
103 const auto pathLengthWithExtraLength = l2 + extraLength;
104 const auto pathLengthSquared = std::pow(pathLengthWithExtraLength, 2) - std::pow(extraLength, 2);
105
106 // Want L2 (sample-pixel distance) squared, times the prefactor g^2/h^2
107 const double L2 = gm2_OVER_2h2 * pathLengthSquared;
108
109 return waveLength * waveLength * L2;
110}
111} // namespace Mantid::Algorithms
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
Definition: SpectrumInfo.h:53
Kernel::V3D position(const size_t index) const
Returns the position of the spectrum with given index.
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
double m_dropPerAngstrom2
the drop is proportional to the wavelength squared, storing this drop increases calculation speed a l...
double m_cachedDrop
the drop that was last caclulated, this allows m_cachedDetLoc to be recalculated each time without it...
Kernel::V3D m_cachedLineOfSight
the location that the neutron would have been detected at if it continued in a straight line,...
double gravitationalDrop(const double wav) const
double calcSinTheta() const
getDetLoc must have been called before this is used to calculate the sin of the angle
const Kernel::V3D & getDetLoc(const double wav) const
Finds the location of the detector the neutron would have entered if it followed a straight line path...
Kernel::V3D m_samplePos
coordinates of the sample
double m_beamLineNorm
twice the distance from the source to the sample
double calcComponents(const double wavAngstroms, double &xFrac, double &yFrac) const
Calculate the sins and cosins of angles as required to calculate Q is 2 dimensions.
Kernel::V3D m_beamLine
the displacement from the source to the sample
Class for 3D vectors.
Definition: V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
double norm() const noexcept
Definition: V3D.h:263
A namespace containing physical constants that are required by algorithms and unit routines.
Definition: Atom.h:14
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double g
Standard acceleration due to gravity.