18#include "Poco/NumberFormatter.h"
25using namespace Kernel;
27using namespace Geometry;
28using namespace DataObjects;
32 "The name of the input file to load");
34 "Then name of the output workspace");
35 declareProperty(
"NoBeamCenter",
false,
"If true, the detector will not be moved according to the beam center");
39 "Sample to detector distance to use (overrides meta data), in mm");
41 "Offset to the sample to detector distance (use only when "
42 "using the distance found in the meta data), in mm."
43 "Not used when SampleDetectorDistance is provided.");
48 auto mustBePositive = std::make_shared<Kernel::BoundedValidator<double>>();
49 mustBePositive->setLower(0.0);
51 "Wavelength value to use when loading the data file (Angstrom).");
53 "Wavelength spread to use when loading the data file (default 0.0)");
61 double default_ctr_x_pix = 0.0;
62 double default_ctr_y_pix = 0.0;
63 double default_ctr_x = 0.0;
64 double default_ctr_y = 0.0;
71 center_x = default_ctr_x_pix;
72 center_y = default_ctr_y_pix;
73 g_log.
information() <<
"Setting beam center to [" << Poco::NumberFormatter::format(center_x, 1) <<
", "
74 << Poco::NumberFormatter::format(center_y, 1) <<
"]\n";
78 double beam_ctr_x = 0.0;
79 double beam_ctr_y = 0.0;
84 mvAlg->setProperty(
"ComponentName",
"detector1");
85 mvAlg->setProperty(
"X", default_ctr_x - beam_ctr_x);
86 mvAlg->setProperty(
"Y", default_ctr_y - beam_ctr_y);
87 mvAlg->setProperty(
"RelativePosition",
true);
88 mvAlg->executeAsChildAlg();
89 g_log.
information() <<
"Moving beam center to " << center_x <<
" " << center_y <<
'\n';
100 const std::string reductionManagerName =
getProperty(
"ReductionProperties");
101 std::shared_ptr<PropertyManager> reductionManager;
105 reductionManager = std::make_shared<PropertyManager>();
114 if (!reductionManager->existsProperty(
"LoadAlgorithm")) {
115 auto algProp = std::make_unique<AlgorithmProperty>(
"LoadAlgorithm");
117 reductionManager->declareProperty(std::move(algProp));
123 std::string output_message;
124 const double wavelength_input =
getProperty(
"Wavelength");
125 const double wavelength_spread_input =
getProperty(
"WavelengthSpread");
130 loadAlg->setProperty(
"Filename", fileName);
131 loadAlg->setPropertyValue(
"OutputWorkspace",
getPropertyValue(
"OutputWorkspace"));
132 if (!
isEmpty(wavelength_input)) {
133 loadAlg->setProperty(
"Wavelength", wavelength_input);
134 loadAlg->setProperty(
"WavelengthSpread", wavelength_spread_input);
137 loadAlg->executeAsChildAlg();
147 g_log.
warning() <<
"Unable to load file as a SPICE file. Trying to load as "
150 loadAlg->setProperty(
"Filename", fileName);
151 loadAlg->executeAsChildAlg();
152 Workspace_sptr dataWS_tmp = loadAlg->getProperty(
"OutputWorkspace");
154 dataWS->mutableRun().addProperty(
"is_sensitivity", 1,
"",
true);
155 setProperty<MatrixWorkspace_sptr>(
"OutputWorkspace", dataWS);
156 g_log.
notice() <<
"Successfully loaded " << fileName <<
" and setting sensitivity flag to True\n";
159 Workspace_sptr dataWS_tmp = loadAlg->getProperty(
"OutputWorkspace");
161 g_log.
debug() <<
"Calling LoadSpice2D Done. OutputWorkspace name = " << dataWS_tmp->getName() <<
'\n';
169 const double sample_det_dist =
getProperty(
"SampleDetectorDistance");
170 if (!
isEmpty(sample_det_dist)) {
171 g_log.
debug() <<
"Getting the SampleDetectorDistance = " << sample_det_dist
172 <<
" from the Algorithm input property.\n";
173 sdd = sample_det_dist;
175 const std::string sddName =
"total-sample-detector-distance";
179 throw std::runtime_error(
"Could not cast (interpret) the property " + sddName +
180 " as a floating point numeric value.");
185 const double sample_det_offset =
getProperty(
"SampleDetectorDistanceOffset");
186 if (!
isEmpty(sample_det_offset)) {
187 sdd += sample_det_offset;
190 dataWS->mutableRun().addProperty(
"sample_detector_distance", sdd,
"mm",
true);
191 g_log.
debug() <<
"FINAL: Using Total Sample Detector Distance = " << sdd <<
"\n";
193 progress.report(
"MoveInstrumentComponent...");
198 mvAlg->setProperty(
"ComponentName",
"detector1");
199 mvAlg->setProperty(
"Z", sdd / 1000.0);
200 mvAlg->setProperty(
"RelativePosition",
false);
201 mvAlg->executeAsChildAlg();
203 output_message +=
" Detector position: " + Poco::NumberFormatter::format(sdd / 1000.0, 3) +
" m\n";
206 double src_to_sample = 0.0;
210 dataWS->mutableRun().addProperty(
"source-sample-distance", src_to_sample,
"mm",
true);
212 " Computed SSD from number of guides: " + Poco::NumberFormatter::format(src_to_sample / 1000.0, 3) +
" \n";
217 output_message +=
" Could not compute SSD from number of guides, taking: " +
218 Poco::NumberFormatter::format(src_to_sample / 1000.0, 3) +
" \n";
221 const std::string sampleADName =
"sample-aperture-diameter";
225 throw std::runtime_error(
"Could not cast (interpret) the property " + sampleADName +
226 " as a floating point numeric value.");
228 double sample_apert = *dp;
230 const std::string sourceADName =
"source-aperture-diameter";
231 prop = dataWS->run().getProperty(sourceADName);
234 throw std::runtime_error(
"Could not cast (interpret) the property " + sourceADName +
235 " as a floating point numeric value.");
237 double source_apert = *dp;
239 const double beam_diameter = sdd / src_to_sample * (source_apert + sample_apert) + sample_apert;
240 dataWS->mutableRun().addProperty(
"beam-diameter", beam_diameter,
"mm",
true);
242 progress.report(
"Move to center beam...");
248 const bool noBeamCenter =
getProperty(
"NoBeamCenter");
253 if (reductionManager->existsProperty(
"LatestBeamCenterX") &&
254 reductionManager->existsProperty(
"LatestBeamCenterY")) {
255 center_x = reductionManager->getProperty(
"LatestBeamCenterX");
256 center_y = reductionManager->getProperty(
"LatestBeamCenterY");
267 if (!reductionManager->existsProperty(
"LatestBeamCenterX"))
270 reductionManager->setProperty(
"LatestBeamCenterX", center_x);
271 if (!reductionManager->existsProperty(
"LatestBeamCenterY"))
274 reductionManager->setProperty(
"LatestBeamCenterY", center_y);
276 dataWS->mutableRun().addProperty(
"beam_center_x", center_x,
"pixel",
true);
277 dataWS->mutableRun().addProperty(
"beam_center_y", center_y,
"pixel",
true);
278 output_message +=
" Beam center: " + Poco::NumberFormatter::format(center_x, 1) +
", " +
279 Poco::NumberFormatter::format(center_y, 1) +
"\n";
283 dataWS->mutableRun().addProperty(
"beam_center_x", center_x,
"pixel",
true);
284 dataWS->mutableRun().addProperty(
"beam_center_y", center_y,
"pixel",
true);
285 output_message +=
" Default beam center: " + Poco::NumberFormatter::format(center_x, 1) +
", " +
286 Poco::NumberFormatter::format(center_y, 1) +
"\n";
289 setProperty<MatrixWorkspace_sptr>(
"OutputWorkspace", std::dynamic_pointer_cast<MatrixWorkspace>(dataWS));
#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.
std::string toString() const override
Serialize an object to a string.
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.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
@ Load
allowed here which will be passed to the algorithm
Helper class for reporting progress from algorithms.
A property class for workspaces.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
Base class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void moveToBeamCenter(API::MatrixWorkspace_sptr &dataWS, double ¢er_x, double ¢er_y)
Move the detector according to the beam center.
void exec() override
Execution code.
void init() override
Initialisation code.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
void getDefaultBeamCenter(const API::MatrixWorkspace_sptr &dataWS, double &pixel_x, double &pixel_y)
double getSourceToSampleDistance(const API::MatrixWorkspace_sptr &dataWS)
void getCoordinateFromPixel(const double &pixel_x, const double &pixel_y, const API::MatrixWorkspace_sptr &dataWS, double &x, double &y)
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.