Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Static Private Attributes | List of all members
Mantid::Kernel::Unit Class Referenceabstract

The base units (abstract) class. More...

#include <Unit.h>

Inheritance diagram for Mantid::Kernel::Unit:
Mantid::Kernel::Units::DeltaE Mantid::Kernel::Units::Empty Mantid::Kernel::Units::Energy Mantid::Kernel::Units::Energy_inWavenumber Mantid::Kernel::Units::Momentum Mantid::Kernel::Units::MomentumTransfer Mantid::Kernel::Units::TOF Mantid::Kernel::Units::Time Mantid::Kernel::Units::Wavelength Mantid::Kernel::Units::dSpacing Mantid::Kernel::Units::dSpacingPerpendicular

Public Member Functions

virtual const std::string caption () const =0
 The full name of the unit. More...
 
virtual Unitclone () const =0
 
virtual std::pair< double, double > conversionRange () const
 The range where conversion to TOF from given units is monotonic and reversible. More...
 
virtual double conversionTOFMax () const =0
 This function returns maximal TOF value still reversibly convertible into the unit. More...
 
virtual double conversionTOFMin () const =0
 some units can be converted from TOF only in the range of TOF ; This function returns minimal TOF value still reversibly convertible into the unit. More...
 
double convertSingleFromTOF (const double xvalue, const double &l1, const int &emode, const UnitParametersMap &params)
 Convert from the time-of-flight to the concrete unit. More...
 
double convertSingleToTOF (const double xvalue, const double &l1, const int &emode, const UnitParametersMap &params)
 Convert from the concrete unit to time-of-flight. More...
 
void fromTOF (std::vector< double > &xdata, std::vector< double > &ydata, const double &_l1, const int &_emode, const UnitParametersMap &params)
 
void fromTOF (std::vector< double > &xdata, std::vector< double > &ydata, const double &_l1, const int &_emode, std::initializer_list< std::pair< const UnitParams, double > > params)
 Convert from time-of-flight to the concrete unit. More...
 
virtual void init ()=0
 Finalize the initialization. More...
 
void initialize (const double &_l1, const int &_emode, const UnitParametersMap &params)
 Initialize the unit to perform conversion using singleToTof() and singleFromTof() More...
 
virtual bool isConvertible () const
 Returns if the unit can be used in conversions. More...
 
bool isInitialized () const
 
virtual const UnitLabel label () const =0
 A label for the unit to be printed on axes,. More...
 
bool operator!= (const Unit &u) const
 
bool operator== (const Unit &u) const
 
bool quickConversion (const Unit &destination, double &factor, double &power) const
 Is conversion by constant multiplication possible? More...
 
bool quickConversion (std::string destUnitName, double &factor, double &power) const
 Is conversion by constant multiplication possible? More...
 
virtual double singleFromTOF (const double tof) const =0
 Convert a single tof value to this unit. More...
 
virtual double singleToTOF (const double x) const =0
 Convert a single X value to TOF. More...
 
void toTOF (std::vector< double > &xdata, std::vector< double > &ydata, const double &_l1, const int &_emode, const UnitParametersMap &params)
 
void toTOF (std::vector< double > &xdata, std::vector< double > &ydata, const double &_l1, const int &_emode, std::initializer_list< std::pair< const UnitParams, double > > params)
 Convert from the concrete unit to time-of-flight. More...
 
 Unit ()
 (Empty) Constructor More...
 
virtual const std::string unitID () const =0
 The name of the unit. More...
 
virtual ~Unit ()=default
 Virtual destructor. More...
 

Protected Member Functions

void addConversion (std::string to, const double &factor, const double &power=1.0) const
 Add a 'quick conversion' from the unit class on which this method is called. More...
 
virtual void validateUnitParams (const int emode, const UnitParametersMap &params)
 

Protected Attributes

int emode
 emode :: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry) More...
 
bool initialized
 The unit values have been initialized. More...
 
double l1
 l1 :: The source-sample distance (in metres) More...
 
const UnitParametersMapm_params
 additional parameters l2 :: distance from sample to detector (in metres) twoTheta :: scattering angle in radians efixed :: Value of fixed energy: EI (emode=1) or EF (emode=2) (in meV) difc :: diffractometer constant DIFC More...
 

Private Types

using ConstantAndPower = std::pair< double, double >
 A 'quick conversion' requires the constant by which to multiply the input and the power to which to raise it. More...
 
using ConversionsMap = tbb::concurrent_unordered_map< std::string, UnitConversions >
 The possible 'quick conversions' are held in a map with the starting unit as the key. More...
 
using UnitConversions = tbb::concurrent_unordered_map< std::string, ConstantAndPower >
 Lists, for a given starting unit, the units to which a 'quick conversion' can be made. More...
 

Static Private Attributes

static ConversionsMap s_conversionFactors = Unit::ConversionsMap()
 The table of possible 'quick conversions'. More...
 

Detailed Description

The base units (abstract) class.

All concrete units should inherit from this class and provide implementations of the caption(), label(), toTOF() and fromTOF() methods. They also need to declare (but NOT define) the unitID() method and register into the UnitFactory via the macro DECLARE_UNIT(classname).

Author
Russell Taylor, Tessella Support Services plc
Date
25/02/2008

Definition at line 41 of file Unit.h.

Member Typedef Documentation

◆ ConstantAndPower

using Mantid::Kernel::Unit::ConstantAndPower = std::pair<double, double>
private

A 'quick conversion' requires the constant by which to multiply the input and the power to which to raise it.

Definition at line 217 of file Unit.h.

◆ ConversionsMap

using Mantid::Kernel::Unit::ConversionsMap = tbb::concurrent_unordered_map<std::string, UnitConversions>
private

The possible 'quick conversions' are held in a map with the starting unit as the key.

Definition at line 223 of file Unit.h.

◆ UnitConversions

using Mantid::Kernel::Unit::UnitConversions = tbb::concurrent_unordered_map<std::string, ConstantAndPower>
private

Lists, for a given starting unit, the units to which a 'quick conversion' can be made.

Definition at line 220 of file Unit.h.

Constructor & Destructor Documentation

◆ Unit()

Mantid::Kernel::Unit::Unit ( )

(Empty) Constructor

Default constructor Gives the unit an empty UnitLabel.

Definition at line 42 of file Unit.cpp.

◆ ~Unit()

virtual Mantid::Kernel::Unit::~Unit ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ addConversion()

void Mantid::Kernel::Unit::addConversion ( std::string  to,
const double &  factor,
const double &  power = 1.0 
) const
protected

Add a 'quick conversion' from the unit class on which this method is called.

Parameters
to:: The destination Unit for this conversion (use name returned by the unit's unitID() method)
factor:: The constant by which to multiply the input unit
power:: The power to which to raise the input unit (defaults to 1)

Definition at line 113 of file Unit.cpp.

References s_conversionFactors, and unitID().

Referenced by Mantid::Kernel::Units::DeltaE::DeltaE(), Mantid::Kernel::Units::DeltaE_inFrequency::DeltaE_inFrequency(), Mantid::Kernel::Units::DeltaE_inWavenumber::DeltaE_inWavenumber(), Mantid::Kernel::Units::Energy::Energy(), Mantid::Kernel::Units::Energy_inWavenumber::Energy_inWavenumber(), Mantid::Kernel::Units::Momentum::Momentum(), Mantid::Kernel::Units::MomentumTransfer::MomentumTransfer(), and Mantid::Kernel::Units::QSquared::QSquared().

◆ caption()

virtual const std::string Mantid::Kernel::Unit::caption ( ) const
pure virtual

◆ clone()

virtual Unit * Mantid::Kernel::Unit::clone ( ) const
pure virtual

◆ conversionRange()

std::pair< double, double > Mantid::Kernel::Unit::conversionRange ( ) const
virtual

The range where conversion to TOF from given units is monotonic and reversible.

Definition at line 204 of file Unit.cpp.

References conversionTOFMax(), conversionTOFMin(), and singleFromTOF().

◆ conversionTOFMax()

virtual double Mantid::Kernel::Unit::conversionTOFMax ( ) const
pure virtual

◆ conversionTOFMin()

virtual double Mantid::Kernel::Unit::conversionTOFMin ( ) const
pure virtual

◆ convertSingleFromTOF()

double Mantid::Kernel::Unit::convertSingleFromTOF ( const double  xvalue,
const double &  l1,
const int &  emode,
const UnitParametersMap params 
)

Convert from the time-of-flight to the concrete unit.

Convert a single value from TOF.

TOF is in microseconds.

Parameters
xvalue:: A single X-value to convert
l1:: The source-sample distance (in metres)
emode:: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
params:: Map containing optional parameters eg The sample-detector distance (in metres) The scattering angle (in radians) Fixed energy: EI (emode=1) or EF (emode=2)(in meV) Delta (not currently used)
Returns
the value in these units.
Parameters
xvalue
l1
emode
params(eg efixed or delta)

Definition at line 198 of file Unit.cpp.

References emode, initialize(), and singleFromTOF().

Referenced by Mantid::Kernel::UnitConversion::convertViaTOF(), Mantid::Crystal::AnvredCorrection::exec(), and Mantid::Crystal::AnvredCorrection::execEvent().

◆ convertSingleToTOF()

double Mantid::Kernel::Unit::convertSingleToTOF ( const double  xvalue,
const double &  l1,
const int &  emode,
const UnitParametersMap params 
)

Convert from the concrete unit to time-of-flight.

Convert a single value to TOF.

TOF is in microseconds.

Parameters
xvalue:: A single X-value to convert
l1:: The source-sample distance (in metres)
emode:: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
params:: Map containing optional parameters eg The sample-detector distance (in metres) The scattering angle (in radians) Fixed energy: EI (emode=1) or EF (emode=2)(in meV) Delta (not currently used)
Returns
the value in TOF units.
Parameters
xvalue
l1
emode
params(eg efixed or delta)

Definition at line 168 of file Unit.cpp.

References emode, initialize(), and singleToTOF().

Referenced by Mantid::Kernel::UnitConversion::convertViaTOF().

◆ fromTOF() [1/2]

void Mantid::Kernel::Unit::fromTOF ( std::vector< double > &  xdata,
std::vector< double > &  ydata,
const double &  _l1,
const int &  _emode,
const UnitParametersMap params 
)

Definition at line 183 of file Unit.cpp.

References initialize(), singleFromTOF(), and UNUSED_ARG.

◆ fromTOF() [2/2]

void Mantid::Kernel::Unit::fromTOF ( std::vector< double > &  xdata,
std::vector< double > &  ydata,
const double &  _l1,
const int &  _emode,
std::initializer_list< std::pair< const UnitParams, double > >  params 
)

Convert from time-of-flight to the concrete unit.

Perform the conversion to TOF on a vector of data.

TOF is in microseconds.

Parameters
xdata:: The array of X data to be converted
ydata:: Not currently used (ConvertUnits passes an empty vector)
_l1:: The source-sample distance (in metres)
_emode:: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
params:: Map containing optional parameters eg The sample-detector distance (in metres) The scattering angle (in radians) Fixed energy: EI (emode=1) or EF (emode=2)(in meV) Delta (not currently used)

Definition at line 177 of file Unit.cpp.

References fromTOF().

Referenced by Mantid::Algorithms::AlignDetectors::align(), Mantid::Crystal::NormaliseVanadium::exec(), fromTOF(), Mantid::Crystal::CentroidPeaks::integrate(), and Mantid::Crystal::CentroidPeaks::integrateEvent().

◆ init()

virtual void Mantid::Kernel::Unit::init ( )
pure virtual

◆ initialize()

void Mantid::Kernel::Unit::initialize ( const double &  _l1,
const int &  _emode,
const UnitParametersMap params 
)

Initialize the unit to perform conversion using singleToTof() and singleFromTof()

Parameters
_l1:: The source-sample distance (in metres)
_emode:: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
params:: map containing other optional parameters: The sample-detector distance (in metres) The scattering angle (in radians) Fixed energy: EI (emode=1) or EF (emode=2) (in meV) Diffractometer constants (DIFA, DIFC, TZERO) Delta: unused
Parameters
_l1:: The source-sample distance (in metres)
_emode:: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
params:: Map containing optional parameters eg The sample-detector distance (in metres) The scattering angle (in radians) Fixed energy: EI (emode=1) or EF (emode=2)(in meV) Delta (not currently used)

Definition at line 132 of file Unit.cpp.

References emode, init(), initialized, l1, m_params, and validateUnitParams().

Referenced by Mantid::Algorithms::AlignDetectors::align(), Mantid::Crystal::LoadIsawPeaks::appendFile(), Mantid::Kernel::Units::dSpacing::calcTofMax(), Mantid::Kernel::Units::dSpacing::calcTofMin(), convertSingleFromTOF(), convertSingleToTOF(), Mantid::Crystal::PeakHKLErrors::createNewPeak(), Mantid::Crystal::SCDPanelErrors::eval(), Mantid::Algorithms::ApplyInstrumentToPeaks::exec(), Mantid::Algorithms::CalculatePlaczek::exec(), Mantid::Algorithms::PDCalibration::exec(), Mantid::Crystal::SCDCalibratePanels::findT0(), fromTOF(), Mantid::Crystal::SCDCalibratePanels2ObjFunc::function1D(), Mantid::Algorithms::BackgroundHelper::removeBackground(), and toTOF().

◆ isConvertible()

virtual bool Mantid::Kernel::Unit::isConvertible ( ) const
inlinevirtual

Returns if the unit can be used in conversions.

Returns
true if the unit can be used in unit conversions

Reimplemented in Mantid::Kernel::Units::Empty, and Mantid::Kernel::Units::Time.

Definition at line 68 of file Unit.h.

◆ isInitialized()

bool Mantid::Kernel::Unit::isInitialized ( ) const
inline

◆ label()

virtual const UnitLabel Mantid::Kernel::Unit::label ( ) const
pure virtual

◆ operator!=()

bool Mantid::Kernel::Unit::operator!= ( const Unit u) const

Definition at line 46 of file Unit.cpp.

◆ operator==()

bool Mantid::Kernel::Unit::operator== ( const Unit u) const

Definition at line 44 of file Unit.cpp.

References unitID().

◆ quickConversion() [1/2]

bool Mantid::Kernel::Unit::quickConversion ( const Unit destination,
double &  factor,
double &  power 
) const

Is conversion by constant multiplication possible?

Look to see if conversion from the unit upon which this method is called requires only multiplication by a constant and not detector information (i.e. distance & angle), in which case doing the conversion via time-of-flight is not necessary.

Parameters
destination:: The unit to which conversion is sought
factor:: Returns the constant by which to multiply the input unit (if a conversion is found)
power:: Returns the power to which to raise the unput unit (if a conversion is found)
Returns
True if a 'quick conversion' exists, false otherwise

Definition at line 62 of file Unit.cpp.

References quickConversion(), and unitID().

Referenced by Mantid::Kernel::UnitConversion::convertToElasticQ(), quickConversion(), and Mantid::Kernel::UnitConversion::run().

◆ quickConversion() [2/2]

bool Mantid::Kernel::Unit::quickConversion ( std::string  destUnitName,
double &  factor,
double &  power 
) const

Is conversion by constant multiplication possible?

Look to see if conversion from the unit upon which this method is called requires only multiplication by a constant and not detector information (i.e. distance & angle), in which case doing the conversion via time-of-flight is not necessary.

Parameters
destUnitName:: The class name of the unit to which conversion is sought
factor:: Returns the constant by which to multiply the input unit (if a conversion is found)
power:: Returns the power to which to raise the unput unit (if a conversion is found)
Returns
True if a 'quick conversion' exists, false otherwise

Definition at line 82 of file Unit.cpp.

References s_conversionFactors, and unitID().

◆ singleFromTOF()

virtual double Mantid::Kernel::Unit::singleFromTOF ( const double  tof) const
pure virtual

◆ singleToTOF()

virtual double Mantid::Kernel::Unit::singleToTOF ( const double  x) const
pure virtual

◆ toTOF() [1/2]

void Mantid::Kernel::Unit::toTOF ( std::vector< double > &  xdata,
std::vector< double > &  ydata,
const double &  _l1,
const int &  _emode,
const UnitParametersMap params 
)

Definition at line 153 of file Unit.cpp.

References initialize(), singleToTOF(), and UNUSED_ARG.

◆ toTOF() [2/2]

void Mantid::Kernel::Unit::toTOF ( std::vector< double > &  xdata,
std::vector< double > &  ydata,
const double &  _l1,
const int &  _emode,
std::initializer_list< std::pair< const UnitParams, double > >  params 
)

Convert from the concrete unit to time-of-flight.

Perform the conversion to TOF on a vector of data.

TOF is in microseconds.

Parameters
xdata:: The array of X data to be converted
ydata:: Not currently used (ConvertUnits passes an empty vector)
_l1:: The source-sample distance (in metres)
_emode:: The energy mode (0=elastic, 1=direct geometry, 2=indirect geometry)
params:: Map containing optional parameters eg The sample-detector distance (in metres) The scattering angle (in radians) Fixed energy: EI (emode=1) or EF (emode=2)(in meV) Delta (not currently used)

Definition at line 147 of file Unit.cpp.

References toTOF().

Referenced by Mantid::DataHandling::SaveGDA::exec(), Mantid::Algorithms::PDCalibration::FittedPeaks::setPositions(), and toTOF().

◆ unitID()

virtual const std::string Mantid::Kernel::Unit::unitID ( ) const
pure virtual

◆ validateUnitParams()

void Mantid::Kernel::Unit::validateUnitParams ( const int  emode,
const UnitParametersMap params 
)
protectedvirtual

Member Data Documentation

◆ emode

int Mantid::Kernel::Unit::emode
protected

◆ initialized

bool Mantid::Kernel::Unit::initialized
protected

The unit values have been initialized.

Definition at line 201 of file Unit.h.

Referenced by initialize().

◆ l1

double Mantid::Kernel::Unit::l1
protected

◆ m_params

const UnitParametersMap* Mantid::Kernel::Unit::m_params
protected

◆ s_conversionFactors

Unit::ConversionsMap Mantid::Kernel::Unit::s_conversionFactors = Unit::ConversionsMap()
staticprivate

The table of possible 'quick conversions'.

Definition at line 225 of file Unit.h.

Referenced by addConversion(), and quickConversion().


The documentation for this class was generated from the following files: