41class ConversionFactors {
46 this->generateDetidToRow(table);
49 std::tuple<double, double, double> getDiffConstants(
const std::set<detid_t> &detIds)
const {
50 const std::set<size_t> rows = this->getRow(detIds);
54 for (
auto row : rows) {
59 if (rows.size() > 1) {
60 double norm = 1. /
static_cast<double>(rows.size());
72 const size_t numDets = detIDs.
size();
73 for (
size_t i = 0; i < numDets; ++i) {
78 std::set<size_t> getRow(
const std::set<detid_t> &detIds)
const {
79 std::set<size_t> rows;
80 for (
auto detId : detIds) {
83 rows.insert(rowIter->second);
87 std::string detIdsStr = std::accumulate(std::begin(detIds), std::end(detIds), std::string{},
88 [](
const std::string &a,
const detid_t &b) {
110 return "Performs a unit change from TOF to dSpacing, correcting the X "
111 "values to account for small errors in the detector positions.";
121 auto wsValidator = std::make_shared<CompositeValidator>();
128 "A workspace with units of TOF");
131 "The name to use for the output workspace");
133 const std::vector<std::string> exts{
".h5",
".hd5",
".hdf",
".cal"};
135 "Optional: The .cal file containing the position correction factors. "
136 "Either this or OffsetsWorkspace needs to be specified.");
140 "Optional: A Workspace containing the calibration information. Either "
141 "this or CalibrationFile needs to be specified.");
145 "Optional: A OffsetsWorkspace containing the calibration offsets. Either "
146 "this or CalibrationFile needs to be specified.");
149 std::string calibrationGroup(
"Calibration");
156 std::map<std::string, std::string> result;
160 const std::string calFileName =
getProperty(
"CalibrationFile");
161 if (!calFileName.empty())
165 if (
bool(calibrationWS))
174 message =
"You must specify only one of CalibrationFile, "
175 "CalibrationWorkspace, OffsetsWorkspace.";
178 message =
"You must specify one of CalibrationFile, "
179 "CalibrationWorkspace, OffsetsWorkspace.";
182 if (!message.empty()) {
183 result[
"CalibrationFile"] = message;
184 result[
"CalibrationWorkspace"] = message;
192 alg->setProperty(
"InputWorkspace", inputWS);
193 alg->setPropertyValue(
"Filename", filename);
194 alg->setProperty<
bool>(
"MakeCalWorkspace",
true);
195 alg->setProperty<
bool>(
"MakeGroupingWorkspace",
false);
196 alg->setProperty<
bool>(
"MakeMaskWorkspace",
false);
197 alg->setPropertyValue(
"WorkspaceName",
"temp");
198 alg->executeAsChildAlg();
211 alg->setProperty(
"OffsetsWorkspace", offsetsWS);
212 alg->executeAsChildAlg();
219 if (!calFileName.empty()) {
220 progress(0.0,
"Reading calibration file");
225 throw std::runtime_error(
"Failed to determine calibration information");
250 if (outputWS != inputWS) {
251 outputWS = inputWS->clone();
266 auto eventW = std::dynamic_pointer_cast<EventWorkspace>(outputWS);
272 auto &spec = outputWS->getSpectrum(
size_t(i));
273 auto [
difc,
difa,
tzero] = converter.getDiffConstants(spec.getDetectorIDs());
275 auto &
x = outputWS->dataX(i);
277 std::vector<double> yunused;
278 dSpacingUnit.
fromTOF(
x, yunused, -1., 0,
287 eventW->getSpectrum(i).convertUnitsViaTof(&tofUnit, &dSpacingUnit);
289 }
catch (
const std::runtime_error &) {
293 outputWS->setHistogram(i, BinEdges(outputWS->x(i).size()), Counts(outputWS->y(i).size()));
301 if (eventW->getTofMin() < 0.) {
302 std::stringstream msg;
303 msg <<
"Something wrong with the calibration. Negative minimum d-spacing "
305 << eventW->getTofMin() <<
" d_max " << eventW->getTofMax();
312Parallel::ExecutionMode
314 using namespace Parallel;
315 const auto inputMode = storageModes.at(
"InputWorkspace");
316 const auto &calibrationMode = storageModes.find(
"CalibrationWorkspace");
317 if (calibrationMode != storageModes.end())
318 if (calibrationMode->second != StorageMode::Cloned)
319 return ExecutionMode::Invalid;
320 return getCorrespondingExecutionMode(inputMode);
#define DECLARE_ALGORITHM(classname)
std::map< detid_t, size_t > m_detidToRow
Column_const_sptr m_tzeroCol
Column_const_sptr m_difcCol
Column_const_sptr m_difaCol
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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.
ConstColumnVector gives const access to the column elements without alowing its resizing.
size_t size()
Size of the vector.
void deprecatedDate(const std::string &)
The date the algorithm was deprecated on.
void useAlgorithm(const std::string &, const int version=-1)
The algorithm to use instead of this one.
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Helper class for reporting progress from algorithms.
A validator which checks that a workspace contains raw counts in its bins.
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
int64_t m_numberOfSpectra
number of spectra in input workspace
Parallel::ExecutionMode getParallelExecutionMode(const std::map< std::string, Parallel::StorageMode > &storageModes) const override
Get correct execution mode based on input storage modes for an MPI run.
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 init() override
Virtual method - must be overridden by concrete algorithm.
void exec() override
Executes the algorithm.
const std::string category() const override
Algorithm's category for identification.
void align(const ConversionFactors &converter, API::Progress &progress, API::MatrixWorkspace_sptr &outputWS)
Mantid::API::ITableWorkspace_sptr m_calibrationWS
AlignDetectors()
Constructor.
void getCalibrationWS(const API::MatrixWorkspace_sptr &inputWS)
const std::string name() const override
Algorithms name for identification.
std::map< std::string, std::string > validateInputs() override
Cross-check properties with each other.
void loadCalFile(const API::MatrixWorkspace_sptr &inputWS, const std::string &filename)
An OffsetsWorkspace is a specialized Workspace2D where the Y value at each pixel is the offset to be ...
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
void warning(const std::string &msg)
Logs at warning level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void initialize(const double &_l1, const int &_emode, const UnitParametersMap ¶ms)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
void fromTOF(std::vector< double > &xdata, std::vector< double > &ydata, const double &_l1, const int &_emode, std::initializer_list< std::pair< const UnitParams, double > > params)
Convert from time-of-flight to the concrete unit.
Time of flight in microseconds.
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const Column > Column_const_sptr
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
void setXAxisUnits(const API::MatrixWorkspace_sptr &outputWS)
std::shared_ptr< const OffsetsWorkspace > OffsetsWorkspace_const_sptr
shared pointer to a const OffsetsWorkspace
std::shared_ptr< OffsetsWorkspace > OffsetsWorkspace_sptr
shared pointer to the OffsetsWorkspace class
std::unordered_map< UnitParams, double > UnitParametersMap
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
int32_t detid_t
Typedef for a detector ID.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.