Commit 8a3c9690 authored by Danny Hindson's avatar Danny Hindson Committed by Zhang, Chen
Browse files

Changes to dSpacing to TOF in ConvertUnits

Changes to the Unit class and ConvertUnits algorithm to allow
diffractometer constants (DIFA, DIFC, TZERO) stored in the instrument map
to be used in conversions between d spacing and TOF and v.v.

Rather than add 3 more parameters to lots of methods provided by the Unit
class I have changed some of the methods to take a std:map containing the
optional parameters relevant to only some units. I have included efixed
and delta in this new map

New diffractometerConstants method added to SpectrumInfo and DetectorInfo
to allow retrieval for a particular spectrum including averaging across
detectors. Also manages situations where some of the three constants are
missing.

New algorithm created called ApplyDiffCal to read the diffractometer
constants from a diffraction calibration table workspace and write them
into the instrument parameter map

Add diffractometer constants to the Show Detectors screen for elastic
workspaces

Remove the Diffraction.cpp unit and replace with calls to dSpacing unit class

Add ability to write difa, difc, tzero into a reduced instrument
geometry as part of EditInstrumentGeometry
parent 8ac4c061
......@@ -68,6 +68,10 @@ public:
double azimuthal(const size_t index) const;
std::pair<double, double> geographicalAngles(const size_t index) const;
Kernel::V3D position(const size_t index) const;
std::tuple<double, double, double>
diffractometerConstants(const size_t index,
std::vector<detid_t> &uncalibratedDets) const;
double difcUncalibrated(const size_t index) const;
bool hasDetectors(const size_t index) const;
bool hasUniqueDetector(const size_t index) const;
......
......@@ -1225,10 +1225,18 @@ void IFunction::convertValue(std::vector<double> &values, Kernel::Unit_sptr &out
efixed = 0.0;
emode = 0;
}
std::vector<int> emptyWarningVec;
auto [difa, difc, tzero] =
spectrumInfo.diffractometerConstants(wsIndex, emptyWarningVec);
std::vector<double> emptyVec;
wsUnit->toTOF(values, emptyVec, l1, l2, twoTheta, emode, efixed, 0.0);
outUnit->fromTOF(values, emptyVec, l1, l2, twoTheta, emode, efixed, 0.0);
Kernel::ExtraParametersMap pmap{
{Kernel::UnitConversionParameters::efixed, efixed},
{Kernel::UnitConversionParameters::difa, difa},
{Kernel::UnitConversionParameters::difc, difc},
{Kernel::UnitConversionParameters::tzero, tzero}};
wsUnit->toTOF(values, emptyVec, l1, l2, twoTheta, emode, pmap);
outUnit->fromTOF(values, emptyVec, l1, l2, twoTheta, emode, pmap);
}
}
......
......@@ -132,6 +132,70 @@ Kernel::V3D SpectrumInfo::position(const size_t index) const {
return newPos / static_cast<double>(spectrumDefinition(index).size());
}
/** Calculate average diffractometer constants (DIFA, DIFC, TZERO) of detectors
* associated with this spectrum. Use calibrated values where possible, filling
* in with uncalibrated values where they're missing
* @param index Index of the spectrum that constants are required for
* @param warningDets A vector containing the det ids where an uncalibrated
* value was used in the situation where some dets have calibrated values and
* some don't
* @return tuple containing the average constants
*/
std::tuple<double, double, double>
SpectrumInfo::diffractometerConstants(const size_t index,
std::vector<detid_t> &warningDets) const {
if (m_detectorInfo.isScanning()) {
throw std::runtime_error("Retrieval of diffractometer constants not "
"implemented for scanning instrument");
}
auto spectrumDef = checkAndGetSpectrumDefinition(index);
std::vector<size_t> detectorIndicesOnly;
std::vector<detid_t> calibratedDets;
std::vector<detid_t> uncalibratedDets;
std::transform(spectrumDef.begin(), spectrumDef.end(),
std::back_inserter(detectorIndicesOnly),
[](auto const &pair) { return pair.first; });
double difa{0.}, difc{0.}, tzero{0.};
for (const auto &detIndex : detectorIndicesOnly) {
auto newDiffConstants = m_detectorInfo.diffractometerConstants(
detIndex, calibratedDets, uncalibratedDets);
difa += std::get<0>(newDiffConstants);
difc += std::get<1>(newDiffConstants);
tzero += std::get<2>(newDiffConstants);
}
if (calibratedDets.size() > 0 && uncalibratedDets.size() > 0) {
warningDets.insert(warningDets.end(), uncalibratedDets.begin(),
uncalibratedDets.end());
};
return {difa / static_cast<double>(spectrumDefinition(index).size()),
difc / static_cast<double>(spectrumDefinition(index).size()),
tzero / static_cast<double>(spectrumDefinition(index).size())};
}
/** Calculate average uncalibrated DIFC value of detectors associated with this
* spectrum
* @param index Index of the spectrum that DIFC is required for
* @return The average DIFC
*/
double SpectrumInfo::difcUncalibrated(const size_t index) const {
double difc{0.0};
bool atLeastOneCalibrated = false, atLeastOneUncalibrated = false;
if (m_detectorInfo.isScanning()) {
throw std::runtime_error("Retrieval of diffractometer constants not "
"implemented for scanning instrument");
}
auto spectrumDef = checkAndGetSpectrumDefinition(index);
std::vector<size_t> detectorIndicesOnly;
std::transform(spectrumDef.begin(), spectrumDef.end(),
std::back_inserter(detectorIndicesOnly),
[](auto const &pair) { return pair.first; });
for (const auto &detIndex : detectorIndicesOnly)
difc += m_detectorInfo.difcUncalibrated(detIndex);
return difc / static_cast<double>(spectrumDefinition(index).size());
}
/// Returns true if the spectrum is associated with detectors in the instrument.
bool SpectrumInfo::hasDetectors(const size_t index) const {
// Workspaces can contain invalid detector IDs. Those IDs will be silently
......
......@@ -65,8 +65,8 @@ private:
void init() override;
void exec() override;
void align(const ConversionFactors &converter, API::Progress &progress, API::MatrixWorkspace &outputWS);
void align(const ConversionFactors &converter, API::Progress &progress, DataObjects::EventWorkspace &outputWS);
void align(const ConversionFactors &converter, API::Progress &progress,
API::MatrixWorkspace_sptr &outputWS);
void loadCalFile(const API::MatrixWorkspace_sptr &inputWS, const std::string &filename);
void getCalibrationWS(const API::MatrixWorkspace_sptr &inputWS);
......
......@@ -93,9 +93,13 @@ protected:
const double &power);
/// Internal function to gather detector specific L2, theta and efixed values
bool getDetectorValues(const API::SpectrumInfo &spectrumInfo, const Kernel::Unit &outputUnit, int emode,
const API::MatrixWorkspace &ws, const bool signedTheta, int64_t wsIndex, double &efixed,
double &l2, double &twoTheta);
bool getDetectorValues(const API::SpectrumInfo &spectrumInfo,
const Kernel::Unit &outputUnit, int emode,
const API::MatrixWorkspace &ws, const bool signedTheta,
int64_t wsIndex, double &l2, double &twoTheta,
Kernel::ExtraParametersMap &pmap);
void createDetectorIdLogMessages(const std::vector<detid_t> &detids,
int64_t wsIndex) const;
/// Convert the workspace units using TOF as an intermediate step in the
/// conversion
......
......@@ -62,10 +62,13 @@ std::string createTruncatedList(const std::set<int> &elements);
void populateTable(Mantid::API::ITableWorkspace_sptr &t, const Mantid::API::MatrixWorkspace_sptr &ws, const int nrows,
const std::vector<int> &indices, const Mantid::API::SpectrumInfo &spectrumInfo,
bool signedThetaParamRetrieved, bool showSignedTwoTheta,
const Mantid::Geometry::PointingAlong &beamAxisIndex, const double sampleDist, const bool isScanning,
const bool include_data, const bool calcQ, Kernel::Logger &logger);
std::vector<std::pair<std::string, std::string>> createColumns(const bool isScanning, const bool includeData,
const bool calcQ);
const Mantid::Geometry::PointingAlong &beamAxisIndex,
const double sampleDist, const bool isScanning,
const bool include_data, const bool calcQ,
const bool includeDiffConstants, Kernel::Logger &logger);
std::vector<std::pair<std::string, std::string>>
createColumns(const bool isScanning, const bool includeData, const bool calcQ,
const bool hasDiffConstants);
} // namespace Algorithms
} // namespace Mantid
......@@ -42,12 +42,17 @@ private:
void createCalTableFromExisting();
void createCalTableNew();
void createInformationWorkspaces();
std::function<double(double)> getDSpacingToTof(const std::set<detid_t> &detIds);
std::vector<double> dSpacingWindows(const std::vector<double> &centres, const double widthMax);
std::vector<double> getTOFminmax(const double difc, const double difa, const double tzero);
void setCalibrationValues(const detid_t detid, const double difc, const double difa, const double tzero);
void fitDIFCtZeroDIFA_LM(const std::vector<double> &d, const std::vector<double> &tof,
const std::vector<double> &height2, double &difc, double &t0, double &difa);
std::tuple<double, double, double> getDSpacingToTof(const detid_t detid);
std::vector<double> dSpacingWindows(const std::vector<double> &centres,
const double widthMax);
std::vector<double> getTOFminmax(const double difc, const double difa,
const double tzero);
void setCalibrationValues(const detid_t detid, const double difc,
const double difa, const double tzero);
void fitDIFCtZeroDIFA_LM(const std::vector<double> &d,
const std::vector<double> &tof,
const std::vector<double> &height2, double &difc,
double &t0, double &difa);
API::MatrixWorkspace_sptr calculateResolutionTable();
/// NEW: convert peak positions in dSpacing to peak centers workspace
......
......@@ -66,7 +66,9 @@ private:
void crop(const double &start, const double &end);
void transformRangeUnit(const int index, double &startX, double &endX);
void calculateDetectorPosition(const int index, double &l1, double &l2, double &twoTheta);
void calculateDetectorPosition(const int index, double &l1, double &l2,
double &twoTheta, double &difa, double &difc,
double &tzero);
int findIndex(const double &value, const HistogramData::HistogramX &vec);
void RemoveFromEnds(int start, int end, HistogramData::HistogramY &Y, HistogramData::HistogramE &E);
void RemoveFromMiddle(const int &start, const int &end, const double &startFrac, const double &endFrac,
......
......@@ -80,6 +80,9 @@ void AddPeak::exec() {
double Qz = 1.0 - cos(theta2);
double l1 = detectorInfo.l1();
double l2 = detectorInfo.l2(detectorIndex);
std::vector<int> emptyWarningVec;
auto [difa, difc, tzero] = detectorInfo.diffractometerConstants(
detectorIndex, emptyWarningVec, emptyWarningVec);
Mantid::Kernel::Unit_sptr unit = runWS->getAxis(0)->unit();
if (unit->unitID() != "TOF") {
......@@ -107,7 +110,11 @@ void AddPeak::exec() {
}
std::vector<double> xdata(1, tof);
std::vector<double> ydata;
unit->toTOF(xdata, ydata, l1, l2, theta2, emode, efixed, 0.0);
unit->toTOF(xdata, ydata, l1, l2, theta2, emode,
{{Kernel::UnitConversionParameters::efixed, efixed},
{Kernel::UnitConversionParameters::difa, difa},
{Kernel::UnitConversionParameters::difc, difc},
{Kernel::UnitConversionParameters::tzero, tzero}});
tof = xdata[0];
}
......
......@@ -17,7 +17,6 @@
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/OffsetsWorkspace.h"
#include "MantidKernel/CompositeValidator.h"
#include "MantidKernel/Diffraction.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/V3D.h"
......@@ -48,7 +47,8 @@ public:
this->generateDetidToRow(table);
}
std::function<double(double)> getConversionFunc(const std::set<detid_t> &detIds) const {
std::tuple<double, double, double>
getDiffConstants(const std::set<detid_t> &detIds) const {
const std::set<size_t> rows = this->getRow(detIds);
double difc = 0.;
double difa = 0.;
......@@ -65,7 +65,7 @@ public:
tzero = norm * tzero;
}
return Kernel::Diffraction::getTofToDConversionFunc(difc, difa, tzero);
return {difc, difa, tzero};
}
private:
......@@ -251,56 +251,53 @@ void AlignDetectors::exec() {
Progress progress(this, 0.0, 1.0, m_numberOfSpectra);
auto eventW = std::dynamic_pointer_cast<EventWorkspace>(outputWS);
if (eventW) {
align(converter, progress, *eventW);
} else {
align(converter, progress, *outputWS);
}
align(converter, progress, outputWS);
}
void AlignDetectors::align(const ConversionFactors &converter, Progress &progress, MatrixWorkspace &outputWS) {
PARALLEL_FOR_IF(Kernel::threadSafe(outputWS))
void AlignDetectors::align(const ConversionFactors &converter,
Progress &progress, MatrixWorkspace_sptr &outputWS) {
auto eventW = std::dynamic_pointer_cast<EventWorkspace>(outputWS);
PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS))
for (int64_t i = 0; i < m_numberOfSpectra; ++i) {
PARALLEL_START_INTERUPT_REGION
try {
// Get the input spectrum number at this workspace index
auto &spec = outputWS.getSpectrum(size_t(i));
auto toDspacing = converter.getConversionFunc(spec.getDetectorIDs());
auto &x = outputWS.mutableX(i);
std::transform(x.begin(), x.end(), x.begin(), toDspacing);
auto &spec = outputWS->getSpectrum(size_t(i));
auto [difc, difa, tzero] =
converter.getDiffConstants(spec.getDetectorIDs());
std::vector<double> x{outputWS->x(i).front(), outputWS->x(i).back()};
Kernel::Units::dSpacing dSpacingUnit;
dSpacingUnit.fromTOF(
x, std::vector<double>{}, -1., -1., -1., 0,
ExtraParametersMap{{Kernel::UnitConversionParameters::difa, difa},
{Kernel::UnitConversionParameters::difc, difc},
{Kernel::UnitConversionParameters::tzero, tzero}});
if (eventW) {
Kernel::Units::TOF tofUnit;
// EventWorkspace part, modifying the EventLists.
eventW->getSpectrum(i).convertUnitsViaTof(&tofUnit, &dSpacingUnit);
}
} catch (const Exception::NotFoundError &) {
// Zero the data in this case
outputWS.setHistogram(i, BinEdges(outputWS.x(i).size()), Counts(outputWS.y(i).size()));
outputWS->setHistogram(i, BinEdges(outputWS->x(i).size()),
Counts(outputWS->y(i).size()));
}
progress.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
}
void AlignDetectors::align(const ConversionFactors &converter, Progress &progress, EventWorkspace &outputWS) {
PARALLEL_FOR_NO_WSP_CHECK()
for (int64_t i = 0; i < m_numberOfSpectra; ++i) {
PARALLEL_START_INTERUPT_REGION
auto toDspacing = converter.getConversionFunc(outputWS.getSpectrum(size_t(i)).getDetectorIDs());
outputWS.getSpectrum(i).convertTof(toDspacing);
progress.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
if (outputWS.getTofMin() < 0.) {
std::stringstream msg;
msg << "Something wrong with the calibration. Negative minimum d-spacing "
"created. d_min = "
<< outputWS.getTofMin() << " d_max " << outputWS.getTofMax();
g_log.warning(msg.str());
if (eventW) {
if (eventW->getTofMin() < 0.) {
std::stringstream msg;
msg << "Something wrong with the calibration. Negative minimum d-spacing "
"created. d_min = "
<< eventW->getTofMin() << " d_max " << eventW->getTofMax();
g_log.warning(msg.str());
}
eventW->clearMRU();
}
outputWS.clearMRU();
}
Parallel::ExecutionMode
......
......@@ -151,7 +151,8 @@ void CalculatePlaczekSelfScattering::exec() {
const double f = specInfo.l1() / pathLength;
const double sinThetaBy2 = sin(specInfo.twoTheta(specIndex) / 2.0);
Kernel::Units::Wavelength wavelength;
wavelength.initialize(specInfo.l1(), specInfo.l2(specIndex), specInfo.twoTheta(specIndex), 0, 1.0, 1.0);
wavelength.initialize(specInfo.l1(), specInfo.l2(specIndex),
specInfo.twoTheta(specIndex), 0);
for (size_t xIndex = 0; xIndex < xLambda.size() - 1; xIndex++) {
const double term1 = (f - 1.0) * phi1[xIndex];
const double term2 = f * (1.0 - eps1[xIndex]);
......
......@@ -94,24 +94,32 @@ void ConvertSpectrumAxis::exec() {
emode = 1;
else if (emodeStr == "Indirect")
emode = 2;
const double delta = 0.0;
double efixed;
for (size_t i = 0; i < nHist; i++) {
std::vector<double> xval{inputWS->x(i).front(), inputWS->x(i).back()};
double twoTheta, l1val, l2;
ExtraParametersMap pmap{};
if (!spectrumInfo.isMonitor(i)) {
twoTheta = spectrumInfo.twoTheta(i);
l2 = spectrumInfo.l2(i);
l1val = l1;
efixed = getEfixed(spectrumInfo.detector(i), inputWS, emode); // get efixed
efixed =
getEfixed(spectrumInfo.detector(i), inputWS, emode); // get efixed
std::vector<int> emptyWarningVec;
auto [difa, difc, tzero] =
spectrumInfo.diffractometerConstants(i, emptyWarningVec);
pmap = {{UnitConversionParameters::efixed, efixed},
{UnitConversionParameters::difa, difa},
{UnitConversionParameters::difc, difc},
{UnitConversionParameters::tzero, tzero}};
} else {
twoTheta = 0.0;
l2 = l1;
l1val = 0.0;
efixed = DBL_MIN;
}
fromUnit->toTOF(xval, emptyVector, l1val, l2, twoTheta, emode, efixed, delta);
toUnit->fromTOF(xval, emptyVector, l1val, l2, twoTheta, emode, efixed, delta);
fromUnit->toTOF(xval, emptyVector, l1val, l2, twoTheta, emode, pmap);
toUnit->fromTOF(xval, emptyVector, l1val, l2, twoTheta, emode, pmap);
double value = (xval.front() + xval.back()) / 2;
indexMap.emplace(value, i);
}
......
......@@ -14,6 +14,7 @@
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/CompositeValidator.h"
......@@ -365,6 +366,25 @@ MatrixWorkspace_sptr ConvertUnits::convertQuickly(const API::MatrixWorkspace_con
return outputWS;
}
void ConvertUnits::createDetectorIdLogMessages(
const std::vector<detid_t> &detids, int64_t wsIndex) const {
std::string detIDstring;
auto iter = detids.begin();
auto itEnd = detids.end();
for (; iter != itEnd; ++iter) {
detIDstring += std::to_string(*iter) + ",";
}
if (!detIDstring.empty()) {
detIDstring.pop_back(); // Drop last comma
}
g_log.warning(
"Incomplete set of calibrated diffractometer constants found for "
"workspace index" +
std::to_string(wsIndex) + ". Using uncalibrated values for detectors " +
detIDstring);
}
/** Get the L2, theta and efixed values for a workspace index
* @param spectrumInfo :: SpectrumInfo of the workspace
* @param outputUnit :: The output unit
......@@ -375,11 +395,15 @@ MatrixWorkspace_sptr ConvertUnits::convertQuickly(const API::MatrixWorkspace_con
* @param efixed :: the returned fixed energy
* @param l2 :: The returned sample - detector distance
* @param twoTheta :: the returned two theta angle
* @param pmap :: a map containing optional unit conversion parameters eg efixed
* @returns true if lookup successful, false on error
*/
bool ConvertUnits::getDetectorValues(const API::SpectrumInfo &spectrumInfo, const Kernel::Unit &outputUnit, int emode,
const MatrixWorkspace &ws, const bool signedTheta, int64_t wsIndex, double &efixed,
double &l2, double &twoTheta) {
bool ConvertUnits::getDetectorValues(const API::SpectrumInfo &spectrumInfo,
const Kernel::Unit &outputUnit, int emode,
const MatrixWorkspace &ws,
const bool signedTheta, int64_t wsIndex,
double &l2, double &twoTheta,
ExtraParametersMap &pmap) {
if (!spectrumInfo.hasDetectors(wsIndex))
return false;
......@@ -397,21 +421,38 @@ bool ConvertUnits::getDetectorValues(const API::SpectrumInfo &spectrumInfo, cons
twoTheta = std::numeric_limits<double>::quiet_NaN();
}
// If an indirect instrument, try getting Efixed from the geometry
if (emode == 2 && efixed == EMPTY_DBL()) // indirect
if (emode == 2 &&
pmap[UnitConversionParameters::efixed] == EMPTY_DBL()) // indirect
{
if (spectrumInfo.hasUniqueDetector(wsIndex)) {
const auto &det = spectrumInfo.detector(wsIndex);
auto par = ws.constInstrumentParameters().getRecursive(&det, "Efixed");
if (par) {
efixed = par->value<double>();
g_log.debug() << "Detector: " << det.getID() << " EFixed: " << efixed << "\n";
pmap[UnitConversionParameters::efixed] = par->value<double>();
g_log.debug() << "Detector: " << det.getID()
<< " EFixed: " << pmap[UnitConversionParameters::efixed]
<< "\n";
}
}
// Non-unique detector (i.e., DetectorGroup): use single provided value
}
if (emode == 0) { // elastic
auto detids = ws.getSpectrum(wsIndex).getDetectorIDs();
if (detids.size() > 0) {
std::vector<detid_t> warnDetIds;
auto [difa, difc, tzero] =
ws.spectrumInfo().diffractometerConstants(wsIndex, warnDetIds);
pmap[UnitConversionParameters::difa] = difa;
pmap[UnitConversionParameters::difc] = difc;
pmap[UnitConversionParameters::tzero] = tzero;
if (warnDetIds.size() > 0) {
createDetectorIdLogMessages(warnDetIds, wsIndex);
}
}
}
} else {
twoTheta = 0.0;
efixed = DBL_MIN;
pmap[UnitConversionParameters::efixed] = DBL_MIN;
// Energy transfer is meaningless for a monitor, so set l2 to 0.
if (outputUnit.unitID().find("DeltaE") != std::string::npos) {
l2 = 0.0;
......@@ -492,16 +533,20 @@ MatrixWorkspace_sptr ConvertUnits::convertViaTOF(Kernel::Unit_const_sptr fromUni
double checkefixed = efixedProp;
double checkl2;
double checktwoTheta;
const double checkdelta = 0.0;
ExtraParametersMap pmap = {{UnitConversionParameters::efixed, checkefixed},
{UnitConversionParameters::delta, checkdelta}};
size_t checkIndex = 0;
if (getDetectorValues(spectrumInfo, *outputUnit, emode, *inputWS, signedTheta, checkIndex, checkefixed, checkl2,
checktwoTheta)) {
const double checkdelta = 0.0;
if (getDetectorValues(spectrumInfo, *outputUnit, emode, *inputWS, signedTheta,
checkIndex, checkl2, checktwoTheta, pmap)) {
// copy the X values for the check
auto checkXValues = inputWS->readX(checkIndex);
// Convert the input unit to time-of-flight
localFromUnit->toTOF(checkXValues, emptyVec, l1, checkl2, checktwoTheta, emode, checkefixed, checkdelta);
localFromUnit->toTOF(checkXValues, emptyVec, l1, checkl2, checktwoTheta,
emode, pmap);
// Convert from time-of-flight to the desired unit
localOutputUnit->fromTOF(checkXValues, emptyVec, l1, checkl2, checktwoTheta, emode, checkefixed, checkdelta);
localOutputUnit->fromTOF(checkXValues, emptyVec, l1, checkl2, checktwoTheta,
emode, pmap);
}
// create the output workspace
......@@ -517,15 +562,19 @@ MatrixWorkspace_sptr ConvertUnits::convertViaTOF(Kernel::Unit_const_sptr fromUni
// Now get the detector object for this histogram
double l2;
double twoTheta;
if (getDetectorValues(outSpectrumInfo, *outputUnit, emode, *outputWS, signedTheta, i, efixed, l2, twoTheta)) {
/// @todo Don't yet consider hold-off (delta)
const double delta = 0.0;
// TODO toTOF and fromTOF need to be reimplemented outside of kernel
localFromUnit->toTOF(outputWS->dataX(i), emptyVec, l1, l2, twoTheta, emode, efixed, delta);
/// @todo Don't yet consider hold-off (delta)
const double delta = 0.0;
// TODO toTOF and fromTOF need to be reimplemented outside of kernel
ExtraParametersMap pmap = {{UnitConversionParameters::efixed, efixed},
{UnitConversionParameters::delta, delta}};
if (getDetectorValues(outSpectrumInfo, *outputUnit, emode, *outputWS,
signedTheta, i, l2, twoTheta, pmap)) {
localFromUnit->toTOF(outputWS->dataX(i), emptyVec, l1, l2, twoTheta,
emode, pmap);
// Convert from time-of-flight to the desired unit
localOutputUnit->fromTOF(outputWS->dataX(i), emptyVec, l1, l2, twoTheta, emode, efixed, delta);
localOutputUnit->fromTOF(outputWS->dataX(i), emptyVec, l1, l2, twoTheta,
emode, pmap);
// EventWorkspace part, modifying the EventLists.
if (m_inputEvents) {
......
......@@ -149,13 +149,15 @@ MatrixWorkspace_sptr ConvertUnitsUsingDetectorTable::convertViaTOF(Kernel::Unit_
// Convert the input unit to time-of-flight
auto checkFromUnit = std::unique_ptr<Unit>(fromUnit->clone());
auto checkOutputUnit = std::unique_ptr<Unit>(outputUnit->clone());
double checkdelta = 0;
checkFromUnit->toTOF(checkXValues, emptyVec, l1Column[detectorRow], l2Column[detectorRow],
twoThetaColumn[detectorRow], emodeColumn[detectorRow], efixedColumn[detectorRow], checkdelta);
ExtraParametersMap pmap{
{UnitConversionParameters::efixed, efixedColumn[detectorRow]}};
checkFromUnit->toTOF(checkXValues, emptyVec, l1Column[detectorRow],
l2Column[detectorRow], twoThetaColumn[detectorRow],
emodeColumn[detectorRow], pmap);
// Convert from time-of-flight to the desired unit
checkOutputUnit->fromTOF(checkXValues, emptyVec, l1Column[detectorRow], l2Column[detectorRow],
twoThetaColumn[detectorRow], emodeColumn[detectorRow], efixedColumn[detectorRow],
checkdelta);
checkOutputUnit->fromTOF(checkXValues, emptyVec, l1Column[detectorRow],
l2Column[detectorRow], twoThetaColumn[detectorRow],
emodeColumn[detectorRow], pmap);
}
// create the output workspace
......@@ -208,13 +210,15 @@ MatrixWorkspace_sptr ConvertUnitsUsingDetectorTable::convertViaTOF(Kernel::Unit_
auto localFromUnit = std::unique_ptr<Unit>(fromUnit->clone());
auto localOutputUnit = std::unique_ptr<Unit>(outputUnit->clone());
/// @todo Don't yet consider hold-off (delta)
const double delta = 0.0;
std::vector<double> values(outputWS->x(wsid).begin(), outputWS->x(wsid).end());
std::vector<double> values(outputWS->x(wsid).begin(),
outputWS->x(wsid).end());
ExtraParametersMap pmap{{UnitConversionParameters::efixed, efixed}};
// Convert the input unit to time-of-flight
localFromUnit->toTOF(values, emptyVec, l1, l2, twoTheta, emode, efixed, delta);
localFromUnit->toTOF(values, emptyVec, l1, l2, twoTheta, emode, pmap);
// Convert from time-of-flight to the desired unit
localOutputUnit->fromTOF(values, emptyVec, l1, l2, twoTheta, emode, efixed, delta);
localOutputUnit->fromTOF(values, emptyVec, l1, l2, twoTheta, emode,
pmap);