53 "OffsetsWorkspace containing the calibration offsets.");
57 "A calibration table used as a cache for creating the OutputWorkspace. "
58 "Effectively, this algorithm applies partial updates to this table and "
59 "returns it as the OutputWorkspace");
62 "An output workspace.");
73 auto detIDs = offsetsWS->getSpectrum(
index).getDetectorIDs();
74 if (detIDs.size() != 1) {
75 std::stringstream msg;
76 msg <<
"Encountered spectrum with multiple detector ids (size=" << detIDs.size() <<
")";
77 throw std::logic_error(msg.str());
79 return (*(detIDs.begin()));
89 const double offset = offsetsWS->getValue(detid, 0.0);
91 std::stringstream msg;
92 msg <<
"Encountered offset of " << offset <<
" which converts data to negative d-spacing for detectorID " << detid
94 throw std::logic_error(msg.str());
108 const double offset =
getOffset(offsetsWS, detid);
112 }
catch (std::runtime_error &) {
118 const double factor =
135 std::vector<std::string> correct_columns{
"detid",
"difc",
"difa",
"tzero"};
136 if (previous_calibration) {
138 std::vector<std::string> column_names = previous_calibration->getColumnNames();
139 if (column_names != correct_columns) {
140 throw std::runtime_error(
"PreviousCalibration table's column names do not match expected "
144 configWksp = previous_calibration->clone();
149 configWksp = std::make_shared<TableWorkspace>();
151 configWksp->addColumn(
"int", correct_columns[0]);
152 configWksp->addColumn(
"double", correct_columns[1]);
153 configWksp->addColumn(
"double", correct_columns[2]);
154 configWksp->addColumn(
"double", correct_columns[3]);
158 std::unordered_map<int, int> id_to_row;
159 if (previous_calibration) {
160 std::vector<int> previous_calibration_ids = previous_calibration->getColumn(0)->numeric_fill<
int>();
164 for (
auto id : previous_calibration_ids) {
165 id_to_row[id] = row++;
170 const size_t numberOfSpectra = offsetsWS->getNumberHistograms();
175 for (
size_t i = 0; i < numberOfSpectra; ++i) {
179 size_t internal_index = d_info.
indexOf(detector_id);
181 if (!d_info.
isMasked(internal_index)) {
183 double new_offset_value = offsetsWS->getValue(detector_id);
186 auto iter = id_to_row.find(detector_id);
189 if (iter != id_to_row.end()) {
191 int row_to_update = iter->second;
193 double &difc_value_to_update = configWksp->cell<
double>(row_to_update, 1);
195 difc_value_to_update = difc_value_to_update / (1 + new_offset_value);
201 newrow << static_cast<int>(detector_id);
213 sortTable->setProperty(
"InputWorkspace", configWksp);
214 sortTable->setProperty(
"OutputWorkspace", configWksp);
215 sortTable->setPropertyValue(
"Columns",
"detid");
216 sortTable->executeAsChildAlg();
219 configWksp = sortTable->getProperty(
"OutputWorkspace");
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
Helper class for reporting progress from algorithms.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
double twoTheta(const size_t index) const
Returns the scattering angle 2 theta in radians (angle w.r.t.
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
double l1() const
Returns L1 (distance from source to sample).
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
ConvertDiffCal : TODO: DESCRIPTION.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
An OffsetsWorkspace is a specialized Workspace2D where the Y value at each pixel is the offset to be ...
TableWorkspace is an implementation of Workspace in which the data are organised in columns of same s...
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
bool isMasked(const size_t index) const
Returns true if the detector is masked.
size_t indexOf(const detid_t id) const
Returns the index of the detector with the given detector ID.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
double getOffset(const OffsetsWorkspace_const_sptr &offsetsWS, const detid_t detid)
detid_t getDetID(const OffsetsWorkspace_const_sptr &offsetsWS, const size_t index)
double calculateDIFC(const OffsetsWorkspace_const_sptr &offsetsWS, const size_t index, const Mantid::API::SpectrumInfo &spectrumInfo)
std::shared_ptr< const OffsetsWorkspace > OffsetsWorkspace_const_sptr
shared pointer to a const OffsetsWorkspace
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
MANTID_GEOMETRY_DLL double tofToDSpacingFactor(const double l1, const double l2, const double twoTheta, const double offset)
Calculate and return conversion factor from tof to d-spacing.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
int32_t detid_t
Typedef for a detector ID.
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.