Mantid
Loading...
Searching...
No Matches
SetBeam.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
14
15namespace {
17constexpr const char *SHAPE_NAME_SLIT = "Slit";
18constexpr const char *SHAPE_NAME_CIRCLE = "Circle";
20constexpr const char *WIDTH_PARAM_NAME = "beam-width";
22constexpr const char *HEIGHT_PARAM_NAME = "beam-height";
24constexpr const char *RADIUS_PARAM_NAME = "beam-radius";
26constexpr const char *SHAPE_PARAM_NAME = "beam-shape";
27} // namespace
28
29namespace Mantid::DataHandling {
30
31// Register the algorithm into the AlgorithmFactory
32DECLARE_ALGORITHM(SetBeam)
33
34
35const std::string SetBeam::name() const { return "SetBeam"; }
36
38int SetBeam::version() const { return 1; }
39
41const std::string SetBeam::category() const { return "Sample"; }
42
44const std::string SetBeam::summary() const { return "Set properties of the beam such as size and shape"; }
45
47std::map<std::string, std::string> SetBeam::validateInputs() {
49
50 std::map<std::string, std::string> errors;
51 PropertyManager_sptr geometryArgs = getProperty("Geometry");
52 if (geometryArgs) {
53 bool s = geometryArgs->existsProperty("Shape");
54 bool w = geometryArgs->existsProperty("Width");
55 bool h = geometryArgs->existsProperty("Height");
56 bool r = geometryArgs->existsProperty("Radius");
57 if (s && ((w && h) != r)) {
58 std::string shape = geometryArgs->getProperty("Shape");
59 if (shape != SHAPE_NAME_SLIT && shape != SHAPE_NAME_CIRCLE) {
60 errors["Geometry"] = "Only 'Slit' and 'Circle' shapes are supported.";
61 }
62 } else {
63 errors["Geometry"] = "'Geometry' flags missing or incorrect. Required flags: Shape, "
64 "plus Width and Height, or Radius";
65 }
66 } else {
67 errors["Geometry"] = "No 'Geometry' flags given.";
68 }
69 return errors;
70}
71
80
81 // In/out
82 auto validator = std::make_shared<InstrumentValidator>(InstrumentValidator::SourcePosition);
84 std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input, validator),
85 "An input workspace with an attached instrument.");
86 declareProperty(std::make_unique<PropertyManagerProperty>("Geometry", Direction::Input),
87 "A dictionary of geometry parameters for the beam");
88}
89
94
97
98 MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
99 PropertyManager_sptr geometryArgs = getProperty("Geometry");
100
101 auto instrument = inputWS->getInstrument();
102 auto source = instrument->getSource();
103 auto &pmap = inputWS->instrumentParameters();
104
105 std::string shape = geometryArgs->getProperty("Shape");
106
107 if (shape.compare("Circle") == 0) {
108 double radius = geometryArgs->getProperty("Radius");
109 // convert to metres
110 radius *= 0.01;
111
112 // Add the values as parameters on the source object
113 pmap.addDouble(source->getComponentID(), RADIUS_PARAM_NAME, radius);
114 pmap.addString(source->getComponentID(), SHAPE_PARAM_NAME, SHAPE_NAME_CIRCLE);
115 } else {
116 double width = geometryArgs->getProperty("Width");
117 double height = geometryArgs->getProperty("Height");
118 // convert to metres
119 width *= 0.01;
120 height *= 0.01;
121
122 // Add the values as parameters on the source object
123 pmap.addDouble(source->getComponentID(), WIDTH_PARAM_NAME, width);
124 pmap.addDouble(source->getComponentID(), HEIGHT_PARAM_NAME, height);
125 pmap.addString(source->getComponentID(), SHAPE_PARAM_NAME, SHAPE_NAME_SLIT);
126 }
127}
128
129} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double height
Definition: GetAllEi.cpp:155
double radius
Definition: Rasterize.cpp:31
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A validator which checks that a workspace has a valid instrument.
Base MatrixWorkspace Abstract Class.
A property class for workspaces.
Set properties of the beam.
Definition: SetBeam.h:17
std::map< std::string, std::string > validateInputs() override final
Definition: SetBeam.cpp:47
int version() const override final
Algorithm's version for identification.
Definition: SetBeam.cpp:38
const std::string summary() const override final
Algorithm's summary for use in the GUI and help.
Definition: SetBeam.cpp:44
const std::string category() const override final
Algorithm's category for identification.
Definition: SetBeam.cpp:41
void init() override final
Initialize the algorithm's properties.
Definition: SetBeam.cpp:74
void exec() override final
Execute.
Definition: SetBeam.cpp:93
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< PropertyManager > PropertyManager_sptr
Typedef for a shared pointer to a PropertyManager.
Generate a tableworkspace to store the calibration results.
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50
@ Input
An input workspace.
Definition: Property.h:53