31 const std::string &UnitsTo,
bool forceViaTOF) {
33 if (UnitsFrom == UnitsTo)
41 throw(std::invalid_argument(
" Can not initate conversion from unknown unit: " + UnitsFrom));
44 throw(std::invalid_argument(
" Can not initiate conversion to unknown unit: " + UnitsTo));
52 if (UnitsFrom ==
"TOF") {
83 throw(std::runtime_error(
"UnitsConversionHelper::initialize Should not be "
84 "able to call this function when workpsace is "
89 throw(std::invalid_argument(
"Cannot retrieve numeric X axis from the input workspace: " + inWS2D->getName()));
91 std::string unitsFrom = inWS2D->getAxis(0)->
unit()->unitID();
95 throw std::runtime_error(
"MDWSDescription does not have a detector table");
97 auto Emode =
static_cast<int>(targetWSDescr.
getEMode());
103inline bool inRange(
const std::pair<double, double> &range,
const double &val) {
104 return val >= range.first && val <= range.second;
108inline bool inRange(
const double &xMin,
const double &xMax,
const double &val) {
return val >= xMin && val <= xMax; }
120 std::pair<double, double> range;
121 range.first = std::min(x1, x2);
122 range.second = std::max(x1, x2);
135 double uMin = std::min(u1, u2);
136 double uMax = std::max(u1, u2);
137 if (
inRange(uMin, uMax, trRange.first)) {
141 if (
inRange(uMin, uMax, trRange.second)) {
164 if (!
inRange(source_range, range.first) || !
inRange(source_range, range.second)) {
165 if (
inRange(range, source_range.first))
166 range.first = source_range.first;
167 if (
inRange(range, source_range.second))
168 range.second = source_range.second;
172 if (std::isnan(tof1) || std::isnan(tof2)) {
173 if (range.first < source_range.first)
174 range.first = source_range.first;
175 if (range.second > source_range.second)
176 range.second = source_range.second;
186 double u1 = range.first;
187 double u2 = range.second;
192 range.first = std::min(u1, u2);
193 range.second = std::max(u1, u2);
198 throw std::runtime_error(
"updateConversion: unknown type of conversion requested");
224 throw std::runtime_error(
"UnitsConversionHelper::initialize called with "
225 "empty preprocessed detectors table");
234 throw(std::runtime_error(
" Cannot retrieve target unit from the units factory"));
237 m_pTwoThetas = &(DetWS->getColVector<
double>(
"TwoTheta"));
238 m_pL2s = &(DetWS->getColVector<
double>(
"L2"));
240 m_L1 = DetWS->getLogs()->getPropertyValueAsType<
double>(
"L1");
243 m_Efix = DetWS->getLogs()->getPropertyValueAsType<
double>(
"Ei");
248 m_pDIFAs = &(DetWS->getColVector<
double>(
"DIFA"));
249 m_pDIFCs = &(DetWS->getColVector<
double>(
"DIFC"));
250 m_pTZEROs = &(DetWS->getColVector<
double>(
"TZERO"));
264 {{UnitParams::l2,
m_L2},
266 {UnitParams::efixed, Efix},
267 {UnitParams::difa,
m_DIFA},
268 {UnitParams::difc,
m_DIFC},
269 {UnitParams::tzero,
m_TZERO}});
272 {{UnitParams::l2,
m_L2},
274 {UnitParams::efixed, Efix},
275 {UnitParams::difa,
m_DIFA},
276 {UnitParams::difc,
m_DIFC},
277 {UnitParams::tzero,
m_TZERO}});
299 {{UnitParams::l2,
m_L2},
301 {UnitParams::efixed, Efix},
302 {UnitParams::difa,
m_DIFA},
303 {UnitParams::difc,
m_DIFC},
304 {UnitParams::tzero,
m_TZERO}});
318 {UnitParams::efixed, Efix}, {UnitParams::difa,
m_DIFA},
325 throw std::runtime_error(
"updateConversion: unknown type of conversion requested");
348 throw std::runtime_error(
"updateConversion: unknown type of conversion requested");
379 : m_UnitCnvrsn(CnvrtToMD::
ConvertNo), m_Factor(1), m_Power(1), m_Emode(-1),
380 m_L1(1), m_Efix(1), m_TwoTheta(0),
m_L2(1), m_DIFA(0.), m_DIFC(0.), m_TZERO(0.), m_pTwoThetas(nullptr),
381 m_pL2s(nullptr), m_pEfixedArray(nullptr), m_pDIFAs(nullptr), m_pDIFCs(nullptr), m_pTZEROs(nullptr) {}
const std::vector< double > & m_L2
const std::shared_ptr< Kernel::Unit > & unit() const
The unit for this axis.
Class to represent a numeric axis of a workspace.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
helper class describes the properties of target MD workspace, which should be obtained as the result ...
API::MatrixWorkspace_const_sptr getInWS() const
Kernel::DeltaEMode::Type getEMode() const
DataObjects::TableWorkspace_const_sptr m_PreprDetTable
CnvrtToMD::ConvertUnits analyzeUnitsConversion(const std::string &UnitsFrom, const std::string &UnitsTo, bool forceViaTOF=false)
establish and initialize proper units conversion from input to output units;
std::vector< double > const * m_pTwoThetas
bool isUnitConverted() const
Test and check if units conversion really occurs.
CnvrtToMD::ConvertUnits m_UnitCnvrsn
std::vector< double > const * m_pTZEROs
std::vector< double > const * m_pL2s
void updateConversion(size_t i)
Method updates unit conversion given the index of detector parameters in the array of detectors.
std::vector< double > const * m_pDIFAs
Kernel::Unit_sptr m_SourceWSUnit
void initialize(const MDWSDescription &targetWSDescr, const std::string &unitsTo, bool forceViaTOF=false)
Initialize unit conversion helper This method is interface to internal initialize method,...
double convertUnits(double val) const
do actual unit conversion from input to oputput data
Kernel::Unit_sptr m_TargetUnit
std::pair< double, double > getConversionRange(double x1, double x2) const
Method verify if the Units transformation is well defined in the range provided and if not returns th...
std::vector< double > const * m_pDIFCs
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< const TableWorkspace > TableWorkspace_const_sptr
shared pointer to Mantid::DataObjects::TableWorkspace (const version)
MANTID_KERNEL_DLL int isMember(const std::vector< std::string > &group, const std::string &candidate)
checks if the candidate is the member of the group
std::unordered_map< UnitParams, double > UnitParametersMap
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
bool inRange(const std::pair< double, double > &range, const double &val)
Generate a tableworkspace to store the calibration results.