29using namespace Kernel;
38ConvertToYSpace::ConvertToYSpace()
39 :
Algorithm(), m_inputWS(), m_mass(0.0), m_l1(0.0), m_samplePos(), m_outputWS(), m_qOutputWS() {}
42const std::string ConvertToYSpace::name()
const {
return "ConvertToYSpace"; }
45int ConvertToYSpace::version()
const {
return 1; }
48const std::string ConvertToYSpace::category()
const {
return "Transforms\\Units"; }
56 auto inst = ws->getInstrument();
57 auto sample = inst->getSample();
58 auto source = inst->getSource();
59 if (!sample || !source) {
60 throw std::invalid_argument(
"ConvertToYSpace - Workspace has no source/sample.");
63 const auto &spectrumInfo = ws->spectrumInfo();
64 if (!spectrumInfo.hasDetectors(
index))
65 throw std::invalid_argument(
"ConvertToYSpace - Workspace has no detector "
66 "attached to histogram at index " +
70 const auto &
pmap = ws->constInstrumentParameters();
71 const auto &det = spectrumInfo.detector(
index);
72 detpar.
l1 = spectrumInfo.l1();
73 detpar.
l2 = spectrumInfo.l2(
index);
74 detpar.
pos = spectrumInfo.position(
index);
91 const std::string &name) {
95 for (
const auto &det : group->getDetectors()) {
96 auto param =
pmap.getRecursive(det->getComponentID(),
name);
98 avg += param->value<
double>();
100 throw std::invalid_argument(
"ComptonProfile - Unable to find "
101 "DetectorGroup component parameter \"" +
104 result = avg /
static_cast<double>(group->nDets());
108 result = param->value<
double>();
110 throw std::invalid_argument(
"ComptonProfile - Unable to find component parameter \"" +
name +
"\".");
130void ConvertToYSpace::calculateY(
double &yspace,
double &qspace,
double &ei,
const double mass,
const double tsec,
132 const double v0 = detpar.
l1 / (tsec - detpar.
t0 - (detpar.
l2 / v1));
133 ei = MASS_TO_MEV * v0 * v0;
134 const double w = ei - detpar.
efixed;
136 qspace = std::sqrt(k0 * k0 + k1 * k1 - 2.0 * k0 * k1 * std::cos(detpar.
theta));
138 yspace = 0.2393 * (mass / qspace) * (w - wreduced);
145void ConvertToYSpace::init() {
146 auto wsValidator = std::make_shared<CompositeValidator>();
151 "The input workspace in Time of Flight");
153 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
154 mustBePositive->setLower(0.0);
155 mustBePositive->setLowerExclusive(
true);
156 declareProperty(
"Mass", -1.0, mustBePositive,
"The mass defining the recoil peak in AMU");
159 "The output workspace in y-Space");
162 "The output workspace in q-Space");
169void ConvertToYSpace::exec() {
173 const auto nhist =
static_cast<int64_t
>(
m_inputWS->getNumberHistograms());
174 const int64_t nreports = nhist;
175 auto progress = std::make_shared<Progress>(
this, 0.0, 1.0, nreports);
177 auto &spectrumInfo =
m_outputWS->mutableSpectrumInfo();
180 qSpectrumInfo = &
m_qOutputWS->mutableSpectrumInfo();
183 for (int64_t i = 0; i < nhist; ++i) {
190 spectrumInfo.setMasked(i,
true);
193 qSpectrumInfo->setMasked(i,
true);
214bool ConvertToYSpace::convert(
const size_t index) {
217 const double v1 = std::sqrt(detPar.
efixed / MASS_TO_MEV);
229 const size_t npts = inY.size();
230 for (
size_t j = 0; j < npts; ++j) {
231 double ys(0.0), qs(0.0), ei(0.0);
233 const size_t outIndex = (npts - j - 1);
235 const double prefactor = qs / pow(ei, 0.1);
236 outY[outIndex] = prefactor * inY[j];
237 outE[outIndex] = prefactor * inE[j];
253void ConvertToYSpace::retrieveInputs() {
262void ConvertToYSpace::createOutputWorkspace() {
266 auto xLabel = std::make_shared<Units::Label>(
"Momentum",
"A^-1");
281void ConvertToYSpace::cacheInstrumentGeometry() {
283 auto source = inst->getSource();
284 auto sample = inst->getSample();
285 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.
Holds a collection of detectors.
base class for Geometric IComponent
virtual ComponentID getComponentID() const =0
Returns the ComponentID - a unique identifier of the component.
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.