42 return "Applies a calibration to a workspace for powder diffraction";
49 "Set the workspace whose instrument should be updated");
50 const std::vector<std::string> exts{
".h5",
".hd5",
".hdf",
".cal"};
52 "Optional: The .cal file containing the position correction factors. "
53 "Either this, CalibrationWorkspace or OffsetsWorkspace needs to be "
57 "Optional: Set the Diffraction Calibration workspace");
60 "Optional: A OffsetsWorkspace containing the calibration offsets. Either "
61 "this, CalibrationWorkspace or CalibrationFile needs to be specified.");
62 declareProperty(
"ClearCalibration",
false,
"Remove any existing calibration from the workspace");
72 std::map<std::string, std::string> result;
78 if (!std::dynamic_pointer_cast<ExperimentInfo>(inputWS)) {
79 result[
"InstrumentWorkspace"] =
"InputWorkspace type invalid. "
80 "Expected MatrixWorkspace, "
86 const std::string calFileName =
getProperty(
"CalibrationFile");
87 if (!calFileName.empty())
91 if (
bool(calibrationWS))
98 bool clearCalibration =
getProperty(
"ClearCalibration");
100 if ((clearCalibration) && (numWays > 0)) {
101 message =
"You cannot supply a calibration input when clearing the calibration.";
103 if (!clearCalibration) {
105 message =
"You must specify only one of CalibrationFile, "
106 "CalibrationWorkspace, OffsetsWorkspace.";
109 message =
"You must specify one of CalibrationFile, "
110 "CalibrationWorkspace, OffsetsWorkspace.";
114 if (!message.empty()) {
115 result[
"CalibrationFile"] = message;
116 result[
"CalibrationWorkspace"] = message;
124 alg->setProperty(
"InputWorkspace", inputWS);
125 alg->setPropertyValue(
"Filename", filename);
126 alg->setProperty<
bool>(
"MakeCalWorkspace",
true);
127 alg->setProperty<
bool>(
"MakeGroupingWorkspace",
false);
128 alg->setProperty<
bool>(
"MakeMaskWorkspace",
false);
129 alg->setPropertyValue(
"WorkspaceName",
"temp");
130 alg->executeAsChildAlg();
143 alg->setProperty(
"OffsetsWorkspace", offsetsWS);
144 alg->executeAsChildAlg();
151 if (!calFileName.empty()) {
152 progress(0.0,
"Reading calibration file");
157 throw std::runtime_error(
"Failed to determine calibration information");
167 auto experimentInfo = std::dynamic_pointer_cast<API::ExperimentInfo>(InstrumentWorkspace);
168 auto instrument = experimentInfo->getInstrument();
169 auto ¶mMap = experimentInfo->instrumentParameters();
170 bool clearCalibration =
getProperty(
"ClearCalibration");
171 if (clearCalibration) {
172 paramMap.clearParametersByName(
"DIFC");
173 paramMap.clearParametersByName(
"DIFA");
174 paramMap.clearParametersByName(
"TZERO");
183 auto detids = instrument->getDetectorIDs();
184 std::sort(detids.begin(), detids.end());
187 auto detid =
static_cast<detid_t>((*detIdColumn)[i]);
188 double difc = (*difcColumn)[i];
189 double difa = (*difaColumn)[i];
190 double tzero = (*tzeroColumn)[i];
192 if (std::binary_search(detids.begin(), detids.end(), detid)) {
194 auto det = instrument->getDetector(detid);
195 paramMap.addDouble(det->getComponentID(),
"DIFC",
difc);
196 paramMap.addDouble(det->getComponentID(),
"DIFA",
difa);
197 paramMap.addDouble(det->getComponentID(),
"TZERO",
tzero);
#define DECLARE_ALGORITHM(classname)
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.
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
A property class for workspaces.
void exec() override
Execute the algorithm.
void getCalibrationWS(const Mantid::API::Workspace_sptr &inputWS)
std::map< std::string, std::string > validateInputs() override
Cross-check properties with each other.
void loadCalFile(const Mantid::API::Workspace_sptr &inputWS, const std::string &filename)
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
Mantid::API::ITableWorkspace_sptr m_calibrationWS
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
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< const OffsetsWorkspace > OffsetsWorkspace_const_sptr
shared pointer to a const OffsetsWorkspace
std::shared_ptr< OffsetsWorkspace > OffsetsWorkspace_sptr
shared pointer to the OffsetsWorkspace class
int32_t detid_t
Typedef for a detector ID.
Describes the direction (within an algorithm) of a Property.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.