24#include "MantidTypes/SpectrumDefinition.h"
32using namespace Kernel;
41ConvertToYSpace::ConvertToYSpace()
42 :
Algorithm(), m_inputWS(), m_mass(0.0), m_l1(0.0), m_samplePos(), m_outputWS(), m_qOutputWS() {}
45const std::string ConvertToYSpace::name()
const {
return "ConvertToYSpace"; }
48int ConvertToYSpace::version()
const {
return 1; }
51const std::string ConvertToYSpace::category()
const {
return "Transforms\\Units"; }
59 auto inst = ws->getInstrument();
60 auto sample = inst->getSample();
61 auto source = inst->getSource();
62 if (!sample || !source) {
63 throw std::invalid_argument(
"ConvertToYSpace - Workspace has no source/sample.");
66 const auto &spectrumInfo = ws->spectrumInfo();
67 if (!spectrumInfo.hasDetectors(
index))
68 throw std::invalid_argument(
"ConvertToYSpace - Workspace has no detector "
69 "attached to histogram at index " +
73 const auto &componentInfo = ws->componentInfo();
74 const auto &spectrumDefinition = spectrumInfo.spectrumDefinition(
index);
75 detpar.
l1 = spectrumInfo.l1();
76 detpar.
l2 = spectrumInfo.l2(
index);
77 detpar.
pos = spectrumInfo.position(
index);
94 const std::string &
name) {
98 for (
const auto &det :
group->getDetectors()) {
99 auto param =
pmap.getRecursive(det->getComponentID(),
name);
101 avg += param->value<
double>();
103 throw std::invalid_argument(
"ComptonProfile - Unable to find "
104 "DetectorGroup component parameter \"" +
107 result = avg /
static_cast<double>(
group->nDets());
111 result = param->value<
double>();
113 throw std::invalid_argument(
"ComptonProfile - Unable to find component parameter \"" +
name +
"\".");
129 const SpectrumDefinition &spectrumDefinition,
const std::string &
name) {
130 const bool isGroup = spectrumDefinition.size() > 1;
132 for (
const auto &specDefItem : spectrumDefinition) {
135 sum += values.front();
137 throw std::invalid_argument(
"ComptonProfile - Unable to find "
138 "DetectorGroup component parameter \"" +
141 throw std::invalid_argument(
"ComptonProfile - Unable to find component parameter \"" +
name +
"\".");
143 return sum /
static_cast<double>(spectrumDefinition.size());
160void ConvertToYSpace::calculateY(
double &yspace,
double &qspace,
double &ei,
const double mass,
const double tsec,
162 const double v0 = detpar.
l1 / (tsec - detpar.
t0 - (detpar.
l2 / v1));
163 ei = MASS_TO_MEV * v0 * v0;
164 const double w = ei - detpar.
efixed;
166 qspace = std::sqrt(k0 * k0 + k1 * k1 - 2.0 * k0 * k1 * std::cos(detpar.
theta));
168 yspace = 0.2393 * (mass / qspace) * (w - wreduced);
175void ConvertToYSpace::init() {
176 auto wsValidator = std::make_shared<CompositeValidator>();
181 "The input workspace in Time of Flight");
183 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
184 mustBePositive->setLower(0.0);
185 mustBePositive->setLowerExclusive(
true);
186 declareProperty(
"Mass", -1.0, mustBePositive,
"The mass defining the recoil peak in AMU");
189 "The output workspace in y-Space");
192 "The output workspace in q-Space");
199void ConvertToYSpace::exec() {
203 const auto nhist =
static_cast<int64_t
>(
m_inputWS->getNumberHistograms());
204 const int64_t nreports = nhist;
205 auto progress = std::make_shared<Progress>(
this, 0.0, 1.0, nreports);
207 auto &spectrumInfo =
m_outputWS->mutableSpectrumInfo();
210 qSpectrumInfo = &
m_qOutputWS->mutableSpectrumInfo();
213 for (int64_t i = 0; i < nhist; ++i) {
220 spectrumInfo.setMasked(i,
true);
223 qSpectrumInfo->setMasked(i,
true);
244bool ConvertToYSpace::convert(
const size_t index) {
247 const double v1 = std::sqrt(detPar.
efixed / MASS_TO_MEV);
259 const size_t npts = inY.size();
260 for (
size_t j = 0; j < npts; ++j) {
261 double ys(0.0), qs(0.0), ei(0.0);
263 const size_t outIndex = (npts - j - 1);
265 const double prefactor = qs / pow(ei, 0.1);
266 outY[outIndex] = prefactor * inY[j];
267 outE[outIndex] = prefactor * inE[j];
283void ConvertToYSpace::retrieveInputs() {
292void ConvertToYSpace::createOutputWorkspace() {
296 auto xLabel = std::make_shared<Units::Label>(
"Momentum",
"A^-1");
311void ConvertToYSpace::cacheInstrumentGeometry() {
313 auto source = inst->getSource();
314 auto sample = inst->getSample();
315 m_l1 = sample->getDistance(*source);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_CRITICAL(name)
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A validator which checks that a workspace has a valid instrument.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
API::MatrixWorkspace_sptr m_outputWS
Output workspace.
double m_l1
Source-sample distance.
double m_mass
The input mass in AMU.
void retrieveInputs()
Check and store appropriate input data.
const std::string name() const override
Algorithm's name for identification.
void cacheInstrumentGeometry()
Compute & store the parameters that are fixed during the correction.
API::MatrixWorkspace_sptr m_qOutputWS
API::MatrixWorkspace_sptr m_inputWS
Input workspace.
static DetectorParams getDetectorParameters(const API::MatrixWorkspace_const_sptr &ws, const size_t index)
Creates a POD struct containing the required detector parameters for this spectrum.
Kernel::V3D m_samplePos
Sample position.
bool convert(const size_t index)
Perform the conversion to Y-space.
static double getComponentParameter(const Geometry::IComponent &det, const Geometry::ParameterMap &pmap, const std::string &name)
Retrieve a component parameter.
void createOutputWorkspace()
Create the output workspace.
static void calculateY(double &yspace, double &qspace, double &ei, const double mass, const double tsec, const double k1, const double v1, const DetectorParams &detpar)
Convert single time value to Y,Q & Ei values.
ComponentInfo : Provides a component centric view on to the instrument.
std::vector< double > getNumberParameter(const size_t componentIndex, const std::string &name, bool recursive=true) const
Holds a collection of detectors.
base class for Geometric IComponent
virtual ComponentID getComponentID() const =0
Returns the ComponentID - a unique identifier of the component.
Parameter map iterator typedef.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
static constexpr double E_mev_toNeutronWavenumberSq
Transformation coefficient to transform neutron energy into neutron wavevector: K-neutron[m^-10] = sq...
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.
std::string to_string(const wide_integer< Bits, Signed > &n)
Simple data structure to store nominal detector values It avoids some functions taking a huge number ...
double efixed
final energy
double theta
scattering angle in radians
double l1
source-sample distance in metres
double t0
time delay in seconds
Kernel::V3D pos
Full 3D position.
double l2
sample-detector distance in metres
@ Input
An input workspace.
@ Output
An output workspace.