Mantid
Loading...
Searching...
No Matches
ProcessEventsTask.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2025 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
8#pragma once
9
11#include <ranges>
12#include <tbb/tbb.h>
13#include <vector>
14
16
17template <typename DetIDsVector, typename TofVector> class ProcessEventsTask {
18public:
19 ProcessEventsTask(DetIDsVector *detids, TofVector *tofs, const BankCalibration *calibration,
20 const std::vector<double> *binedges)
21 : y_temp(binedges->size() - 1, 0), m_detids(detids), m_tofs(tofs), m_calibration(calibration),
22 m_binedges(binedges) {}
23
25 : y_temp(other.y_temp.size(), 0), m_detids(other.m_detids), m_tofs(other.m_tofs),
27
28 void operator()(const tbb::blocked_range<size_t> &range) {
29 // Cache values to reduce number of function calls
30 const auto &range_end = range.end();
31 const auto &binedges_cbegin = m_binedges->cbegin();
32 const auto &binedges_cend = m_binedges->cend();
33 const auto &tof_min = m_binedges->front();
34 const auto &tof_max = m_binedges->back();
35
36 // Calibrate and histogram the data
37 auto detid_iter = std::ranges::next(m_detids->begin(), range.begin());
38 auto tof_iter = std::ranges::next(m_tofs->begin(), range.begin());
39 for (size_t i = range.begin(); i < range_end; ++i) {
40 const auto &detid = *detid_iter;
41 const auto &calib_factor = m_calibration->value_calibration(detid);
42 if (calib_factor < IGNORE_PIXEL) {
43 // Apply calibration
44 const double &tof = static_cast<double>(*tof_iter) * calib_factor;
45 if ((tof < tof_max) && (!(tof < tof_min))) { // check against max first to allow skipping second
46 // Find the bin index using binary search
47 const auto &it = std::upper_bound(binedges_cbegin, binedges_cend, tof);
48
49 // Increment the count if a bin was found
50 const auto &bin = static_cast<size_t>(std::distance(binedges_cbegin, it) - 1);
51 y_temp[bin]++;
52 }
53 }
54 ++detid_iter;
55 ++tof_iter;
56 }
57 }
58
59 void join(const ProcessEventsTask &other) {
60 // Combine local histograms
61 std::transform(y_temp.begin(), y_temp.end(), other.y_temp.cbegin(), y_temp.begin(), std::plus<>{});
62 }
63
65 std::vector<uint32_t> y_temp;
66
67private:
68 DetIDsVector *m_detids;
69 TofVector *m_tofs;
71 const std::vector<double> *m_binedges;
72};
73
74} // namespace Mantid::DataHandling::AlignAndFocusPowderSlim
Class that handles all the calibration constants for a bank of detectors.
const double & value_calibration(const detid_t detid) const
This assumes that everything is in range.
void operator()(const tbb::blocked_range< size_t > &range)
ProcessEventsTask(DetIDsVector *detids, TofVector *tofs, const BankCalibration *calibration, const std::vector< double > *binedges)
std::vector< uint32_t > y_temp
Local histogram for this block/thread.