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;
25using namespace Mantid::API;
26
27namespace Mantid::Algorithms {
28
32 : m_ws(std::move(ws)), m_spectrumInfo(m_ws->spectrumInfo()) {}
33
34Correction TimeAtSampleStrategyIndirect::calculate(const size_t &workspace_index) const {
35
36 // A constant among all spectra
37 constexpr double TWO_MEV_OVER_MASS = 2. * PhysicalConstants::meV / PhysicalConstants::NeutronMass;
38
39 const IDetector *det = &m_spectrumInfo.detector(workspace_index);
40 if (m_spectrumInfo.isMonitor(workspace_index)) {
41 // use the same math as TimeAtSampleStrategyElastic
42 const double L1s = m_spectrumInfo.l1();
43 const auto &beamDir = m_ws->getInstrument()->getReferenceFrame()->vecPointingAlongBeam();
44 const double L1m = beamDir.scalar_prod(m_spectrumInfo.sourcePosition() - m_spectrumInfo.position(workspace_index));
45 const double scale = std::abs(L1s / L1m);
46 return Correction(0., scale);
47 }
48
49 // Get E_fix
50 double efix{0.};
51 try {
52 // Get the parameter map
53 const ParameterMap &pmap = m_ws->constInstrumentParameters();
54 Parameter_sptr par = pmap.getRecursive(det, "Efixed");
55 if (par) {
56 efix = par->value<double>();
57 }
58 } catch (std::runtime_error &) {
59 // Throws if a DetectorGroup, use single provided value
60 std::stringstream errmsg;
61 errmsg << "Inelastic instrument detector " << det->getID() << " of spectrum " << workspace_index
62 << " does not have EFixed ";
63 throw std::runtime_error(errmsg.str());
64 }
65 if (efix <= 0.) {
66 std::stringstream errmsg;
67 errmsg << "Inelastic instrument detector " << det->getID() << " of spectrum " << workspace_index
68 << " does not have EFixed ";
69 throw std::runtime_error(errmsg.str());
70 }
71
72 const double l2 = m_spectrumInfo.l2(workspace_index);
73 const double shift = -1. * l2 / sqrt(efix * TWO_MEV_OVER_MASS);
74
75 // 1.0 * tof + shift
76 return Correction(shift, 1.0);
77}
78
79} // namespace Mantid::Algorithms
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.
double l1() const
Returns L1 (distance from source to sample).
std::shared_ptr< const Mantid::API::MatrixWorkspace > m_ws
Workspace to operate on.
TimeAtSampleStrategyIndirect(std::shared_ptr< const Mantid::API::MatrixWorkspace > ws)
Constructor.
Correction calculate(const size_t &workspace_index) const override
Interface class for detector objects.
Definition: IDetector.h:43
virtual detid_t getID() const =0
Get the detector ID.
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:195
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double meV
1 meV in Joules.
Generate a tableworkspace to store the calibration results.
STL namespace.
The Correction struct to be applied as factor * TOF + offset offset:: TOF offset in unit of TOF facto...