Mantid
Loading...
Searching...
No Matches
BankCalibration.cpp
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
9#include <algorithm>
10#include <stdexcept>
11
13
14namespace {
15void copy_values_from_map_to_offset_vector(const std::map<detid_t, double> &map_values, const detid_t idmin,
16 const detid_t idmax, std::vector<double> &vector_values) {
17 // allocate memory and set the default value to 1
18 vector_values.assign(static_cast<size_t>(idmax - idmin + 1), 1.);
19
20 // set up iterators for copying data - assumes ordered map
21 auto iter = map_values.find(idmin);
22 if (iter == map_values.end())
23 throw std::runtime_error("Failed to find idmin=" + std::to_string(idmin) + " in map");
24 auto iter_end = map_values.find(idmax);
25 if (iter_end != map_values.end())
26 ++iter_end;
27
28 // copy over values that matter
29 for (; iter != iter_end; ++iter) {
30 const auto index = static_cast<size_t>(iter->first - idmin);
31 vector_values[index] = iter->second;
32 }
33}
34} // namespace
35
36// ------------------------ BankCalibration object
50BankCalibration::BankCalibration(const detid_t idmin, const detid_t idmax, const double time_conversion,
51 const std::map<detid_t, double> &calibration_map,
52 const std::map<detid_t, double> &scale_at_sample, const std::set<detid_t> &mask)
53 : m_detid_offset(idmin) {
54 // error check the id-range
55 if (idmax < idmin) {
56 // std::string msg =
57 // std::string("encountered invalid detector ID range ") + std::to_string(idmin) + " > " + std::to_string(idmax);
58 throw std::runtime_error("encountered invalid detector ID range " + std::to_string(idmin) + " > " +
60 }
61
62 // get the values copied over for calibration
63 copy_values_from_map_to_offset_vector(calibration_map, idmin, idmax, m_calibration);
64 // apply time conversion here so it is effectively applied for each detector once rather than on each event
65 if (time_conversion != 1.) {
66 std::transform(m_calibration.begin(), m_calibration.end(), m_calibration.begin(),
67 [time_conversion](const auto &value) { return std::move(time_conversion * value); });
68 }
69
70 // get the values copied over for scale_at_sample
71 if (!scale_at_sample.empty())
72 copy_values_from_map_to_offset_vector(scale_at_sample, idmin, idmax, m_scale_at_sample);
73
74 // setup the detector mask - this assumes there are not many pixels in the overall mask
75 // TODO could benefit from using lower_bound/upper_bound on the input mask rather than all
76 for (const auto &detid : mask) {
77 if (detid >= idmin && detid <= idmax) {
79 }
80 }
81}
82
86const double &BankCalibration::value_calibration(const detid_t detid) const {
87 return m_calibration[detid - m_detid_offset];
88}
89
90double BankCalibration::value_scale_at_sample(const detid_t detid) const {
91 return m_scale_at_sample[detid - m_detid_offset];
92}
93
95detid_t BankCalibration::idmax() const { return m_detid_offset + static_cast<detid_t>(m_calibration.size()) - 1; }
96} // namespace Mantid::DataHandling::AlignAndFocusPowderSlim
double value
The value of the point.
Definition FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
const double & value_calibration(const detid_t detid) const
This assumes that everything is in range.
BankCalibration(const detid_t idmin, const detid_t idmax, const double time_conversion, const std::map< detid_t, double > &calibration_map, const std::map< detid_t, double > &scale_at_sample, const std::set< detid_t > &mask)
Calibration of a subset of pixels as requested in the constructor.
double value_scale_at_sample(const detid_t detid) const
This returns a value with no bounds checking.
int32_t detid_t
Typedef for a detector ID.
std::string to_string(const wide_integer< Bits, Signed > &n)