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> &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> &ydata,
const double &_l1,
const int &_emode,
108 double convertSingleToTOF(
const double xvalue,
const double &l1,
const int &emode,
const UnitParametersMap ¶ms);
123 void fromTOF(std::vector<double> &xdata, std::vector<double> &ydata,
const double &_l1,
const int &_emode,
124 std::initializer_list<std::pair<const UnitParams, double>> params);
126 void fromTOF(std::vector<double> &xdata, std::vector<double> &ydata,
const double &_l1,
const int &_emode,
142 double convertSingleFromTOF(
const double xvalue,
const double &l1,
const int &emode,
const UnitParametersMap ¶ms);
157 void initialize(
const double &_l1,
const int &_emode,
const UnitParametersMap ¶ms);
189 virtual std::pair<double, double> conversionRange()
const;
193 void addConversion(std::string to,
const double &factor,
const double &power = 1.0)
const;
198 virtual void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms);
223 using ConversionsMap = tbb::concurrent_unordered_map<std::string, UnitConversions>;
244 const std::string
unitID()
const override;
245 const std::string
caption()
const override {
return ""; }
249 double singleToTOF(
const double x)
const override;
250 double singleFromTOF(
const double tof)
const override;
251 void init()
override;
252 Unit *clone()
const override;
254 double conversionTOFMin()
const override;
255 double conversionTOFMax()
const override;
265 const std::string
unitID()
const override;
266 const std::string
caption()
const override {
return m_caption; }
270 Label(
const std::string &caption,
const std::string &label);
272 Unit *clone()
const override;
285 const std::string
unitID()
const override;
286 const std::string
caption()
const override {
return "Time-of-flight"; }
290 void init()
override;
291 double singleToTOF(
const double x)
const override;
292 double singleFromTOF(
const double tof)
const override;
293 Unit *clone()
const override;
295 double conversionTOFMin()
const override;
297 double conversionTOFMax()
const override;
304 const std::string
unitID()
const override;
305 const std::string
caption()
const override {
return "Wavelength"; }
308 double singleToTOF(
const double x)
const override;
309 double singleFromTOF(
const double tof)
const override;
310 void init()
override;
311 Unit *clone()
const override;
313 double conversionTOFMin()
const override;
314 double conversionTOFMax()
const override;
320 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
333 const std::string
unitID()
const override;
334 const std::string
caption()
const override {
return "Energy"; }
337 double singleToTOF(
const double x)
const override;
338 double singleFromTOF(
const double tof)
const override;
339 void init()
override;
340 Unit *clone()
const override;
342 double conversionTOFMin()
const override;
343 double conversionTOFMax()
const override;
349 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
358 const std::string
unitID()
const override;
359 const std::string
caption()
const override {
return "Energy"; }
362 double singleToTOF(
const double x)
const override;
363 double singleFromTOF(
const double tof)
const override;
364 void init()
override;
365 Unit *clone()
const override;
366 double conversionTOFMin()
const override;
367 double conversionTOFMax()
const override;
373 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
379 const double offset);
385 const std::string
unitID()
const override;
386 const std::string
caption()
const override {
return "d-Spacing"; }
388 double singleToTOF(
const double x)
const override;
389 double singleFromTOF(
const double tof)
const override;
390 void init()
override;
391 Unit *clone()
const override;
392 double conversionTOFMin()
const override;
393 double conversionTOFMax()
const override;
394 double calcTofMin(
const double difc,
const double difa,
const double tzero,
const double tofmin = 0.);
395 double calcTofMax(
const double difc,
const double difa,
const double tzero,
const double tofmax = 0.);
401 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
412 const std::string
unitID()
const override;
413 const std::string
caption()
const override {
return "d-SpacingPerpendicular"; }
416 double singleToTOF(
const double x)
const override;
417 double singleFromTOF(
const double tof)
const override;
418 void init()
override;
419 Unit *clone()
const override;
420 double conversionTOFMin()
const override;
421 double conversionTOFMax()
const override;
427 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
439 const std::string
unitID()
const override;
440 const std::string
caption()
const override {
return "q"; }
443 double singleToTOF(
const double x)
const override;
444 double singleFromTOF(
const double tof)
const override;
445 void init()
override;
446 Unit *clone()
const override;
447 double conversionTOFMin()
const override;
448 double conversionTOFMax()
const override;
453 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
461 const std::string
unitID()
const override;
462 const std::string
caption()
const override {
return "Q2"; }
465 double singleToTOF(
const double x)
const override;
466 double singleFromTOF(
const double tof)
const override;
467 Unit *clone()
const override;
468 double conversionTOFMin()
const override;
469 double conversionTOFMax()
const override;
479 const std::string
unitID()
const override;
480 const std::string
caption()
const override {
return "Energy transfer"; }
483 double singleToTOF(
const double x)
const override;
484 double singleFromTOF(
const double tof)
const override;
485 void init()
override;
486 Unit *clone()
const override;
488 double conversionTOFMin()
const override;
489 double conversionTOFMax()
const override;
495 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
508 const std::string
unitID()
const override;
509 const std::string
caption()
const override {
return "Energy transfer"; }
512 void init()
override;
513 Unit *clone()
const override;
514 double conversionTOFMin()
const override;
515 double conversionTOFMax()
const override;
524 const std::string
unitID()
const override;
525 const std::string
caption()
const override {
return "Energy transfer"; }
528 void init()
override;
529 Unit *clone()
const override;
530 double conversionTOFMin()
const override;
531 double conversionTOFMax()
const override;
540 const std::string
unitID()
const override;
541 const std::string
caption()
const override {
return "Momentum"; }
544 double singleToTOF(
const double ki)
const override;
545 double singleFromTOF(
const double tof)
const override;
546 void init()
override;
547 Unit *clone()
const override;
548 double conversionTOFMin()
const override;
549 double conversionTOFMax()
const override;
555 void validateUnitParams(
const int emode,
const UnitParametersMap ¶ms)
override;
568 const std::string
unitID()
const override;
569 const std::string
caption()
const override {
return "Spin Echo Length"; }
572 double singleToTOF(
const double x)
const override;
573 double singleFromTOF(
const double tof)
const override;
574 void init()
override;
575 Unit *clone()
const override;
576 double conversionTOFMin()
const override;
577 double conversionTOFMax()
const override;
590 const std::string
unitID()
const override;
591 const std::string
caption()
const override {
return "Spin Echo Time"; }
594 double singleToTOF(
const double x)
const override;
595 double singleFromTOF(
const double tof)
const override;
596 void init()
override;
597 Unit *clone()
const override;
598 double conversionTOFMin()
const override;
599 double conversionTOFMax()
const override;
612 const std::string
unitID()
const override;
613 const std::string
caption()
const override {
return "t"; }
617 double singleToTOF(
const double x)
const override;
618 double singleFromTOF(
const double tof)
const override;
619 double conversionTOFMax()
const override;
620 double conversionTOFMin()
const override;
621 void init()
override;
622 Unit *clone()
const override;
637 const std::string
unitID()
const override;
638 const std::string
caption()
const override {
return "Scattering angle"; }
641 void init()
override;
642 Unit *clone()
const override;
644 double singleToTOF(
const double x)
const override;
645 double singleFromTOF(
const double tof)
const override;
646 double conversionTOFMin()
const override;
647 double conversionTOFMax()
const override;
656 const std::string
unitID()
const override;
657 const std::string
caption()
const override {
return "Phi"; }
666 const std::string
unitID()
const override;
667 const std::string
caption()
const override {
return "Temperature"; }
670 void init()
override;
671 Unit *clone()
const override;
673 double singleToTOF(
const double x)
const override;
674 double singleFromTOF(
const double tof)
const override;
675 double conversionTOFMin()
const override;
676 double conversionTOFMax()
const override;
687 const std::string
unitID()
const override;
688 const std::string
caption()
const override {
return "Atomic Distance"; }
691 void init()
override;
692 Unit *clone()
const override;
694 double singleToTOF(
const double x)
const override;
695 double singleFromTOF(
const double tof)
const override;
696 double conversionTOFMin()
const override;
697 double conversionTOFMax()
const override;
705MANTID_KERNEL_DLL
double timeConversionValue(
const std::string &input_unit,
const std::string &output_unit);
711 std::transform(vec.begin(), vec.end(), vec.begin(), [factor](T
x) -> T { return x * static_cast<T>(factor); });
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
"Empty"
const std::string caption() const override
< Degrees
Energy transfer in units of frequency (MHz)
const std::string caption() const override
The full name of the unit.
const std::string unitID() const override
"DeltaE_inFrequency"
Energy transfer in units of wavenumber (cm^-1)
const std::string caption() const override
The full name of the unit.
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
"Empty"
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 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)