15#include <unordered_map>
21#include "tbb/concurrent_unordered_map.h"
41class MANTID_KERNEL_DLL
Unit {
57 virtual const std::string
unitID()
const = 0;
60 virtual const std::string
caption()
const = 0;
75 bool quickConversion(
const Unit &destination,
double &factor,
double &power)
const;
76 bool quickConversion(std::string destUnitName,
double &factor,
double &power)
const;
91 void toTOF(std::vector<double> &xdata, std::vector<double>
const &ydata,
const double &_l1,
const int &_emode,
92 std::initializer_list<std::pair<const UnitParams, double>> params);
93 void toTOF(std::vector<double> &xdata, std::vector<double>
const &ydata,
const double &_l1,
const int &_emode,
97 double convertSingleToTOF(
const double xvalue,
const double &l1,
const int &emode,
const UnitParametersMap ¶ms);
112 void fromTOF(std::vector<double> &xdata, std::vector<double>
const &ydata,
const double &_l1,
const int &_emode,
113 std::initializer_list<std::pair<const UnitParams, double>> params);
115 void fromTOF(std::vector<double> &xdata, std::vector<double>
const &ydata,
const double &_l1,
const int &_emode,
119 double convertSingleFromTOF(
const double xvalue,
const double &l1,
const int &emode,
const UnitParametersMap ¶ms);
122 void initialize(
const double &_l1,
const int &_emode,
const UnitParametersMap ¶ms);
154 virtual std::pair<double, double> conversionRange()
const;
158 void addConversion(std::string to,
const double &factor,
const double &power = 1.0)
const;
163 virtual void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms);
188 using ConversionsMap = tbb::concurrent_unordered_map<std::string, UnitConversions>;
209 const std::string
unitID()
const override;
210 const std::string
caption()
const override {
return ""; }
214 double singleToTOF(
const double x)
const override;
215 double singleFromTOF(
const double tof)
const override;
216 void init()
override;
217 Unit *clone()
const override;
219 double conversionTOFMin()
const override;
220 double conversionTOFMax()
const override;
230 const std::string
unitID()
const override;
231 const std::string
caption()
const override {
return m_caption; }
235 Label(
const std::string &caption,
const std::string &label);
237 Unit *clone()
const override;
250 const std::string
unitID()
const override;
251 const std::string
caption()
const override {
return "Time-of-flight"; }
255 void init()
override;
256 double singleToTOF(
const double x)
const override;
257 double singleFromTOF(
const double tof)
const override;
258 Unit *clone()
const override;
260 double conversionTOFMin()
const override;
262 double conversionTOFMax()
const override;
269 const std::string
unitID()
const override;
270 const std::string
caption()
const override {
return "Wavelength"; }
273 double singleToTOF(
const double x)
const override;
274 double singleFromTOF(
const double tof)
const override;
275 void init()
override;
276 Unit *clone()
const override;
278 double conversionTOFMin()
const override;
279 double conversionTOFMax()
const override;
285 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
298 const std::string
unitID()
const override;
299 const std::string
caption()
const override {
return "Energy"; }
302 double singleToTOF(
const double x)
const override;
303 double singleFromTOF(
const double tof)
const override;
304 void init()
override;
305 Unit *clone()
const override;
307 double conversionTOFMin()
const override;
308 double conversionTOFMax()
const override;
314 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
323 const std::string
unitID()
const override;
324 const std::string
caption()
const override {
return "Energy"; }
327 double singleToTOF(
const double x)
const override;
328 double singleFromTOF(
const double tof)
const override;
329 void init()
override;
330 Unit *clone()
const override;
331 double conversionTOFMin()
const override;
332 double conversionTOFMax()
const override;
338 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
344 const double offset);
347 const double offset,
const double binWidth);
353 const std::string
unitID()
const override;
354 const std::string
caption()
const override {
return "d-Spacing"; }
356 double singleToTOF(
const double x)
const override;
357 double singleFromTOF(
const double tof)
const override;
358 void init()
override;
359 Unit *clone()
const override;
360 double conversionTOFMin()
const override;
361 double conversionTOFMax()
const override;
362 double calcTofMin(
const double difc,
const double difa,
const double tzero,
const double tofmin = 0.);
363 double calcTofMax(
const double difc,
const double difa,
const double tzero,
const double tofmax = 0.);
369 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
380 const std::string
unitID()
const override;
381 const std::string
caption()
const override {
return "d-SpacingPerpendicular"; }
384 double singleToTOF(
const double x)
const override;
385 double singleFromTOF(
const double tof)
const override;
386 void init()
override;
387 Unit *clone()
const override;
388 double conversionTOFMin()
const override;
389 double conversionTOFMax()
const override;
395 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
407 const std::string
unitID()
const override;
408 const std::string
caption()
const override {
return "q"; }
411 double singleToTOF(
const double x)
const override;
412 double singleFromTOF(
const double tof)
const override;
413 void init()
override;
414 Unit *clone()
const override;
415 double conversionTOFMin()
const override;
416 double conversionTOFMax()
const override;
421 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
429 const std::string
unitID()
const override;
430 const std::string
caption()
const override {
return "Q2"; }
433 double singleToTOF(
const double x)
const override;
434 double singleFromTOF(
const double tof)
const override;
435 Unit *clone()
const override;
436 double conversionTOFMin()
const override;
437 double conversionTOFMax()
const override;
447 const std::string
unitID()
const override;
448 const std::string
caption()
const override {
return "Energy transfer"; }
451 double singleToTOF(
const double x)
const override;
452 double singleFromTOF(
const double tof)
const override;
453 void init()
override;
454 Unit *clone()
const override;
456 double conversionTOFMin()
const override;
457 double conversionTOFMax()
const override;
463 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
476 const std::string
unitID()
const override;
479 void init()
override;
480 Unit *clone()
const override;
489 const std::string
unitID()
const override;
492 void init()
override;
493 Unit *clone()
const override;
502 const std::string
unitID()
const override;
503 const std::string
caption()
const override {
return "Momentum"; }
506 double singleToTOF(
const double ki)
const override;
507 double singleFromTOF(
const double tof)
const override;
508 void init()
override;
509 Unit *clone()
const override;
510 double conversionTOFMin()
const override;
511 double conversionTOFMax()
const override;
517 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
530 const std::string
unitID()
const override;
531 const std::string
caption()
const override {
return "Spin Echo Length"; }
534 double singleToTOF(
const double x)
const override;
535 double singleFromTOF(
const double tof)
const override;
536 void init()
override;
537 Unit *clone()
const override;
538 double conversionTOFMin()
const override;
539 double conversionTOFMax()
const override;
552 const std::string
unitID()
const override;
553 const std::string
caption()
const override {
return "Spin Echo Time"; }
556 double singleToTOF(
const double x)
const override;
557 double singleFromTOF(
const double tof)
const override;
558 void init()
override;
559 Unit *clone()
const override;
560 double conversionTOFMin()
const override;
561 double conversionTOFMax()
const override;
574 const std::string
unitID()
const override;
575 const std::string
caption()
const override {
return "t"; }
579 double singleToTOF(
const double x)
const override;
580 double singleFromTOF(
const double tof)
const override;
581 double conversionTOFMax()
const override;
582 double conversionTOFMin()
const override;
583 void init()
override;
584 Unit *clone()
const override;
599 const std::string
unitID()
const override;
600 const std::string
caption()
const override {
return "Scattering angle"; }
603 Unit *clone()
const override;
605 double singleToTOF(
const double x)
const override;
606 double singleFromTOF(
const double tof)
const override;
615 const std::string
unitID()
const override;
616 const std::string
caption()
const override {
return "Phi"; }
625 const std::string
unitID()
const override;
626 const std::string
caption()
const override {
return "Temperature"; }
629 Unit *clone()
const override;
631 double singleToTOF(
const double x)
const override;
632 double singleFromTOF(
const double tof)
const override;
643 const std::string
unitID()
const override;
644 const std::string
caption()
const override {
return "Atomic Distance"; }
647 Unit *clone()
const override;
649 double singleToTOF(
const double x)
const override;
650 double singleFromTOF(
const double tof)
const override;
658MANTID_KERNEL_DLL
double timeConversionValue(
const std::string &input_unit,
const std::string &output_unit);
664 std::transform(
vec.begin(),
vec.end(),
vec.begin(), [factor](T
x) -> T { return x * static_cast<T>(factor); });
std::vector< T > const * vec
A base-class for the a class that is able to return unit labels in different representations.
The base units (abstract) class.
virtual Unit * clone() const =0
const UnitParametersMap * m_params
additional parameters l2 :: distance from sample to detector (in metres) twoTheta :: scattering angle...
virtual void init()=0
Finalize the initialization.
virtual ~Unit()=default
Virtual destructor.
virtual const UnitLabel label() const =0
A label for the unit to be printed on axes,.
virtual double conversionTOFMin() const =0
some units can be converted from TOF only in the range of TOF ; This function returns minimal TOF val...
virtual double conversionTOFMax() const =0
This function returns maximal TOF value still reversibly convertible into the unit.
virtual double singleToTOF(const double x) const =0
Convert a single X value to TOF.
virtual bool isConvertible() const
Returns if the unit can be used in conversions.
bool initialized
The unit values have been initialized.
virtual const std::string caption() const =0
The full name of the unit.
tbb::concurrent_unordered_map< std::string, UnitConversions > ConversionsMap
The possible 'quick conversions' are held in a map with the starting unit as the key.
virtual const std::string unitID() const =0
The name of the unit.
std::pair< double, double > ConstantAndPower
A 'quick conversion' requires the constant by which to multiply the input and the power to which to r...
virtual double singleFromTOF(const double tof) const =0
Convert a single tof value to this unit.
tbb::concurrent_unordered_map< std::string, ConstantAndPower > UnitConversions
Lists, for a given starting unit, the units to which a 'quick conversion' can be made.
double l1
l1 :: The source-sample distance (in metres)
static ConversionsMap s_conversionFactors
The table of possible 'quick conversions'.
int emode
emode :: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
bool isInitialized() const
Atomic Distance in Angstroms.
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"AtomicDistance"
Degrees that has degrees as unit and "Scattering angle" as title.
const std::string unitID() const override
The name of the unit.
const std::string caption() const override
< Degrees
Energy transfer in units of frequency (MHz)
const std::string unitID() const override
"DeltaE_inFrequency"
Energy transfer in units of wavenumber (cm^-1)
const std::string unitID() const override
"DeltaE_inWavenumber"
Energy transfer in milli-electronvolts.
const std::string unitID() const override
"DeltaE"
const std::string caption() const override
The full name of the unit.
double factorFrom
Constant factor for from conversion.
double factorTo
Constant factor for to conversion.
double t_otherFrom
Energy mode dependent factor in from conversion.
double unitScaling
Apply unit scaling to energy value.
double t_other
Energy mode dependent factor in to conversion.
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"Empty"
bool isConvertible() const override
Returns if the unit can be used in conversions.
Absolute energy in units of wavenumber (cm^-1)
const std::string unitID() const override
"Energy_inWavenumber"
double factorFrom
Constant factor for from conversion.
const std::string caption() const override
The full name of the unit.
double factorTo
Constant factor for to conversion.
Energy in milli-electronvolts.
const std::string unitID() const override
"Energy"
const std::string caption() const override
The full name of the unit.
double factorTo
Constant factor for to conversion.
double factorFrom
Constant factor for from conversion.
const std::string caption() const override
The full name of the unit.
std::string m_caption
Caption.
const std::string unitID() const override
"Label"
Momentum Transfer in Angstrom^-1.
const std::string unitID() const override
"MomentumTransfer"
const std::string caption() const override
The full name of the unit.
double sfpTo
Extra correction factor in to conversion.
const std::string unitID() const override
"Momentum"
const std::string caption() const override
The full name of the unit.
double sfpFrom
Extra correction factor in from conversion.
bool do_sfpFrom
Apply the sfpFrom value.
double factorTo
Constant factor for to conversion.
double factorFrom
Constant factor for from conversion.
Phi that has degrees as unit and "Phi" as title.
const std::string caption() const override
< Degrees
Unit * clone() const override
const std::string unitID() const override
The name of the unit.
Momentum transfer squared in Angstrom^-2.
const std::string unitID() const override
"QSquared"
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"SpinEchoLength"
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"SpinEchoTime"
const std::string caption() const override
The full name of the unit.
Time of flight in microseconds.
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"TOF"
const std::string unitID() const override
"Temperature"
const std::string caption() const override
The full name of the unit.
double factorFrom
Constant factor for from conversion.
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"Time"
bool isConvertible() const override
Returns if the unit can be used in conversions.
double factorTo
Constant factor for to conversion.
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"Wavelength"
bool do_sfpFrom
Apply the sfpFrom value.
double sfpFrom
Extra correction factor in from conversion.
double factorTo
Constant factor for to conversion.
double sfpTo
Extra correction factor in to conversion.
double factorFrom
Constant factor for from conversion.
d-SpacingPerpendicular in Angstrom
const std::string caption() const override
The full name of the unit.
double sfpFrom
Extra correction factor in to conversion.
double factorFrom
Constant factor for from conversion.
double factorTo
Constant factor for to conversion.
const std::string unitID() const override
"dSpacingPerpendicular"
double sfpTo
Extra correction factor in to conversion.
std::string toDSpacingError
const std::string unitID() const override
"dSpacing"
const std::string caption() const override
The full name of the unit.
void timeConversionVector(std::vector< T > &vec, const std::string &input_unit, const std::string &output_unit)
MANTID_KERNEL_DLL double calculateDIFCCorrection(const double l1, const double l2, const double twotheta, const double offset, const double binWidth)
Calculate DIFC in case of logarithmic binning, used in CalculateDIFC with Signed mode.
MANTID_KERNEL_DLL double tofToDSpacingFactor(const double l1, const double l2, const double twoTheta, const double offset)
Calculate and return conversion factor from tof to d-spacing.
MANTID_KERNEL_DLL double timeConversionValue(const std::string &input_unit, const std::string &output_unit)
std::unordered_map< UnitParams, double > UnitParametersMap
std::shared_ptr< const Unit > Unit_const_sptr
Shared pointer to the Unit base class (const version)
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
Helper class which provides the Collimation Length for SANS instruments.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator!=(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)