22using namespace Kernel;
23using namespace Geometry;
28 m_useSampleShape(false) {}
31 std::map<std::string, std::string> issues;
32 std::vector<double> prop =
getProperty(
"CylinderAxis");
33 if (prop.size() != 3) {
34 issues[
"CylinderAxis"] =
"CylinderAxis must be a list with 3 elements.";
40 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
41 mustBePositive->setLower(0.0);
43 "The height of the cylindrical sample in centimetres");
45 "The radius of the cylindrical sample in centimetres");
47 "A 3D vector specifying the cylindrical sample's orientation");
49 auto positiveInt = std::make_shared<BoundedValidator<int>>();
50 positiveInt->setLower(1);
52 "The number of slices into which the cylinder is divided for the\n"
55 "The number of annuli into which each slice is divided for the\n"
62 if (!(updateHeight || updateRadius))
70 const auto csgshape =
dynamic_cast<const CSGObject *
>(&sampleShape);
73 const auto &shapeObj = csgshape->
shapeInfo();
85 std::vector<double> axisXYZ =
getProperty(
"CylinderAxis");
88 bool userSuppliedHeight =
false;
89 bool userSuppliedRadius =
false;
94 userSuppliedHeight =
true;
99 userSuppliedRadius =
true;
107 if (userSuppliedHeight && userSuppliedRadius) {
108 g_log.
information(
"Chosing user supplied sample geometry in CylinderAbsorption");
113 const auto &sampleShape =
m_inputWS->sample().getShape();
118 if (heightOk && radiusOk) {
120 }
else if (!heightOk) {
122 throw std::invalid_argument(
"Failed to specify height of cylinder");
124 throw std::invalid_argument(
"Failed to specify height and radius of cylinder");
127 throw std::invalid_argument(
"Failed to specify radius of cylinder");
133 return std::string();
137 const V3D samplePos =
m_inputWS->getInstrument()->getSample()->getPos();
143 std::ostringstream xmlShapeStream;
144 xmlShapeStream <<
"<cylinder id=\"detector-shape\"> "
145 <<
"<centre-of-bottom-base x=\"" << cylBase.
X() <<
"\" y=\"" << cylBase.
Y() <<
"\" z=\"" << cylBase.
Z()
153 return xmlShapeStream.str();
160 throw std::runtime_error(
"Do not have a sample object defined");
163 throw std::runtime_error(
"Sample shape is not a cylinder");
166 throw std::runtime_error(
"Failed to convert shape from IObject to CSGObject");
169 if (raster.l1.size() == 0)
170 throw std::runtime_error(
"Failed to rasterize shape");
173 m_L1s = std::move(raster.l1);
#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.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
A base class for absorption correction algorithms.
std::vector< double > m_elementVolumes
Cached element volumes.
Kernel::V3D m_beamDirection
The direction of the beam.
double m_sampleVolume
The total volume of the sample.
API::MatrixWorkspace_sptr m_inputWS
A pointer to the input workspace.
const Geometry::IObject * m_sampleObject
Local cache of sample object.
size_t m_numVolumeElements
The number of volume elements.
std::vector< Kernel::V3D > m_elementPositions
Cached element positions.
std::vector< double > m_L1s
Cached L1 distances.
Kernel::V3D m_cylAxis
The axis orientation of the cylinder.
void defineProperties() override
A virtual function in which additional properties of an algorithm should be declared.
void initialiseCachedDistances() override
Calculate the distances for L1 and element size for each element in the sample.
int m_numAnnuli
The number of annuli.
CylinderAbsorption()
Default constructor.
double m_cylRadius
The radius of the cylindrical sample in m.
void retrieveProperties() override
Fetch the properties and set the appropriate member variables.
std::string sampleXML() override
Returns the XML string describing the sample, which can be used by the ShapeFactory.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
int m_numSlices
The number of slices.
double m_cylHeight
The height of the cylindrical sample in m.
void getShapeFromSample(const Geometry::IObject &sampleShape, bool updateHeight, bool updateRadius)
Constructive Solid Geometry object.
const detail::ShapeInfo & shapeInfo() const override
IObject : Interface for geometry objects.
virtual detail::ShapeInfo::GeometryShape shape() const =0
virtual bool hasValidShape() const =0
Support for a property that holds an array of values.
void information(const std::string &msg)
Logs at information level.
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
constexpr double Z() const noexcept
Get z.
MANTID_GEOMETRY_DLL Raster calculateCylinder(const Kernel::V3D &beamDirection, const IObject &shape, const size_t numSlices, const size_t numAnnuli)
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.