30const std::string CAL_FILE(
"Filename");
31const std::string GROUP_FILE(
"GroupFilename");
32const std::string MAKE_CAL(
"MakeCalWorkspace");
33const std::string MAKE_GRP(
"MakeGroupingWorkspace");
34const std::string MAKE_MSK(
"MakeMaskWorkspace");
52 return "Applies a calibration to a workspace for powder diffraction";
59 "Set the workspace whose instrument should be updated");
60 const std::vector<std::string> exts{
".h5",
".hd5",
".hdf",
".cal"};
62 "Optional: The .cal file containing the position correction factors. "
63 "Either this, CalibrationWorkspace or OffsetsWorkspace needs to be "
67 "Optional: Set the Diffraction Calibration workspace");
70 "Optional: A OffsetsWorkspace containing the calibration offsets. Either "
71 "this, CalibrationWorkspace or CalibrationFile needs to be specified.");
72 declareProperty(
"ClearCalibration",
false,
"Remove any existing calibration from the workspace");
82 std::map<std::string, std::string> result;
88 if (!std::dynamic_pointer_cast<ExperimentInfo>(inputWS)) {
89 result[
"InstrumentWorkspace"] =
"InputWorkspace type invalid. "
90 "Expected MatrixWorkspace, "
96 const std::string calFileName =
getProperty(
"CalibrationFile");
97 if (!calFileName.empty())
101 if (
bool(calibrationWS))
108 bool clearCalibration =
getProperty(
"ClearCalibration");
110 if ((clearCalibration) && (numWays > 0)) {
111 message =
"You cannot supply a calibration input when clearing the calibration.";
113 if (!clearCalibration) {
115 message =
"You must specify only one of CalibrationFile, "
116 "CalibrationWorkspace, OffsetsWorkspace.";
119 message =
"You must specify one of CalibrationFile, "
120 "CalibrationWorkspace, OffsetsWorkspace.";
124 if (!message.empty()) {
125 result[
"CalibrationFile"] = message;
126 result[
"CalibrationWorkspace"] = message;
134 alg->setProperty(
"InputWorkspace", inputWS);
135 alg->setPropertyValue(
"Filename", filename);
136 alg->setProperty<
bool>(
"MakeCalWorkspace",
true);
137 alg->setProperty<
bool>(
"MakeGroupingWorkspace",
false);
138 alg->setProperty<
bool>(
"MakeMaskWorkspace",
false);
139 alg->setPropertyValue(
"WorkspaceName",
"temp");
140 alg->executeAsChildAlg();
153 alg->setProperty(
"OffsetsWorkspace", offsetsWS);
154 alg->executeAsChildAlg();
161 if (!calFileName.empty()) {
162 progress(0.0,
"Reading calibration file");
167 throw std::runtime_error(
"Failed to determine calibration information");
177 auto experimentInfo = std::dynamic_pointer_cast<API::ExperimentInfo>(InstrumentWorkspace);
178 auto instrument = experimentInfo->getInstrument();
179 auto ¶mMap = experimentInfo->instrumentParameters();
180 bool clearCalibration =
getProperty(
"ClearCalibration");
181 if (clearCalibration) {
182 paramMap.clearParametersByName(
"DIFC");
183 paramMap.clearParametersByName(
"DIFA");
184 paramMap.clearParametersByName(
"TZERO");
193 auto detids = instrument->getDetectorIDs();
194 std::sort(detids.begin(), detids.end());
197 auto detid =
static_cast<detid_t>((*detIdColumn)[i]);
198 double difc = (*difcColumn)[i];
199 double difa = (*difaColumn)[i];
200 double tzero = (*tzeroColumn)[i];
202 if (std::binary_search(detids.begin(), detids.end(), detid)) {
204 auto det = instrument->getDetector(detid);
205 paramMap.addDouble(det->getComponentID(),
"DIFC",
difc);
206 paramMap.addDouble(det->getComponentID(),
"DIFA",
difa);
207 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.