Skip to content

Commit

Permalink
Use mask from calibration file
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswhitfield authored and peterfpeterson committed Nov 6, 2024
1 parent c08b2ce commit 4e13c5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<detid_t, double> m_calibration; // detid: 1/difc
std::set<detid_t> m_masked;
bool is_time_filtered{false};
size_t pulse_start_index{0};
size_t pulse_stop_index{std::numeric_limits<size_t>::max()};
Expand Down
19 changes: 15 additions & 4 deletions Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -120,12 +122,15 @@ template <typename CountsType> class ProcessEventsTask {
public:
ProcessEventsTask(const Histogrammer *histogrammer, const std::vector<uint32_t> *detids,
const std::vector<float> *tofs, const AlignAndFocusPowderSlim::BankCalibration *calibration,
std::vector<CountsType> *y_temp)
: m_histogrammer(histogrammer), m_detids(detids), m_tofs(tofs), m_calibration(calibration), y_temp(y_temp) {}
std::vector<CountsType> *y_temp, const std::set<detid_t> *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<size_t> &range) const {
for (size_t i = range.begin(); i < range.end(); ++i) {
const auto detid = static_cast<detid_t>(m_detids->at(i));
if (masked->contains(detid))
continue;
const auto tof = static_cast<double>(m_tofs->at(i)) * m_calibration->value(detid);

const auto binnum = m_histogrammer->findBin(tof);
Expand All @@ -140,6 +145,7 @@ template <typename CountsType> class ProcessEventsTask {
const std::vector<float> *m_tofs;
const AlignAndFocusPowderSlim::BankCalibration *m_calibration;
std::vector<CountsType> *y_temp;
const std::set<detid_t> *masked;
};

template <typename Type> class MinMax {
Expand Down Expand Up @@ -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<size_t>(0, numEvent), task);
auto &y_values = spectrum.dataY();
std::copy(y_temp.cbegin(), y_temp.cend(), y_values.begin());
Expand Down Expand Up @@ -525,7 +532,7 @@ void AlignAndFocusPowderSlim::loadCalFile(const Mantid::API::Workspace_sptr &inp
alg->setPropertyValue("Filename", filename);
alg->setProperty<bool>("MakeCalWorkspace", true);
alg->setProperty<bool>("MakeGroupingWorkspace", false);
alg->setProperty<bool>("MakeMaskWorkspace", false);
alg->setProperty<bool>("MakeMaskWorkspace", true);
alg->setPropertyValue("WorkspaceName", "temp");
alg->executeAsChildAlg();

Expand All @@ -535,6 +542,10 @@ void AlignAndFocusPowderSlim::loadCalFile(const Mantid::API::Workspace_sptr &inp
const double detc = calibrationWS->cell<double>(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
Expand Down

0 comments on commit 4e13c5c

Please sign in to comment.