From 4e13c5c9c51ea477ea4081aceb6c99efedb863fc Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 30 Oct 2024 13:30:40 +1100 Subject: [PATCH] Use mask from calibration file --- .../AlignAndFocusPowderSlim.h | 1 + .../src/AlignAndFocusPowderSlim.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h b/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h index b64c69e61c06..a0125ebf2b44 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h +++ b/Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h @@ -52,6 +52,7 @@ class MANTID_DATAHANDLING_DLL AlignAndFocusPowderSlim : public API::Algorithm { void loadCalFile(const Mantid::API::Workspace_sptr &inputWS, const std::string &filename); std::map m_calibration; // detid: 1/difc + std::set m_masked; 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 1662e6226347..3b26d23e9dc2 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/MaskWorkspace.h" #include "MantidDataObjects/TableWorkspace.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidDataObjects/WorkspaceCreation.h" @@ -33,6 +34,7 @@ using Mantid::API::FileProperty; using Mantid::API::ITableWorkspace_sptr; using Mantid::API::MatrixWorkspace_sptr; using Mantid::API::WorkspaceProperty; +using Mantid::DataObjects::MaskWorkspace_sptr; using Mantid::DataObjects::Workspace2D; using Mantid::Kernel::ArrayLengthValidator; using Mantid::Kernel::ArrayProperty; @@ -120,12 +122,15 @@ template class ProcessEventsTask { public: ProcessEventsTask(const Histogrammer *histogrammer, const std::vector *detids, const std::vector *tofs, const AlignAndFocusPowderSlim::BankCalibration *calibration, - std::vector *y_temp) - : m_histogrammer(histogrammer), m_detids(detids), m_tofs(tofs), m_calibration(calibration), y_temp(y_temp) {} + std::vector *y_temp, const std::set *masked) + : m_histogrammer(histogrammer), m_detids(detids), m_tofs(tofs), m_calibration(calibration), y_temp(y_temp), + masked(masked) {} void operator()(const tbb::blocked_range &range) const { for (size_t i = range.begin(); i < range.end(); ++i) { const auto detid = static_cast(m_detids->at(i)); + if (masked->contains(detid)) + continue; const auto tof = static_cast(m_tofs->at(i)) * m_calibration->value(detid); const auto binnum = m_histogrammer->findBin(tof); @@ -140,6 +145,7 @@ template class ProcessEventsTask { const std::vector *m_tofs; const AlignAndFocusPowderSlim::BankCalibration *m_calibration; std::vector *y_temp; + const std::set *masked; }; template class MinMax { @@ -390,7 +396,8 @@ void AlignAndFocusPowderSlim::exec() { addTimer("setup" + entry_name, startTimeSetup, std::chrono::high_resolution_clock::now()); const auto startTimeProcess = std::chrono::high_resolution_clock::now(); - ProcessEventsTask task(&histogrammer, event_detid.get(), event_time_of_flight.get(), &calibration, &y_temp); + ProcessEventsTask task(&histogrammer, event_detid.get(), event_time_of_flight.get(), &calibration, &y_temp, + &m_masked); tbb::parallel_for(tbb::blocked_range(0, numEvent), task); auto &y_values = spectrum.dataY(); std::copy(y_temp.cbegin(), y_temp.cend(), y_values.begin()); @@ -525,7 +532,7 @@ void AlignAndFocusPowderSlim::loadCalFile(const Mantid::API::Workspace_sptr &inp alg->setPropertyValue("Filename", filename); alg->setProperty("MakeCalWorkspace", true); alg->setProperty("MakeGroupingWorkspace", false); - alg->setProperty("MakeMaskWorkspace", false); + alg->setProperty("MakeMaskWorkspace", true); alg->setPropertyValue("WorkspaceName", "temp"); alg->executeAsChildAlg(); @@ -535,6 +542,10 @@ void AlignAndFocusPowderSlim::loadCalFile(const Mantid::API::Workspace_sptr &inp const double detc = calibrationWS->cell(row, 1); m_calibration.emplace(detid, 1. / detc); } + + const MaskWorkspace_sptr maskWS = alg->getProperty("OutputMaskWorkspace"); + m_masked = maskWS->getMaskedDetectors(); + g_log.debug() << "Masked detectors: " << m_masked.size() << '\n'; } // ------------------------ BankCalibration object