Mantid
Loading...
Searching...
No Matches
TimeAtSampleStrategyIndirect.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 +
15#include "MantidKernel/Logger.h"
17#include "MantidKernel/V3D.h"
18#include <cmath>
19#include <memory>
20#include <sstream>
21#include <utility>
22
23using namespace Mantid::Kernel;
24using namespace Mantid::Geometry;
25
26namespace Mantid::API {
27
31 : m_spectrumInfo(ws->spectrumInfo()), m_L1s(m_spectrumInfo.l1()),
32 m_beamDir(ws->getInstrument()->getReferenceFrame()->vecPointingAlongBeam()),
33 m_paramMap(ws->constInstrumentParameters()) {}
34
38double TimeAtSampleStrategyIndirect::getEfixed(const size_t &workspace_index) const {
39 const IDetector *det = &m_spectrumInfo.detector(workspace_index);
40
41 double efixed{0.};
42 try {
43 // Get the parameter map
44 Parameter_sptr par = m_paramMap.getRecursive(det, "Efixed");
45 if (par) {
46 efixed = par->value<double>();
47 }
48 } catch (std::runtime_error &) {
49 // Throws if a DetectorGroup, use single provided value
50 std::stringstream errmsg;
51 errmsg << "Inelastic instrument detector " << det->getID() << " of spectrum " << workspace_index
52 << " does not have EFixed ";
53 throw std::runtime_error(errmsg.str());
54 }
55 if (efixed <= 0.) {
56 std::stringstream errmsg;
57 errmsg << "Inelastic instrument detector " << det->getID() << " of spectrum " << workspace_index
58 << " does not have EFixed ";
59 throw std::runtime_error(errmsg.str());
60 }
61
62 return efixed;
63}
64
65Correction TimeAtSampleStrategyIndirect::calculate(const size_t &workspace_index) const {
66
67 // A constant among all spectra
68 constexpr double TWO_MEV_OVER_MASS = 2. * PhysicalConstants::meV / PhysicalConstants::NeutronMass;
69
70 if (m_spectrumInfo.isMonitor(workspace_index)) {
71 // use the same math as TimeAtSampleStrategyElastic
72 const double L1m =
74 const double scale = std::abs(m_L1s / L1m);
75 return Correction(scale, 0.);
76 } else {
77 const double efix = this->getEfixed(workspace_index);
78 const double l2 = m_spectrumInfo.l2(workspace_index);
79 const double shift = -1. * l2 / sqrt(efix * TWO_MEV_OVER_MASS);
80
81 // 1.0 * tof + shift
82 constexpr double NO_MULTIPLY_TOF{1.};
83 return Correction(NO_MULTIPLY_TOF, shift);
84 }
85}
86
87} // namespace Mantid::API
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
Kernel::V3D sourcePosition() const
Returns the source position.
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).
const Geometry::IDetector & detector(const size_t index) const
Return a const reference to the detector or detector group of the spectrum with given index.
Correction calculate(const size_t &workspace_index) const override
double getEfixed(const size_t &workspace_index) const
This will throw an exception if efixed is not found or negative.
TimeAtSampleStrategyIndirect(std::shared_ptr< const Mantid::API::MatrixWorkspace > ws)
Constructor.
Interface class for detector objects.
Definition IDetector.h:43
virtual detid_t getID() const =0
Get the detector ID.
std::shared_ptr< Parameter > getRecursive(const IComponent *comp, const std::string &name, const std::string &type="") const
Use get() recursively to see if can find param in all parents of comp and given type (std::string ver...
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition V3D.h:280
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
Definition Parameter.h:194
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double meV
1 meV in Joules.
The Correction struct to be applied as factor * TOF + offset multiplicativeFactor: TOF correction fac...