diff --git a/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h b/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h index 1e7cd5334881..b64c69e61c06 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h +++ b/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h @@ -49,7 +49,9 @@ class MANTID_DATAHANDLING_DLL AlignAndFocusPowderSlim : public API::Algorithm { void loadPulseTimes(std::unique_ptr> &data, ::NeXus::File &h5file); void loadEventIndex(std::unique_ptr> &data, ::NeXus::File &h5file); - std::map m_calibration; + void loadCalFile(const Mantid::API::Workspace_sptr &inputWS, const std::string &filename); + + std::map m_calibration; // detid: 1/difc bool is_time_filtered{false}; size_t pulse_start_index{0}; size_t pulse_stop_index{std::numeric_limits::max()}; diff --git a/Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp b/Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp index d6643f632a0b..67ee28bca9c6 100644 --- a/Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp +++ b/Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp @@ -13,6 +13,7 @@ #include "MantidDataHandling/LoadEventNexus.h" #include "MantidDataHandling/LoadEventNexusIndexSetup.h" #include "MantidDataObjects/EventList.h" +#include "MantidDataObjects/TableWorkspace.h" #include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidKernel/Timer.h" #include "MantidKernel/VectorHelper.h" @@ -25,6 +26,7 @@ namespace Mantid::DataHandling { using Mantid::API::FileProperty; +using Mantid::API::ITableWorkspace_sptr; using Mantid::API::MatrixWorkspace_sptr; using Mantid::API::WorkspaceFactory; using Mantid::API::WorkspaceProperty; @@ -197,6 +199,10 @@ void AlignAndFocusPowderSlim::init() { Direction::Input), "Optional: To only include events before the provided stop " "time, in seconds (relative to the start of the run)."); + const std::vector cal_exts{".h5", ".hd5", ".hdf", ".cal"}; + declareProperty(std::make_unique(PropertyNames::CAL_FILE, "", FileProperty::OptionalLoad, cal_exts), + "Optional: The .cal file containing the position correction factors. " + "Either this or OffsetsWorkspace needs to be specified."); declareProperty( std::make_unique>(PropertyNames::OUTPUT_WKSP, "", Direction::Output), "An output workspace."); @@ -208,8 +214,8 @@ void AlignAndFocusPowderSlim::init() { void AlignAndFocusPowderSlim::exec() { // create a histogram workspace constexpr size_t numHist{6}; - constexpr double xmin{6463}; - constexpr double xmax{39950}; + constexpr double xmin{0.25}; + constexpr double xmax{2.25}; // These give the limits in each file as to which events we actually load // (when filtering by time). @@ -217,7 +223,7 @@ void AlignAndFocusPowderSlim::exec() { loadSize.resize(1, 0); HistogramData::BinEdges XValues_new(0); - const double binWidth{10.}; + const double binWidth{1.6e-3}; // to get 1250 bins total const bool linearBins = bool(binWidth > 0.); UNUSED_ARG(Kernel::VectorHelper::createAxisFromRebinParams({xmin, binWidth, xmax}, XValues_new.mutableRawData(), true, false, xmin, xmax)); @@ -236,7 +242,13 @@ void AlignAndFocusPowderSlim::exec() { // prog->doReport("Loading instrument"); TODO add progress bar stuff // LoadEventNexus::loadInstrument(filename, wksp, "entry", this, &descriptor); LoadEventNexus::loadInstrument(filename, wksp, ENTRY_TOP_LEVEL, this, &descriptor); - this->initCalibrationConstants(wksp); + + const std::string cal_filename = getPropertyValue(PropertyNames::CAL_FILE); + if (!cal_filename.empty()) { + loadCalFile(wksp, cal_filename); + } else { + this->initCalibrationConstants(wksp); + } /* // load run metadata @@ -398,12 +410,10 @@ void AlignAndFocusPowderSlim::exec() { void AlignAndFocusPowderSlim::initCalibrationConstants(API::MatrixWorkspace_sptr &wksp) { const auto detInfo = wksp->detectorInfo(); - // TODO currently arbitrary - const auto difCFocus = 1. / Kernel::Units::tofToDSpacingFactor(detInfo.l1(), 1., 0.5 * M_PI, 0.); for (auto iter = detInfo.cbegin(); iter != detInfo.cend(); ++iter) { if (!iter->isMonitor()) { - m_calibration.emplace(iter->detid(), difCFocus / detInfo.difcUncalibrated(iter->index())); + m_calibration.emplace(iter->detid(), 1. / detInfo.difcUncalibrated(iter->index())); } } } @@ -504,6 +514,24 @@ void AlignAndFocusPowderSlim::loadEventIndex(std::unique_ptrsetProperty("InputWorkspace", inputWS); + alg->setPropertyValue("Filename", filename); + alg->setProperty("MakeCalWorkspace", true); + alg->setProperty("MakeGroupingWorkspace", false); + alg->setProperty("MakeMaskWorkspace", false); + alg->setPropertyValue("WorkspaceName", "temp"); + alg->executeAsChildAlg(); + + const ITableWorkspace_sptr calibrationWS = alg->getProperty("OutputCalWorkspace"); + for (size_t row = 0; row < calibrationWS->rowCount(); ++row) { + const detid_t detid = calibrationWS->cell(row, 0); + const double detc = calibrationWS->cell(row, 1); + m_calibration.emplace(detid, 1. / detc); + } +} + // ------------------------ BankCalibration object AlignAndFocusPowderSlim::BankCalibration::BankCalibration(const detid_t idmin, const detid_t idmax, const std::map &calibration_map)