19#include <unordered_map>
24using namespace Geometry;
25using namespace Kernel;
28const std::string UNIT_M =
"m";
29const std::string UNIT_CM =
"cm";
30const std::string UNIT_MM =
"mm";
31static const std::unordered_map<std::string, double> unitToMeters{{UNIT_M, 1.0}, {UNIT_CM, 0.01}, {UNIT_MM, 0.001}};
43 std::make_shared<InstrumentValidator>()),
46 "Estimated centre of mass of illuminated sample volume");
48 auto moreThanZero = std::make_shared<BoundedValidator<double>>();
49 moreThanZero->setLower(1e-6);
51 "The size of one side of an integration element cube in {ElementUnits}");
54 std::make_shared<StringListValidator>(std::vector<std::string>{UNIT_M, UNIT_CM, UNIT_MM}),
55 "The units which ElementSize has been provided in");
62 const V3D beamDirection =
m_inputWS->getInstrument()->getBeamDirection();
65 const std::string elementUnits =
getProperty(
"ElementUnits");
67 auto it = unitToMeters.find(elementUnits);
68 if (it == unitToMeters.end()) {
69 throw std::invalid_argument(
"Supported units for ElementUnits are (m, cm, mm), not: " + elementUnits);
84 const V3D averagePos =
86 setProperty(
"CentreOfMass", std::vector<double>(averagePos));
95 if (raster.l1.size() == 0) {
97 const std::string mess(
"Failed to find any points in the rasterized illumination volume within the sample shape - "
98 "Check sample shape and gauge volume are defined correctly or try reducing the ElementSize");
100 throw std::runtime_error(mess);
111 const std::string mess(
"No shape has been defined for the sample in the input workspace");
113 throw std::invalid_argument(mess);
121 g_log.
information(
"Calculating scattering within the gauge volume defined on "
122 "the input workspace");
133 V3D sum = std::accumulate(pos.begin(), pos.end(),
V3D(0.0, 0.0, 0.0));
134 sum /=
static_cast<double>(pos.size());
138 const std::string mess(
"No intersection points found between illumination volume and sample shape - "
139 "Check sample shape and gauge volume are defined correctly or try reducing the ElementSize");
141 throw std::runtime_error(mess);
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
This class stores information about the sample used in particular run.
const Geometry::IObject & getShape() const
Return the sample shape.
const Geometry::IObject_sptr getShapePtr() const
Return a pointer to the sample shape.
A property class for workspaces.
void init() override
Initialisation code.
const Geometry::IObject_sptr extractValidSampleObject(const API::Sample &sample)
Create the sample object using the Geometry classes, or use the existing one.
const Kernel::V3D rasterizeGaugeVolumeAndCalculateMeanElementPosition(const Kernel::V3D beamDirection, const Geometry::IObject_sptr integrationVolume, const Geometry::IObject_sptr sampleObject)
Calculate as raster of the illumination volume, evaluating which points are within the sample geometr...
void exec() override
Execution code.
double m_cubeSide
Element size of raster.
const Geometry::IObject_sptr getGaugeVolumeObject()
const Kernel::V3D calcAveragePosition(const std::vector< Kernel::V3D > &pos)
API::MatrixWorkspace_sptr m_inputWS
A pointer to the input workspace.
virtual bool hasValidShape() const =0
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
MANTID_GEOMETRY_DLL Raster calculate(const Kernel::V3D &beamDirection, const IObject &integShape, const IObject &sampleShape, const double cubeSizeInMetre)
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
@ Input
An input workspace.
@ Output
An output workspace.