diff --git a/Framework/Algorithms/CMakeLists.txt b/Framework/Algorithms/CMakeLists.txt index 3a44091c90bf..636dea4819e7 100644 --- a/Framework/Algorithms/CMakeLists.txt +++ b/Framework/Algorithms/CMakeLists.txt @@ -5,7 +5,6 @@ set(SRC_FILES src/AddPeak.cpp src/AddSampleLog.cpp src/AddTimeSeriesLog.cpp - src/AlignDetectors.cpp src/AnnularRingAbsorption.cpp src/AnyShapeAbsorption.cpp src/ApodizationFunctions.cpp @@ -355,7 +354,6 @@ set(INC_FILES inc/MantidAlgorithms/AddPeak.h inc/MantidAlgorithms/AddSampleLog.h inc/MantidAlgorithms/AddTimeSeriesLog.h - inc/MantidAlgorithms/AlignDetectors.h inc/MantidAlgorithms/AnnularRingAbsorption.h inc/MantidAlgorithms/AnyShapeAbsorption.h inc/MantidAlgorithms/ApodizationFunctions.h @@ -712,7 +710,6 @@ set(TEST_FILES AddPeakTest.h AddSampleLogTest.h AddTimeSeriesLogTest.h - AlignDetectorsTest.h AnnularRingAbsorptionTest.h AnyShapeAbsorptionTest.h AppendSpectraTest.h diff --git a/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h b/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h deleted file mode 100644 index e94927c2d12b..000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h +++ /dev/null @@ -1,77 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/DeprecatedAlgorithm.h" -#include "MantidAPI/ITableWorkspace_fwd.h" -#include "MantidAlgorithms/DllConfig.h" -#include "MantidDataObjects/OffsetsWorkspace.h" - -namespace Mantid { - -namespace DataObjects { -class EventWorkspace; -} - -namespace Algorithms { - -namespace { -class ConversionFactors; -} - -/** Performs a unit change from TOF to dSpacing, correcting the X values to - account for small - errors in the detector positions. - - Required Properties: - - - @author Russell Taylor, Tessella Support Services plc - @date 18/08/2008 -*/ -class MANTID_ALGORITHMS_DLL AlignDetectors final : public API::Algorithm, public API::DeprecatedAlgorithm { -public: - AlignDetectors(); - - /// Algorithms name for identification. @see Algorithm::name - const std::string name() const override; - /// Algorithm's summary for use in the GUI and help. @see Algorithm::summary - const std::string summary() const override; - - /// Algorithm's version for identification. @see Algorithm::version - int version() const override; - const std::vector seeAlso() const override { return {"DiffractionFocussing", "AlignAndFocusPowder"}; } - /// Algorithm's category for identification. @see Algorithm::category - const std::string category() const override; - /// Cross-check properties with each other @see IAlgorithm::validateInputs - std::map validateInputs() override; - -private: - // Implement abstract Algorithm methods - void init() override; - void exec() override; - - 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); - - Mantid::API::ITableWorkspace_sptr m_calibrationWS; - - /// number of spectra in input workspace - int64_t m_numberOfSpectra; -}; - -} // namespace Algorithms -} // namespace Mantid diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CreateCalFileByNames.h b/Framework/Algorithms/inc/MantidAlgorithms/CreateCalFileByNames.h index 5aefbe4032d1..c66f60066bb9 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/CreateCalFileByNames.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/CreateCalFileByNames.h @@ -22,8 +22,8 @@ namespace Algorithms { * The offsets are all sets to zero and all detectors are selected. Detectors not assigned * to any group will appear as group 0, i.e. not included when using - AlignDetector or - * DiffractionFocussing algorithms. + the + * DiffractionFocussing algorithm. * The group number is assigned based on a descent in the instrument tree assembly. * If two assemblies are parented, say Bank1 and module1, and both assembly @@ -59,7 +59,7 @@ class MANTID_ALGORITHMS_DLL CreateCalFileByNames final : public API::Algorithm { /// Algorithm's version int version() const override { return (1); } const std::vector seeAlso() const override { - return {"ReadGroupsFromFile", "CreateDummyCalFile", "AlignDetectors", "DiffractionFocussing", + return {"ReadGroupsFromFile", "CreateDummyCalFile", "DiffractionFocussing", "LoadCalFile", "SaveCalFile", "MergeCalFiles"}; } /// Algorithm's category for identification diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CreateDummyCalFile.h b/Framework/Algorithms/inc/MantidAlgorithms/CreateDummyCalFile.h index 0d9e6f252e5b..4bc9828351f7 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/CreateDummyCalFile.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/CreateDummyCalFile.h @@ -18,7 +18,7 @@ namespace Algorithms { * The offsets are all sets to zero and all detectors are selected. Detectors not assigned * to any group will appear as group 0, i.e. not included when using - AlignDetector or +the * DiffractionFocussing algorithms. * The group number is assigned based on a descent in the instrument tree assembly. @@ -58,7 +58,7 @@ class MANTID_ALGORITHMS_DLL CreateDummyCalFile final : public API::Algorithm { /// Algorithm's version int version() const override { return (1); } const std::vector seeAlso() const override { - return {"ReadGroupsFromFile", "CreateCalFileByNames", "AlignDetectors", "DiffractionFocussing", + return {"ReadGroupsFromFile", "CreateCalFileByNames", "DiffractionFocussing", "LoadCalFile", "SaveCalFile", "MergeCalFiles"}; } /// Algorithm's category for identification diff --git a/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h b/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h index 734ecabcabed..7c1cd80645b5 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h @@ -29,7 +29,7 @@ namespace Algorithms { detector, the third column corresponds to an offset in Deltad/d (not applied, usually applied using - the AlignDetectors algorithm). The forth column is a flag to indicate whether + the ConvertUnits algorithm). The forth column is a flag to indicate whether the detector is selected. The fifth column indicates the group this detector belongs to (number >=1), @@ -74,9 +74,7 @@ class MANTID_ALGORITHMS_DLL DiffractionFocussing2 final : public API::Algorithm /// Algorithm's version for identification overriding a virtual method int version() const override { return 2; } - const std::vector seeAlso() const override { - return {"AlignDetectors", "AlignAndFocusPowder", "LoadCalFile"}; - } + const std::vector seeAlso() const override { return {"AlignAndFocusPowder", "LoadCalFile"}; } /// Algorithm's category for identification overriding a virtual method const std::string category() const override { return "Diffraction\\Focussing"; } diff --git a/Framework/Algorithms/inc/MantidAlgorithms/ReadGroupsFromFile.h b/Framework/Algorithms/inc/MantidAlgorithms/ReadGroupsFromFile.h index 3cd4172e0eaa..60c79e895468 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/ReadGroupsFromFile.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/ReadGroupsFromFile.h @@ -35,9 +35,8 @@ namespace Algorithms { * 4 621 0.0000000 1 0 * The first column is simply an index, the second is a UDET identifier for the detector, - * the third column corresponds to an offset in Deltad/d (not applied, usually - applied using - * the AlignDetectors algorithm). The forth column is a flag to indicate + * the third column corresponds to an offset in Deltad/d (not applied, this can be interpreted by the ApplyDiffCal + * algorithm). The forth column is a flag to indicate whether the detector * is selected. The fifth column indicates the group this detector belongs to (number >=1), @@ -76,7 +75,7 @@ class MANTID_ALGORITHMS_DLL ReadGroupsFromFile final : public API::Algorithm { /// Algorithm's version int version() const override { return (1); } const std::vector seeAlso() const override { - return {"CreateDummyCalFile", "CreateCalFileByNames", "AlignDetectors", "DiffractionFocussing", + return {"CreateDummyCalFile", "CreateCalFileByNames", "DiffractionFocussing", "LoadCalFile", "SaveCalFile", "MergeCalFiles"}; } /// Algorithm's category for identification diff --git a/Framework/Algorithms/src/AlignDetectors.cpp b/Framework/Algorithms/src/AlignDetectors.cpp deleted file mode 100644 index 1164705030a1..000000000000 --- a/Framework/Algorithms/src/AlignDetectors.cpp +++ /dev/null @@ -1,311 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAlgorithms/AlignDetectors.h" - -#include "MantidAPI/Axis.h" -#include "MantidAPI/FileProperty.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/RawCountValidator.h" -#include "MantidAPI/WorkspaceUnitValidator.h" -#include "MantidDataObjects/EventWorkspace.h" -#include "MantidDataObjects/OffsetsWorkspace.h" -#include "MantidKernel/CompositeValidator.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidKernel/UnitFactory.h" -#include "MantidKernel/V3D.h" - -#include -#include -#include - -using namespace Mantid::Kernel; -using namespace Mantid::API; -using namespace Mantid::Geometry; -using namespace Mantid::DataObjects; -using namespace Mantid::HistogramData; -using Mantid::DataObjects::OffsetsWorkspace; - -namespace Mantid::Algorithms { -// Register the algorithm into the algorithm factory -DECLARE_ALGORITHM(AlignDetectors) - -namespace { // anonymous namespace - -class ConversionFactors { -public: - explicit ConversionFactors(const ITableWorkspace_const_sptr &table) - : m_difcCol(table->getColumn("difc")), m_difaCol(table->getColumn("difa")), - m_tzeroCol(table->getColumn("tzero")) { - this->generateDetidToRow(table); - } - - std::tuple getDiffConstants(const std::set &detIds) const { - const std::set rows = this->getRow(detIds); - double difc = 0.; - double difa = 0.; - double tzero = 0.; - for (auto row : rows) { - difc += m_difcCol->toDouble(row); - difa += m_difaCol->toDouble(row); - tzero += m_tzeroCol->toDouble(row); - } - if (rows.size() > 1) { - double norm = 1. / static_cast(rows.size()); - difc = norm * difc; - difa = norm * difa; - tzero = norm * tzero; - } - - return {difc, difa, tzero}; - } - -private: - void generateDetidToRow(const ITableWorkspace_const_sptr &table) { - ConstColumnVector detIDs = table->getVector("detid"); - const size_t numDets = detIDs.size(); - for (size_t i = 0; i < numDets; ++i) { - m_detidToRow[static_cast(detIDs[i])] = i; - } - } - - std::set getRow(const std::set &detIds) const { - std::set rows; - for (auto detId : detIds) { - auto rowIter = m_detidToRow.find(detId); - if (rowIter != m_detidToRow.end()) { // skip if not found - rows.insert(rowIter->second); - } - } - if (rows.empty()) { - std::string detIdsStr = std::accumulate(std::begin(detIds), std::end(detIds), std::string{}, - [](const std::string &a, const detid_t &b) { - return a.empty() ? std::to_string(b) : a + ',' + std::to_string(b); - }); - throw Exception::NotFoundError("None of the detectors were found in the calibration table", detIdsStr); - } - return rows; - } - - std::map m_detidToRow; - Column_const_sptr m_difcCol; - Column_const_sptr m_difaCol; - Column_const_sptr m_tzeroCol; -}; -} // anonymous namespace - -const std::string AlignDetectors::name() const { return "AlignDetectors"; } - -int AlignDetectors::version() const { return 1; } - -const std::string AlignDetectors::category() const { return "Diffraction\\Calibration"; } - -const std::string AlignDetectors::summary() const { - return "Performs a unit change from TOF to dSpacing, correcting the X " - "values to account for small errors in the detector positions."; -} - -/// Constructor -AlignDetectors::AlignDetectors() : m_numberOfSpectra(0) { - useAlgorithm("ConvertUnits"); - deprecatedDate("2021-01-04"); -} - -void AlignDetectors::init() { - auto wsValidator = std::make_shared(); - // Workspace unit must be TOF. - wsValidator->add("TOF"); - wsValidator->add(); - - declareProperty( - std::make_unique>("InputWorkspace", "", Direction::Input, wsValidator), - "A workspace with units of TOF"); - - declareProperty(std::make_unique>("OutputWorkspace", "", Direction::Output), - "The name to use for the output workspace"); - - const std::vector exts{".h5", ".hd5", ".hdf", ".cal"}; - declareProperty(std::make_unique("CalibrationFile", "", FileProperty::OptionalLoad, exts), - "Optional: The .cal file containing the position correction factors. " - "Either this or OffsetsWorkspace needs to be specified."); - - declareProperty(std::make_unique>("CalibrationWorkspace", "", Direction::Input, - PropertyMode::Optional), - "Optional: A Workspace containing the calibration information. Either " - "this or CalibrationFile needs to be specified."); - - declareProperty(std::make_unique>("OffsetsWorkspace", "", Direction::Input, - PropertyMode::Optional), - "Optional: A OffsetsWorkspace containing the calibration offsets. Either " - "this or CalibrationFile needs to be specified."); - - // make group associations. - std::string calibrationGroup("Calibration"); - setPropertyGroup("CalibrationFile", calibrationGroup); - setPropertyGroup("CalibrationWorkspace", calibrationGroup); - setPropertyGroup("OffsetsWorkspace", calibrationGroup); -} - -std::map AlignDetectors::validateInputs() { - std::map result; - - int numWays = 0; - - const std::string calFileName = getProperty("CalibrationFile"); - if (!calFileName.empty()) - numWays += 1; - - ITableWorkspace_const_sptr calibrationWS = getProperty("CalibrationWorkspace"); - if (bool(calibrationWS)) - numWays += 1; - - OffsetsWorkspace_const_sptr offsetsWS = getProperty("OffsetsWorkspace"); - if (bool(offsetsWS)) - numWays += 1; - - std::string message; - if (numWays == 0) { - message = "You must specify only one of CalibrationFile, " - "CalibrationWorkspace, OffsetsWorkspace."; - } - if (numWays > 1) { - message = "You must specify one of CalibrationFile, " - "CalibrationWorkspace, OffsetsWorkspace."; - } - - if (!message.empty()) { - result["CalibrationFile"] = message; - result["CalibrationWorkspace"] = message; - } - - return result; -} - -void AlignDetectors::loadCalFile(const MatrixWorkspace_sptr &inputWS, const std::string &filename) { - auto alg = createChildAlgorithm("LoadDiffCal"); - alg->setProperty("InputWorkspace", inputWS); - alg->setPropertyValue("Filename", filename); - alg->setProperty("MakeCalWorkspace", true); - alg->setProperty("MakeGroupingWorkspace", false); - alg->setProperty("MakeMaskWorkspace", false); - alg->setPropertyValue("WorkspaceName", "temp"); - alg->executeAsChildAlg(); - - m_calibrationWS = alg->getProperty("OutputCalWorkspace"); -} - -void AlignDetectors::getCalibrationWS(const MatrixWorkspace_sptr &inputWS) { - m_calibrationWS = getProperty("CalibrationWorkspace"); - if (m_calibrationWS) - return; // nothing more to do - - OffsetsWorkspace_sptr offsetsWS = getProperty("OffsetsWorkspace"); - if (offsetsWS) { - auto alg = createChildAlgorithm("ConvertDiffCal"); - alg->setProperty("OffsetsWorkspace", offsetsWS); - alg->executeAsChildAlg(); - m_calibrationWS = alg->getProperty("OutputWorkspace"); - m_calibrationWS->setTitle(offsetsWS->getTitle()); - return; - } - - const std::string calFileName = getPropertyValue("CalibrationFile"); - if (!calFileName.empty()) { - progress(0.0, "Reading calibration file"); - loadCalFile(inputWS, calFileName); - return; - } - - throw std::runtime_error("Failed to determine calibration information"); -} - -void setXAxisUnits(const API::MatrixWorkspace_sptr &outputWS) { - outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("dSpacing"); -} - -/** Executes the algorithm - * @throw Exception::FileError If the calibration file cannot be opened and - * read successfully - * @throw Exception::InstrumentDefinitionError If unable to obtain the - * source-sample distance - */ -void AlignDetectors::exec() { - // Get the input workspace - MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); - - this->getCalibrationWS(inputWS); - - // Initialise the progress reporting object - m_numberOfSpectra = static_cast(inputWS->getNumberHistograms()); - - API::MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); - // If input and output workspaces are not the same, create a new workspace for - // the output - if (outputWS != inputWS) { - outputWS = inputWS->clone(); - setProperty("OutputWorkspace", outputWS); - } - - // Set the final unit that our output workspace will have - setXAxisUnits(outputWS); - - ConversionFactors converter = ConversionFactors(m_calibrationWS); - - Progress progress(this, 0.0, 1.0, m_numberOfSpectra); - - align(converter, progress, outputWS); -} - -void AlignDetectors::align(const ConversionFactors &converter, Progress &progress, MatrixWorkspace_sptr &outputWS) { - auto eventW = std::dynamic_pointer_cast(outputWS); - PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS)) - for (int64_t i = 0; i < m_numberOfSpectra; ++i) { - PARALLEL_START_INTERRUPT_REGION - try { - // Get the input spectrum number at this workspace index - auto &spec = outputWS->getSpectrum(size_t(i)); - auto [difc, difa, tzero] = converter.getDiffConstants(spec.getDetectorIDs()); - - auto &x = outputWS->dataX(i); - Kernel::Units::dSpacing dSpacingUnit; - std::vector yunused; - dSpacingUnit.fromTOF(x, yunused, -1., 0, - UnitParametersMap{{Kernel::UnitParams::difa, difa}, - {Kernel::UnitParams::difc, difc}, - {Kernel::UnitParams::tzero, tzero}}); - - if (eventW) { - Kernel::Units::TOF tofUnit; - tofUnit.initialize(0, 0, {}); - // EventWorkspace part, modifying the EventLists. - eventW->getSpectrum(i).convertUnitsViaTof(&tofUnit, &dSpacingUnit); - } - } catch (const std::runtime_error &) { - if (!eventW) { - // Zero the data in this case (detectors not found in cal table or - // conversion fails) - outputWS->setHistogram(i, BinEdges(outputWS->x(i).size()), Counts(outputWS->y(i).size())); - } - } - progress.report(); - PARALLEL_END_INTERRUPT_REGION - } - PARALLEL_CHECK_INTERRUPT_REGION - 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(); - } -} -} // namespace Mantid::Algorithms diff --git a/Framework/Algorithms/test/AlignDetectorsTest.h b/Framework/Algorithms/test/AlignDetectorsTest.h deleted file mode 100644 index 1a70ee2707bb..000000000000 --- a/Framework/Algorithms/test/AlignDetectorsTest.h +++ /dev/null @@ -1,169 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "MantidFrameworkTestHelpers/WorkspaceCreationHelper.h" -#include - -#include "MantidAPI/Axis.h" -#include "MantidAlgorithms/AlignDetectors.h" -#include "MantidDataHandling/LoadNexus.h" -#include "MantidDataObjects/EventWorkspace.h" -#include "MantidKernel/Unit.h" - -using namespace Mantid::Algorithms; -using namespace Mantid::DataHandling; -using namespace Mantid::DataObjects; -using namespace Mantid::Kernel; -using namespace Mantid::API; - -class AlignDetectorsTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static AlignDetectorsTest *createSuite() { return new AlignDetectorsTest(); } - static void destroySuite(AlignDetectorsTest *suite) { delete suite; } - - /** Setup for loading Nexus data */ - void setUp_HRP38692() { - - LoadNexus loader; - loader.initialize(); - loader.setPropertyValue("Filename", "HRP38692a.nxs"); - inputWS = "nexusWS"; - loader.setPropertyValue("OutputWorkspace", inputWS); - loader.execute(); - } - - void testTheBasics() { - TS_ASSERT_EQUALS(align.name(), "AlignDetectors"); - TS_ASSERT_EQUALS(align.version(), 1); - } - - void testInit() { - TS_ASSERT_THROWS_NOTHING(align.initialize()); - TS_ASSERT(align.isInitialized()); - } - - /** Test alignDetectors for a Workspace2D loaded from some - * raw data file. - */ - void testExecWorkspace2D() { - setUp_HRP38692(); - if (!align.isInitialized()) - align.initialize(); - - TS_ASSERT_THROWS(align.execute(), const std::runtime_error &); - - align.setPropertyValue("InputWorkspace", inputWS); - const std::string outputWS = "aligned"; - align.setPropertyValue("OutputWorkspace", outputWS); - align.setPropertyValue("CalibrationFile", "hrpd_new_072_01.cal"); - - TS_ASSERT_THROWS_NOTHING(align.execute()); - TS_ASSERT(align.isExecuted()); - - std::shared_ptr inWS = AnalysisDataService::Instance().retrieveWS(inputWS); - std::shared_ptr outWS = AnalysisDataService::Instance().retrieveWS(outputWS); - - TS_ASSERT_EQUALS(outWS->getAxis(0)->unit()->unitID(), "dSpacing"); - TS_ASSERT_EQUALS(outWS->size(), inWS->size()); - TS_ASSERT_EQUALS(outWS->blocksize(), inWS->blocksize()); - - TS_ASSERT_DELTA(outWS->x(2)[50], 0.7223, 0.0001); - TS_ASSERT_EQUALS(outWS->y(2)[50], inWS->y(1)[50]); - TS_ASSERT_EQUALS(outWS->y(2)[50], inWS->y(1)[50]); - - for (size_t i = 0; i < outWS->getNumberHistograms(); i++) { - TS_ASSERT_EQUALS(outWS->getSpectrum(i).getSpectrumNo(), inWS->getSpectrum(i).getSpectrumNo()); - TS_ASSERT_EQUALS(outWS->getSpectrum(i).getDetectorIDs().size(), inWS->getSpectrum(i).getDetectorIDs().size()); - TS_ASSERT_EQUALS(*outWS->getSpectrum(i).getDetectorIDs().begin(), *inWS->getSpectrum(i).getDetectorIDs().begin()); - } - - AnalysisDataService::Instance().remove(outputWS); - } - - /** Setup for loading raw data */ - void setUp_Event() { - inputWS = "eventWS"; - EventWorkspace_sptr ws = WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(1, 10, false); - ws->getAxis(0)->setUnit("TOF"); - AnalysisDataService::Instance().addOrReplace(inputWS, ws); - } - - void testExecEventWorkspace_sameOutputWS() { - this->setUp_Event(); - std::size_t wkspIndex = 1; // a good workspace index (with events) - - // Retrieve Workspace - WS = AnalysisDataService::Instance().retrieveWS(inputWS); - TS_ASSERT(WS); // workspace is loaded - size_t start_blocksize = WS->blocksize(); - size_t num_events = WS->getNumberEvents(); - double a_tof = WS->getSpectrum(wkspIndex).getEvents()[0].tof(); - - // Start by init'ing the algorithm - TS_ASSERT_THROWS_NOTHING(align.initialize()); - TS_ASSERT(align.isInitialized()); - - // Set all the properties - align.setPropertyValue("InputWorkspace", inputWS); - const std::string outputWS = inputWS; - align.setPropertyValue("OutputWorkspace", outputWS); - align.setPropertyValue("CalibrationFile", "refl_fake.cal"); - - TS_ASSERT_THROWS_NOTHING(align.execute()); - TS_ASSERT(align.isExecuted()); - - // WS hasn;t changed - - // Things that haven't changed - TS_ASSERT_EQUALS(start_blocksize, WS->blocksize()); - TS_ASSERT_EQUALS(num_events, WS->getNumberEvents()); - // But a TOF changed. - TS_ASSERT_DIFFERS(a_tof, WS->getSpectrum(wkspIndex).getEvents()[0].tof()); - } - - void testExecEventWorkspace_differentOutputWS() { - this->setUp_Event(); - std::size_t wkspIndex = 1; // a good workspace index (with events) - - // Retrieve Workspace - WS = AnalysisDataService::Instance().retrieveWS(inputWS); - TS_ASSERT(WS); // workspace is loaded - - // Start by init'ing the algorithm - TS_ASSERT_THROWS_NOTHING(align.initialize()); - TS_ASSERT(align.isInitialized()); - - // Set all the properties - align.setPropertyValue("InputWorkspace", inputWS); - const std::string outputWS = "eventWS_changed"; - align.setPropertyValue("OutputWorkspace", outputWS); - align.setPropertyValue("CalibrationFile", "refl_fake.cal"); - - TS_ASSERT_THROWS_NOTHING(align.execute()); - TS_ASSERT(align.isExecuted()); - - // Retrieve Workspace changed - EventWorkspace_sptr outWS; - outWS = AnalysisDataService::Instance().retrieveWS(outputWS); - TS_ASSERT(outWS); // workspace is loaded - - // Things that haven't changed - TS_ASSERT_EQUALS(outWS->blocksize(), WS->blocksize()); - TS_ASSERT_EQUALS(outWS->getNumberEvents(), WS->getNumberEvents()); - // But a TOF changed. - TS_ASSERT_DIFFERS(outWS->getSpectrum(wkspIndex).getEvents()[0].tof(), - WS->getSpectrum(wkspIndex).getEvents()[0].tof()); - } - -private: - AlignDetectors align; - std::string inputWS; - EventWorkspace_sptr WS; -}; diff --git a/Framework/Algorithms/test/DiffractionFocussing2Test.h b/Framework/Algorithms/test/DiffractionFocussing2Test.h index 34929f024d1b..5321799acf23 100644 --- a/Framework/Algorithms/test/DiffractionFocussing2Test.h +++ b/Framework/Algorithms/test/DiffractionFocussing2Test.h @@ -8,10 +8,11 @@ #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/SpectraAxis.h" -#include "MantidAlgorithms/AlignDetectors.h" +#include "MantidAlgorithms/ConvertUnits.h" #include "MantidAlgorithms/DiffractionFocussing2.h" #include "MantidAlgorithms/MaskBins.h" #include "MantidAlgorithms/Rebin.h" +#include "MantidDataHandling/ApplyDiffCal.h" #include "MantidDataHandling/LoadNexus.h" #include "MantidDataHandling/LoadRaw3.h" #include "MantidDataObjects/EventWorkspace.h" @@ -52,14 +53,22 @@ class DiffractionFocussing2Test : public CxxTest::TestSuite { TS_ASSERT_THROWS_NOTHING(loader.execute()); TS_ASSERT(loader.isExecuted()); - // Have to align because diffraction focussing wants d-spacing - Mantid::Algorithms::AlignDetectors align; - align.initialize(); - align.setPropertyValue("InputWorkspace", outputSpace); - align.setPropertyValue("OutputWorkspace", outputSpace); - align.setPropertyValue("CalibrationFile", "hrpd_new_072_01.cal"); - TS_ASSERT_THROWS_NOTHING(align.execute()); - TS_ASSERT(align.isExecuted()); + Mantid::DataHandling::ApplyDiffCal applyDiffCal; + applyDiffCal.setChild(true); + applyDiffCal.initialize(); + applyDiffCal.setPropertyValue("InstrumentWorkspace", outputSpace); + applyDiffCal.setPropertyValue("CalibrationFile", "hrpd_new_072_01.cal"); + TS_ASSERT_THROWS_NOTHING(applyDiffCal.execute()); + TS_ASSERT(applyDiffCal.isExecuted()); + + // Have to convert because diffraction focussing wants d-spacing + Mantid::Algorithms::ConvertUnits convert; + convert.initialize(); + convert.setPropertyValue("InputWorkspace", outputSpace); + convert.setPropertyValue("OutputWorkspace", outputSpace); + convert.setPropertyValue("Target", "dSpacing"); + TS_ASSERT_THROWS_NOTHING(convert.execute()); + TS_ASSERT(convert.isExecuted()); focus.setPropertyValue("InputWorkspace", outputSpace); focus.setPropertyValue("OutputWorkspace", "focusedWS"); diff --git a/Framework/DataHandling/inc/MantidDataHandling/ApplyDiffCal.h b/Framework/DataHandling/inc/MantidDataHandling/ApplyDiffCal.h index 2e52c24e5573..05f6421e1cb9 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/ApplyDiffCal.h +++ b/Framework/DataHandling/inc/MantidDataHandling/ApplyDiffCal.h @@ -21,9 +21,7 @@ class MANTID_DATAHANDLING_DLL ApplyDiffCal final : public API::Algorithm { public: const std::string name() const override; int version() const override; - const std::vector seeAlso() const override { - return {"AlignDetectors", "ConvertDiffCal", "ConvertUnits", "LoadDiffCal"}; - } + const std::vector seeAlso() const override { return {"ConvertDiffCal", "ConvertUnits", "LoadDiffCal"}; } const std::string category() const override; const std::string summary() const override; /// Cross-check properties with each other @see IAlgorithm::validateInputs diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadCalFile.h b/Framework/DataHandling/inc/MantidDataHandling/LoadCalFile.h index fb56056e29a5..0e34d5c4d44c 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadCalFile.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadCalFile.h @@ -37,8 +37,8 @@ class MANTID_DATAHANDLING_DLL LoadCalFile final : public API::Algorithm { /// Algorithm's version for identification int version() const override { return 1; }; const std::vector seeAlso() const override { - return {"LoadDiffCal", "ReadGroupsFromFile", "CreateDummyCalFile", "CreateCalFileByNames", - "AlignDetectors", "DiffractionFocussing", "SaveCalFile", "MergeCalFiles"}; + return {"LoadDiffCal", "ReadGroupsFromFile", "CreateDummyCalFile", "CreateCalFileByNames", + "DiffractionFocussing", "SaveCalFile", "MergeCalFiles"}; } /// Algorithm's category for identification const std::string category() const override { return R"(DataHandling\Text;Diffraction\DataHandling\CalFiles)"; } diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveCalFile.h b/Framework/DataHandling/inc/MantidDataHandling/SaveCalFile.h index 7ad72cdcada2..54b88d098385 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveCalFile.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveCalFile.h @@ -35,8 +35,8 @@ class MANTID_DATAHANDLING_DLL SaveCalFile final : public API::Algorithm { /// Algorithm's version for identification int version() const override { return 1; }; const std::vector seeAlso() const override { - return {"SaveDiffCal", "ReadGroupsFromFile", "CreateDummyCalFile", "CreateCalFileByNames", - "AlignDetectors", "DiffractionFocussing", "LoadCalFile", "MergeCalFiles"}; + return {"SaveDiffCal", "ReadGroupsFromFile", "CreateDummyCalFile", "CreateCalFileByNames", + "DiffractionFocussing", "LoadCalFile", "MergeCalFiles"}; } /// Algorithm's category for identification const std::string category() const override { return R"(DataHandling\Text;Diffraction\DataHandling\CalFiles)"; } diff --git a/Framework/DataHandling/src/SaveGDA.cpp b/Framework/DataHandling/src/SaveGDA.cpp index 629a0c155a95..25e70e221451 100644 --- a/Framework/DataHandling/src/SaveGDA.cpp +++ b/Framework/DataHandling/src/SaveGDA.cpp @@ -93,7 +93,7 @@ const std::string SaveGDA::summary() const { int SaveGDA::version() const { return 1; } -const std::vector SaveGDA::seeAlso() const { return {"SaveBankScatteringAngles", "AlignDetectors"}; } +const std::vector SaveGDA::seeAlso() const { return {"SaveBankScatteringAngles"}; } const std::string SaveGDA::category() const { return "DataHandling\\Text;Diffraction\\DataHandling"; } diff --git a/Framework/DataObjects/inc/MantidDataObjects/OffsetsWorkspace.h b/Framework/DataObjects/inc/MantidDataObjects/OffsetsWorkspace.h index 1c5340b7b447..b7e93c3ccaf3 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/OffsetsWorkspace.h +++ b/Framework/DataObjects/inc/MantidDataObjects/OffsetsWorkspace.h @@ -15,7 +15,7 @@ namespace DataObjects { /** An OffsetsWorkspace is a specialized Workspace2D where * the Y value at each pixel is the offset to be used for correcting - * calculations (specifically AlignDetectors). + * calculations. * * @author Janik Zikovsky * @date 2011-05-09 diff --git a/Framework/PythonInterface/plugins/algorithms/BASISCrystalDiffraction.py b/Framework/PythonInterface/plugins/algorithms/BASISCrystalDiffraction.py index 7150714e2e9f..04a69d2d440a 100644 --- a/Framework/PythonInterface/plugins/algorithms/BASISCrystalDiffraction.py +++ b/Framework/PythonInterface/plugins/algorithms/BASISCrystalDiffraction.py @@ -139,7 +139,7 @@ def summary(): @staticmethod def seeAlso(): - return ["AlignDetectors", "DiffractionFocussing", "SNSPowderReduction"] + return ["DiffractionFocussing", "SNSPowderReduction"] @staticmethod def _run_list(runs): diff --git a/Framework/PythonInterface/plugins/algorithms/BASISDiffraction.py b/Framework/PythonInterface/plugins/algorithms/BASISDiffraction.py index 3ae6bf4cdb3c..86c22683e84e 100644 --- a/Framework/PythonInterface/plugins/algorithms/BASISDiffraction.py +++ b/Framework/PythonInterface/plugins/algorithms/BASISDiffraction.py @@ -129,7 +129,7 @@ def summary(self): return DEPRECATION_NOTICE def seeAlso(self): - return ["AlignDetectors", "DiffractionFocussing", "SNSPowderReduction"] + return ["DiffractionFocussing", "SNSPowderReduction"] def PyInit(self): # Input validators diff --git a/Framework/PythonInterface/plugins/algorithms/EnggFocus.py b/Framework/PythonInterface/plugins/algorithms/EnggFocus.py index 0bce9a734d12..758348a96310 100644 --- a/Framework/PythonInterface/plugins/algorithms/EnggFocus.py +++ b/Framework/PythonInterface/plugins/algorithms/EnggFocus.py @@ -17,7 +17,7 @@ def category(self): return "Diffraction\\Engineering" def seeAlso(self): - return ["AlignDetectors", "DiffractionFocussing"] + return ["DiffractionFocussing"] def name(self): return "EnggFocus" diff --git a/Framework/PythonInterface/plugins/algorithms/MaskWorkspaceToCalFile.py b/Framework/PythonInterface/plugins/algorithms/MaskWorkspaceToCalFile.py index ae86ae3665b8..c7f8ac9e0965 100644 --- a/Framework/PythonInterface/plugins/algorithms/MaskWorkspaceToCalFile.py +++ b/Framework/PythonInterface/plugins/algorithms/MaskWorkspaceToCalFile.py @@ -33,7 +33,6 @@ def seeAlso(self): "ReadGroupsFromFile", "CreateDummyCalFile", "CreateCalFileByNames", - "AlignDetectors", "DiffractionFocussing", "LoadCalFile", "SaveCalFile", diff --git a/Framework/PythonInterface/plugins/algorithms/MergeCalFiles.py b/Framework/PythonInterface/plugins/algorithms/MergeCalFiles.py index 8e57d985cd1e..fd24d2059848 100644 --- a/Framework/PythonInterface/plugins/algorithms/MergeCalFiles.py +++ b/Framework/PythonInterface/plugins/algorithms/MergeCalFiles.py @@ -17,7 +17,6 @@ def seeAlso(self): "ReadGroupsFromFile", "CreateDummyCalFile", "CreateCalFileByNames", - "AlignDetectors", "DiffractionFocussing", "LoadCalFile", "SaveCalFile", diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CorelliPowderCalibrationCreate.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CorelliPowderCalibrationCreate.py index 74774a32d419..1bbb14dd03fc 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CorelliPowderCalibrationCreate.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CorelliPowderCalibrationCreate.py @@ -123,7 +123,7 @@ def category(self): return "Diffraction\\Reduction" def seeAlso(self): - return ["PDCalibration", "AlignDetectors", "AlignComponents"] + return ["PDCalibration", "AlignComponents"] def summary(self): return "Adjust bank positions and orientations to optimize peak determination in d-spacing" diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py index 8a27d5becf28..6286aa5a32ff 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py @@ -107,7 +107,7 @@ def summary(self): return "Performs a diffraction reduction for a set of raw run files for an ISIS indirect spectrometer" def seeAlso(self): - return ["AlignDetectors", "DiffractionFocussing", "SNSPowderReduction"] + return ["DiffractionFocussing", "SNSPowderReduction"] # ------------------------------------------------------------------------------ diff --git a/Testing/SystemTests/tests/framework/WishAnalysis.py b/Testing/SystemTests/tests/framework/WishAnalysis.py index 29ed81441cd0..b8d5e78ca11d 100644 --- a/Testing/SystemTests/tests/framework/WishAnalysis.py +++ b/Testing/SystemTests/tests/framework/WishAnalysis.py @@ -7,7 +7,7 @@ # pylint: disable=no-init import systemtesting from mantid.simpleapi import ( - AlignDetectors, + ApplyDiffCal, ConvertFromDistribution, ConvertToDistribution, ConvertUnits, @@ -64,9 +64,9 @@ def runTest(self): # align detectors ConvertUnits(InputWorkspace="w16748-1", OutputWorkspace="w16748-1", Target="TOF") ReplaceSpecialValues(InputWorkspace="w16748-1", OutputWorkspace="w16748-1", NaNValue="0", InfinityValue="0") - AlignDetectors( - InputWorkspace="w16748-1", OutputWorkspace="w16748-1", CalibrationFile="wish_grouping_noends2_no_offsets_nov2009.cal" - ) + ApplyDiffCal(InstrumentWorkspace="w16748-1", CalibrationFile="wish_grouping_noends2_no_offsets_nov2009.cal") + ConvertUnits(InputWorkspace="w16748-1", OutputWorkspace="w16748-1", Target="dSpacing") + ApplyDiffCal(InstrumentWorkspace="w16748-1", ClearCalibration=True) # focus data DiffractionFocussing( InputWorkspace="w16748-1", OutputWorkspace="w16748-1foc", GroupingFileName="wish_grouping_noends2_no_offsets_nov2009.cal" diff --git a/docs/source/algorithms/AlignComponents-v1.rst b/docs/source/algorithms/AlignComponents-v1.rst index f063c3084937..11795001924f 100644 --- a/docs/source/algorithms/AlignComponents-v1.rst +++ b/docs/source/algorithms/AlignComponents-v1.rst @@ -20,7 +20,7 @@ the absolute value of the fractional difference between the observed peak center for detector pixel :math:`i` and peak :math:`j`, :math:`DIFC_i * TOF_{i,j}`, and a reference experimental value for the d-spacing of peak :math:`j`, :math:`d^{exp}_j`. The conversion from peak center in TOF units (:math:`TOF_{i,j}`) to d-spacing units is carried out via the -geometrical parameter :math:`DIFC_i` -- see :ref:`algm-AlignDetectors` for more information +geometrical parameter :math:`DIFC_i` -- see :ref:`Unit Factory` for more information regarding this parameter. As we change the location and orientations of the instrument components during the minimization, the geometrical parameter :math:`DIFC_i` is bound to change. diff --git a/docs/source/algorithms/AlignDetectors-v1.rst b/docs/source/algorithms/AlignDetectors-v1.rst deleted file mode 100644 index bfa5e80ca869..000000000000 --- a/docs/source/algorithms/AlignDetectors-v1.rst +++ /dev/null @@ -1,93 +0,0 @@ -.. algorithm:: - -.. summary:: - -.. relatedalgorithms:: - -.. properties:: - -.. note:: As of 2021-01-04, this algorithm is officially deprecated. - As a result, developers and users are recommend to use - :ref:`ApplyDiffCal`, followed by - :ref:`ConvertUnits`, followed by - :ref:`ApplyDiffCal` (ClearCalibration=true) to - produce the equivalent results. - -Description ------------ - -This algorithm applies a :ref:`calibration table -` to convert a workspace from -time-of-flight to dSpacing as described below. The equation in `GSAS -`_ converts from -d-spacing (:math:`d`) to time-of-flight (:math:`TOF`) by the equation: - -.. math:: TOF = DIFC * d + DIFA * d^2 + TZERO - -The manual describes these terms in more detail. Roughly, -:math:`TZERO` is related to the difference between the measured and -actual time-of-flight base on emission time from the moderator, :math:`DIFA` is an empirical term (ideally zero), and :math:`DIFC` is - -.. math:: DIFC = \frac{2m_N}{h} L_{tot} sin \theta - -Measuring peak positions using a crystal with a very well known -lattice constant will give a good value for converting the data. The -d-spacing of the data will be calculated using whichever equation -below is appropriate for solving the quadratic. - -When :math:`DIFA = 0` then the solution is just for a line and - -.. math:: d = \frac{TOF - TZERO}{DIFC} - -For the case of needing to solve the actual quadratic equation - -.. math:: d = \frac{-DIFC}{2 DIFA} \pm \sqrt{\frac{TOF}{DIFA} + \left(\frac{DIFC}{2 DIFA}\right)^2 - \frac{TZERO}{DIFA}} - -Here the positive root is used when :math:`DIFA > 0` and the negative -when :math:`DIFA < 0`. - -This algorithm always uses a :ref:`calibration table -` which it either reads from the -`CalibrationWorkspace` property, or uses :ref:`ConvertDiffCal -` to produce from the ``OffsetsWorkspace``. - -.. note:: The workspace that this algorithms outputs is a - :ref:`ragged workspace `. - -Restrictions on the input workspace -################################### - -The input workspace must contain histogram or event data where the X -unit is time-of-flight and the Y data is raw counts. The -:ref:`instrument ` associated with the workspace must be -fully defined because detector, source & sample position are needed if -an OffsetsWorkspace is provided. - -Usage ------ - -**Example: Use offset to move peak in Dspace** - -.. testcode:: ExAlignDetectors - - ws = CreateSampleWorkspace("Event",NumBanks=1,BankPixelWidth=1) - ws = MoveInstrumentComponent(Workspace='ws', ComponentName='bank1', X=0.5, RelativePosition=False) - wsD = ConvertUnits(InputWorkspace='ws', Target='dSpacing') - maxD = Max(wsD) - offset = GetDetectorOffsets(InputWorkspace='wsD', DReference=2.5, XMin=2, XMax=3) - wsA = AlignDetectors(InputWorkspace='ws', OutputWorkspace='wsA', OffsetsWorkspace='offset') - maxA = Max(wsA) - print("Peak in dSpace {:.11f}".format(maxD.readX(0)[0])) - print("Peak from calibration {:.10f}".format(maxA.readX(0)[0])) - -Output: - -.. testoutput:: ExAlignDetectors - - Peak in dSpace 2.66413186052 - Peak from calibration 2.5622683421 - - -.. categories:: - -.. sourcelink:: diff --git a/docs/source/algorithms/ApplyDiffCal-v1.rst b/docs/source/algorithms/ApplyDiffCal-v1.rst index 487240933431..b67c7988ec35 100644 --- a/docs/source/algorithms/ApplyDiffCal-v1.rst +++ b/docs/source/algorithms/ApplyDiffCal-v1.rst @@ -25,8 +25,7 @@ calibrated diffractometer constants to be performed using the reads the constants from the instrument parameter map. When used together with :ref:`ConvertUnits ` this algorithm provides a way of -converting in both directions between time of flight and d spacing and it is an alternative to -using :ref:`AlignDetectors `. +converting in both directions between time of flight and d spacing. The values of the diffractometer constants that are stored in the instrument parameter map can be viewed on the Show Detectors screen of a workspace. diff --git a/docs/source/algorithms/CalculateDIFC-v1.rst b/docs/source/algorithms/CalculateDIFC-v1.rst index d46ec692b7e2..88e2709c0a41 100644 --- a/docs/source/algorithms/CalculateDIFC-v1.rst +++ b/docs/source/algorithms/CalculateDIFC-v1.rst @@ -24,8 +24,7 @@ DIFC is used in the equation .. math:: TOF = DIFC \times d -This algorithm uses the same underlying calculation as :ref:`algm-ConvertUnits` -and :ref:`algm-AlignDetectors`. +This algorithm uses the same underlying calculation as :ref:`algm-ConvertUnits`. When specifying the ``CalibrationWorkspace``, this algorithm copies the values in the ``detid`` and ``difc`` columns of the calibration workspace. diff --git a/docs/source/algorithms/ConvertUnits-v1.rst b/docs/source/algorithms/ConvertUnits-v1.rst index 29c962a024cf..2af35cc8f3ff 100644 --- a/docs/source/algorithms/ConvertUnits-v1.rst +++ b/docs/source/algorithms/ConvertUnits-v1.rst @@ -35,6 +35,22 @@ If ConvertFromPointData is true, an input workspace contains Point data will be converted using :ref:`ConvertToHistogram ` and then the algorithm will be run on the converted workspace. +Applying instrument calibration +############################### + +Some workflows involve applying a calibration in the form of updated detector positions. In the case of +time-of-flight (TOF) diffraction it is also possible to provide detector offsets +(from :ref:`GetDetectorOffsets `) or diffractometer constants +(from :ref:`PDCalibration `) for the conversion between TOF and d-spacing. +For more details on diffractometer constants see :ref:`Unit Factory`, for the relation between offsets and diffractometer +constants see :ref:`algm-ConvertDiffCal`. + +:ref:`ApplyDiffCal ` is used to apply a detector calibration in the form of a ``CalibrationFile``, +``CalibrationWorkspace`` or ``OffsetsWorkspace``. Note this calibration will be used to do the conversion from d-spacing +to TOF unless the user calls :ref:`ApplyDiffCal ` again with ``ClearCalibration=True`` after the call +to :ref:`ConvertUnits ` (to reproduce the behaviour of the deprecated ``AlignDetectors`` algorithm). + + Restrictions on the input workspace ################################### diff --git a/docs/source/algorithms/CreateCalFileByNames-v1.rst b/docs/source/algorithms/CreateCalFileByNames-v1.rst index e968228dbe98..e94dbdceec9f 100644 --- a/docs/source/algorithms/CreateCalFileByNames-v1.rst +++ b/docs/source/algorithms/CreateCalFileByNames-v1.rst @@ -24,7 +24,7 @@ then any existing offsets and selection values will be maintained and only the grouping values changed. Detectors not assigned to any group will appear as group 0, i.e. not -included when using AlignDetector or DiffractionFocussing algorithms. +included when using the DiffractionFocussing algorithm. The group number is assigned based on a descent in the instrument tree assembly. If two assemblies are parented, say Bank1 and module1, and diff --git a/docs/source/algorithms/CreateDummyCalFile-v1.rst b/docs/source/algorithms/CreateDummyCalFile-v1.rst index c1b8fb909dce..b5a59e37ad8c 100644 --- a/docs/source/algorithms/CreateDummyCalFile-v1.rst +++ b/docs/source/algorithms/CreateDummyCalFile-v1.rst @@ -21,8 +21,8 @@ Offsets in the file are all sets to zero and all detectors are selected. Overwrites a calibration file that already exists at the location specified. -Detectors will be assigned to group one when using AlignDetector or -DiffractionFocussing algorithms. +Detectors will be assigned to group one when using the +DiffractionFocussing algorithm. Usage ----- diff --git a/docs/source/algorithms/DiffractionFocussing-v2.rst b/docs/source/algorithms/DiffractionFocussing-v2.rst index b340dd9e2cee..62af1a685abe 100644 --- a/docs/source/algorithms/DiffractionFocussing-v2.rst +++ b/docs/source/algorithms/DiffractionFocussing-v2.rst @@ -80,7 +80,8 @@ Usage cal_file = "hrpd_new_072_01_corr.cal" # For HRPD data, perform a unit conversion TOF->d-spacing, taking into account detector position offsets - ws = AlignDetectors(InputWorkspace='ws',CalibrationFile=cal_file) + ws = ApplyDiffCal(InstrumentWorkspace='ws', CalibrationFile=cal_file) + ws = ConvertUnits(InputWorkspace='ws', Target="dSpacing") # Focus the data ws = DiffractionFocussing(InputWorkspace='ws',GroupingFileName=cal_file) @@ -124,9 +125,11 @@ Output: cal_file = "hrpd_new_072_01_corr.cal" # For HRPD data, perform a unit conversion TOF->d-spacing, taking into account detector position offsets - ws = AlignDetectors(InputWorkspace='ws',CalibrationFile=cal_file) + ApplyDiffCal(InstrumentWorkspace=ws, CalibrationFile=cal_file) + ws = ConvertUnits(InputWorkspace=ws, Target="dSpacing") + ApplyDiffCal(InstrumentWorkspace=ws, ClearCalibration=True) # use uncalibrated DIFC to convert from d-spacing to TOF # Focus the data with defined binning parameters - ws = DiffractionFocussing(InputWorkspace='ws',GroupingFileName=cal_file, DMin=[0.6,1.0,2.2], DMax=[1.0,1.5,4.0], Delta=0.1) + ws = DiffractionFocussing(InputWorkspace=ws,GroupingFileName=cal_file, DMin=[0.6,1.0,2.2], DMax=[1.0,1.5,4.0], Delta=0.1) print(f"Output has {ws.getNumberHistograms()} spectra with number of bins {len(ws.readY(0))}, {len(ws.readY(1))} and {len(ws.readY(2))}") diff --git a/docs/source/algorithms/EnggFitPeaks-v1.rst b/docs/source/algorithms/EnggFitPeaks-v1.rst index 547b5b1788fd..0c614bf9f577 100644 --- a/docs/source/algorithms/EnggFitPeaks-v1.rst +++ b/docs/source/algorithms/EnggFitPeaks-v1.rst @@ -33,9 +33,8 @@ then the algorithm fails. After the conversion of units, the algorithm tries to fit (in time-of-flight) a peak in the neighborhood of every expected peak -using a peak shape or function. The conversion is done as in the -Mantid algorithm :ref:`AlignDetectors ` -(following GSAS equations) if the workspace is focused (single +using a peak shape or function. The conversion is done following GSAS equations +(see :ref:`Unit Factory ` for more details) if the workspace is focused (single spectrum) and has a log entry named "difc", where the GSAS DIFC parameter is expected. Otherwise the conversion of units is done as in the Mantid :ref:`ConvertUnits `. diff --git a/docs/source/algorithms/EnggFitTOFFromPeaks-v1.rst b/docs/source/algorithms/EnggFitTOFFromPeaks-v1.rst index 18357490711c..e0e04d20e42f 100644 --- a/docs/source/algorithms/EnggFitTOFFromPeaks-v1.rst +++ b/docs/source/algorithms/EnggFitTOFFromPeaks-v1.rst @@ -39,10 +39,8 @@ If a name is given in OutParametersTable this algorithm also produces a table workspace with that name, containing the parameters fitted (DIFA, DIFC, TZERO). -The parameters DIFA, DIFC, TZERO are also used in other Mantid -algorithms. For example see :ref:`AlignDetectors -` where these parameters are used to convert -units from time-of-flight to d-spacing. +The parameters DIFA, DIFC, TZERO are also used in other Mantid algorithms. See +:ref:`Unit Factory ` for more details. Usage ----- diff --git a/docs/source/algorithms/LoadDspacemap-v1.rst b/docs/source/algorithms/LoadDspacemap-v1.rst index 209df49fb654..f179db4b8374 100644 --- a/docs/source/algorithms/LoadDspacemap-v1.rst +++ b/docs/source/algorithms/LoadDspacemap-v1.rst @@ -13,7 +13,7 @@ Loads a Dspacemap file (POWGEN binary, VULCAN binary or ascii format) into an OffsetsWorkspace. The resulting workspace can then be used with, e.g. -:ref:`AlignDetectors ` to perform calibration. +:ref:`ConvertUnits ` to perform calibration. Usage ----- diff --git a/docs/source/algorithms/PDCalibration-v1.rst b/docs/source/algorithms/PDCalibration-v1.rst index 0329485b819d..1bd07ef11af2 100644 --- a/docs/source/algorithms/PDCalibration-v1.rst +++ b/docs/source/algorithms/PDCalibration-v1.rst @@ -13,7 +13,7 @@ Description This algorithm takes an ``InputWorkspace`` containing powder diffraction spectra from a standard sample with x-units of time-of-flight (TOF). These spectra are fitted to extract the Bragg peak positions. The extracted peak positions are then used to determine the diffractometer constants that convert diffraction spectra from TOF to d-spacing. These constants are described in detail -in :ref:`algm-AlignDetectors`. The number of the constants being determined (1,2,or 3) is controlled by ``CalibrationParameters``. +in :ref:`Unit Factory`. The number of the constants being determined (1,2,or 3) is controlled by ``CalibrationParameters``. The results are output to a :ref:`diffraction calibration workspace `. Unlike other calibration algorithms (see `Time-of-Flight Powder Diffraction Calibration <../concepts/calibration/PowderDiffractionCalibration.html>`_), @@ -42,9 +42,11 @@ returned. This favors using less parameters. When not specified using the ``MaskWorkspace`` parameter, the default name for the mask workspace will be the ``OutputCalibrationTable`` parameter + ``_mask``. If the mask workspace already exists, its masked values will be combined with those from any uncalibrated pixels detected during the algorithm's execution. The resulting calibration table can be saved with -:ref:`algm-SaveDiffCal`, loaded with :ref:`algm-LoadDiffCal` and -applied to a workspace with :ref:`algm-AlignDetectors`. There are also -three workspaces placed in the ``DiagnosticWorkspace`` group. They are: +:ref:`algm-SaveDiffCal`, loaded with :ref:`algm-LoadDiffCal`. +The calibration can be applied to a workspace using :ref:`algm-ApplyDiffCal` which uses the calibration table +and updates the diffractometer constants in the ``UnitParams`` map of the workspace that is then used in :ref:`algm-ConvertUnits` to convert the x-axis of the data from TOF to e.g. d-spacing. + +There are also three workspaces placed in the ``DiagnosticWorkspace`` group. They are: * evaluated fit functions (``_fitted``) which is the ``OutputPeakParametersWorkspace`` from :ref:`FitPeaks ` * raw peak fit values (``_fitparam``) which is the ``FittedPeaksWorkspace`` from :ref:`FitPeaks ` diff --git a/docs/source/algorithms/SaveGDA-v1.rst b/docs/source/algorithms/SaveGDA-v1.rst index def556fa4baa..7117da7c7499 100644 --- a/docs/source/algorithms/SaveGDA-v1.rst +++ b/docs/source/algorithms/SaveGDA-v1.rst @@ -56,7 +56,7 @@ D to TOF Conversion conversion factors for each bank. SaveGDA takes input in D-spacing, and applies the GSAS conversion -(explained at :ref:`AlignDetectors `), using +(explained in :ref:`Unit Factory`), using parameters from the calibration file, to convert back to time-of-flight. The caveat here is that, if the calibration file contains the wrong conversion factors, then the TOF values will not diff --git a/docs/source/concepts/UnitFactory.rst b/docs/source/concepts/UnitFactory.rst index f5795c657596..bd4514d71347 100644 --- a/docs/source/concepts/UnitFactory.rst +++ b/docs/source/concepts/UnitFactory.rst @@ -81,6 +81,35 @@ of :math:`\mu s` per :math:`\mathrm{\AA}`. of angular and wavelength-dispersive neutron time-of-flight powder diffraction data. Together with the d-Spacing :math:`d`, d-SpacingPerpendicular :math:`d_{\perp}` forms a new orthogonal coordinate system. +**Note on converting time-of-flight to dSpacing using GSAS** +The equation in `GSAS +`_ converts from +d-spacing (:math:`d`) to time-of-flight (:math:`TOF`) by the equation: + +.. math:: TOF = DIFC * d + DIFA * d^2 + TZERO + +The manual describes these terms in more detail. Roughly, +:math:`TZERO` is related to the difference between the measured and +actual time-of-flight base on emission time from the moderator, :math:`DIFA` is an empirical term (ideally zero), and :math:`DIFC` is + +.. math:: DIFC = \frac{2m_N}{h} L_{tot} sin \theta + +Measuring peak positions using a crystal with a very well known +lattice constant will give a good value for converting the data. The +d-spacing of the data will be calculated using whichever equation +below is appropriate for solving the quadratic. + +When :math:`DIFA = 0` then the solution is just for a line and + +.. math:: d = \frac{TOF - TZERO}{DIFC} + +For the case of needing to solve the actual quadratic equation + +.. math:: d = \frac{-DIFC}{2 DIFA} \pm \sqrt{\frac{TOF}{DIFA} + \left(\frac{DIFC}{2 DIFA}\right)^2 - \frac{TZERO}{DIFA}} + +Here the positive root is used when :math:`DIFA > 0` and the negative +when :math:`DIFA < 0`. + Available non-TOF Convertible units ----------------------------------- diff --git a/docs/source/concepts/calibration/CalFile.rst b/docs/source/concepts/calibration/CalFile.rst index 503a59383ba5..0593300a3a1f 100644 --- a/docs/source/concepts/calibration/CalFile.rst +++ b/docs/source/concepts/calibration/CalFile.rst @@ -35,8 +35,7 @@ The file is a simple text file with the following format - ``number``: ignored - ``UDET``: detector ID -- ``offset``: calibration offset used in :ref:`AlignDetectors - `. Comes from the ``OffsetsWorkspace``, or 0.0 +- ``offset``: calibration offset. Comes from the ``OffsetsWorkspace``, or 0.0 if none is given. - ``select``: 1 if selected (use the pixel). Comes from the ``MaskWorkspace``, or 1 if none is given. diff --git a/docs/source/concepts/calibration/PowderDiffractionCalibration.rst b/docs/source/concepts/calibration/PowderDiffractionCalibration.rst index 8edbeef606ca..244b189ff4b9 100644 --- a/docs/source/concepts/calibration/PowderDiffractionCalibration.rst +++ b/docs/source/concepts/calibration/PowderDiffractionCalibration.rst @@ -34,10 +34,7 @@ the rest of the instrument to. The main algorithm that does this is 1. :ref:`Load ` the calibration data 2. Convert the X-Units to d-spacing using :ref:`ConvertUnits `. The "offsets" calculated are relative - reference spectrum's geometry so using :ref:`AlignDetectors - ` will violate the assumptions for other - algorithms used with time-of-flight powder diffraction and give the - wrong results for focused data. + reference spectrum's geometry. 3. Run :ref:`Rebin ` to set a common d-spacing bin structure across all of the spectra, you will need fine enough bins to allow fitting of your peak. Whatever you choose, make a note of @@ -596,9 +593,10 @@ reasonable calibration constant for each of the spectra in your data. The easiest way to do this is to apply the calibration to your calibration data and check that the bragg peaks align as expected. -1. Load the calibration data using :ref:`Load ` -2. Run :ref:`AlignDetectors `, this will convert the data to d-spacing and apply the calibration. You can provide the calibration using the ``CalibrationFile``, the ``CalibrationWorkspace``, or ``OffsetsWorkspace``. -3. Plot the workspace as a Color Fill plot, in the spectrum view, or a few spectra in a line plot. +1. Load the instrument data using :ref:`Load ` +2. Apply the calibration to the workspace using :ref:`ApplyDiffCal ` (the calibration can be provided using the ``CalibrationFile``, the ``CalibrationWorkspace``, or ``OffsetsWorkspace``). +3. Run :ref:`ConvertUnits `, to convert the data to d-spacing using the calibration. +4. Plot the workspace as a Color Fill plot, in the spectrum view, or a few spectra in a line plot. Further insight can be gained by comparing the grouped (after aligning and focussing the data) spectra from a previous calibration or convert @@ -662,13 +660,13 @@ This can be done using the following code .. code:: - from mantid.simpleapi import (AlignDetectors, LoadDiffCal, LoadEventNexus, LoadInstrument, Rebin) + from mantid.simpleapi import (ApplyDiffCal, ConvertUnits, LoadEventNexus, LoadInstrument, Rebin) from Calibration.tofpd import diagnostics LoadEventNexus(Filename='VULCAN_192227.nxs.h5', OutputWorkspace='ws') Rebin(InputWorkspace='ws', OutputWorkspace='ws', Params=(5000,-.002,70000)) - LoadDiffCal(Filename='VULCAN_Calibration_CC_4runs_hybrid.h5', InputWorkspace='ws', WorkspaceName='VULCAN') - AlignDetectors(InputWorkspace='ws', OutputWorkspace='ws', CalibrationWorkspace='VULCAN_cal') + ApplyDiffCal(InputWorkspace='ws', CalibrationFile='VULCAN_Calibration_CC_4runs_hybrid.h5') + ConvertUnits(InputWorkspace='ws', Target="dSpacing") diagnostics.plot2d(mtd['ws'], horiz_markers=[8*512*20, 2*8*512*20], xmax=1.3) Here the expected peak positions are vertical lines, the horizontal lines are boundaries between banks. diff --git a/docs/source/release/v6.1.0/diffraction.rst b/docs/source/release/v6.1.0/diffraction.rst index bd921a618fcc..e05b5f48d1b8 100644 --- a/docs/source/release/v6.1.0/diffraction.rst +++ b/docs/source/release/v6.1.0/diffraction.rst @@ -10,7 +10,7 @@ Powder Diffraction New features ############ -- The :ref:`ConvertUnits ` algorithm has been extended to use a calibration when converting between d spacing, momentum transfer and TOF. A calibration can be loaded into a workspace using a new :ref:`ApplyDiffCal ` algorithm and then viewed in the Show Detectors screen. The calibration consists of the diffractometer constants DIFA, DIFC and TZERO that determine the form of the quadratic relationship between d spacing and TOF. This functionality was previously only available in :ref:`AlignDetectors ` which only performed the conversion in the direction TOF to d spacing. This change will provide several benefits: +- The :ref:`ConvertUnits ` algorithm has been extended to use a calibration when converting between d spacing, momentum transfer and TOF. A calibration can be loaded into a workspace using a new :ref:`ApplyDiffCal ` algorithm and then viewed in the Show Detectors screen. The calibration consists of the diffractometer constants DIFA, DIFC and TZERO that determine the form of the quadratic relationship between d spacing and TOF. This functionality was previously only available in ``AlignDetectors`` which only performed the conversion in the direction TOF to d spacing. This change will provide several benefits: - Allow the user to choose the calibration to use when converting focused data from d-spacing to TOF - Improved integration with GSAS e.g. both the calibration and the data will be loaded from GSAS files when running the algorithm :ref:`LoadGSS ` and subsequent unit conversions will respect the calibration diff --git a/docs/source/release/v6.13.0/Framework/Algorithms/Deprecated/37799.rst b/docs/source/release/v6.13.0/Framework/Algorithms/Deprecated/37799.rst new file mode 100644 index 000000000000..d327be642672 --- /dev/null +++ b/docs/source/release/v6.13.0/Framework/Algorithms/Deprecated/37799.rst @@ -0,0 +1 @@ +- The AlignDetectors algorithm was deprecated in :ref:`Release 6.1 ` and has now been removed. Please use a combination of :ref:`ApplyDiffCal ` and :ref:`ConvertUnits ` instead. diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_calibration_algs.py b/scripts/Diffraction/isis_powder/gem_routines/gem_calibration_algs.py index eb34e8f82c3b..f5997c27a087 100644 --- a/scripts/Diffraction/isis_powder/gem_routines/gem_calibration_algs.py +++ b/scripts/Diffraction/isis_powder/gem_routines/gem_calibration_algs.py @@ -138,7 +138,9 @@ def _calibration_processing( InputWorkspace=cross_correlated, GroupingFileName=offset_file, OutputWorkspace=offsets_ws_name, **get_det_offset_params ) rebinned_tof = mantid.ConvertUnits(InputWorkspace=rebinned, Target="TOF") - aligned = mantid.AlignDetectors(InputWorkspace=rebinned_tof, CalibrationFile=offset_file) + mantid.ApplyDiffCal(InstrumentWorkspace="rebinned_tof", CalibrationFile=offset_file) + aligned = mantid.ConvertUnits(InputWorkspace=rebinned_tof, Target="dSpacing") + mantid.ApplyDiffCal(InstrumentWorkspace=aligned, ClearCalibration=True) grouping_file = os.path.join(calibration_dir, grouping_file_name) focused = mantid.DiffractionFocussing( InputWorkspace=aligned,