Mantid
Loading...
Searching...
No Matches
FlatPlateAbsorption.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 +
13
14namespace Mantid::Algorithms {
15
16// Register the algorithm into the AlgorithmFactory
17DECLARE_ALGORITHM(FlatPlateAbsorption)
18
19using namespace Kernel;
20using namespace Geometry;
21using namespace API;
22
24 : AbsorptionCorrection(), m_slabHeight(0.0), m_slabWidth(0.0), m_slabThickness(0.0), m_numXSlices(0),
25 m_numYSlices(0), m_numZSlices(0), m_XSliceThickness(0), m_YSliceThickness(0), m_ZSliceThickness(0) {}
26
28 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
29 mustBePositive->setLower(0.0);
30 declareProperty("SampleHeight", -1.0, mustBePositive, "The height of the plate in cm");
31 declareProperty("SampleWidth", -1.0, mustBePositive, "The width of the plate in cm");
32 declareProperty("SampleThickness", -1.0, mustBePositive, "The thickness of the plate in cm");
33
34 auto moreThanZero = std::make_shared<BoundedValidator<double>>();
35 moreThanZero->setLower(0.001);
36 declareProperty("ElementSize", 1.0, moreThanZero, "The size of one side of an integration element cube in mm");
37}
38
41 m_slabHeight = getProperty("SampleHeight"); // in cm
42 m_slabWidth = getProperty("SampleWidth"); // in cm
43 m_slabThickness = getProperty("SampleThickness"); // in cm
44 m_slabHeight *= 0.01; // now in m
45 m_slabWidth *= 0.01; // now in m
46 m_slabThickness *= 0.01; // now in m
47
48 double cubeSide = getProperty("ElementSize"); // in mm
49 cubeSide *= 0.001; // now in m
50 m_numXSlices = static_cast<int>(m_slabWidth / cubeSide);
51 m_numYSlices = static_cast<int>(m_slabHeight / cubeSide);
52 m_numZSlices = static_cast<int>(m_slabThickness / cubeSide);
56
59}
60
62 // Get the sample position, which is typically the origin but we should be
63 // generic
64 const V3D samplePos = m_inputWS->getInstrument()->getSample()->getPos();
65 // Shift so that plate is centered at sample position
66 const double szX = (m_slabWidth / 2);
67 const double szY = (m_slabHeight / 2);
68 const double szZ = (m_slabThickness / 2);
69
70 std::ostringstream xmlShapeStream;
71 xmlShapeStream << " <cuboid id=\"sample-shape\"> "
72 << "<left-front-bottom-point x=\"" << szX + samplePos.X() << "\" y=\"" << -szY + samplePos.Y()
73 << "\" z=\"" << -szZ + samplePos.Z() << "\" /> "
74 << "<left-front-top-point x=\"" << szX + samplePos.X() << "\" y=\"" << szY + samplePos.Y()
75 << "\" z=\"" << -szZ + samplePos.Z() << "\" /> "
76 << "<left-back-bottom-point x=\"" << szX + samplePos.X() << "\" y=\"" << -szY + samplePos.Y()
77 << "\" z=\"" << szZ + samplePos.Z() << "\" /> "
78 << "<right-front-bottom-point x=\"" << -szX + samplePos.X() << "\" y=\"" << -szY + samplePos.Y()
79 << "\" z=\"" << -szZ + samplePos.Z() << "\" /> "
80 << "</cuboid>";
81
82 return xmlShapeStream.str();
83}
84
88 try {
92 } catch (...) {
93 // Typically get here if the number of volume elements is too large
94 // Provide a bit more information
95 g_log.error("Too many volume elements requested - try increasing the value "
96 "of the ElementSize property.");
97 throw;
98 }
99
100 int counter = 0;
101
102 for (int i = 0; i < m_numZSlices; ++i) {
103 const double z = (i + 0.5) * m_ZSliceThickness - 0.5 * m_slabThickness;
104
105 for (int j = 0; j < m_numYSlices; ++j) {
106 const double y = (j + 0.5) * m_YSliceThickness - 0.5 * m_slabHeight;
107
108 for (int k = 0; k < m_numXSlices; ++k) {
109 const double x = (k + 0.5) * m_XSliceThickness - 0.5 * m_slabWidth;
110 // Set the current position in the sample in Cartesian coordinates.
111 m_elementPositions[counter](x, y, z);
112 // This should never happen for the FlatPlateAbsorption algorithm, but
113 // can for the
114 // inherited CuboidGaugeVolumeAbsorption algorithm if the sample has not
115 // been defined
116 // to fully enclose the requested cuboid
117 if (!m_sampleObject->isValid(m_elementPositions[counter])) {
118 throw Exception::InstrumentDefinitionError("Integration element not located within sample");
119 }
120 // Create track for distance in sample before scattering point
121 Track incoming(m_elementPositions[counter], m_beamDirection * -1.0);
123 m_L1s[counter] = incoming.cbegin()->distFromStart;
124
125 // Also calculate element volume here
127
128 counter++;
129 }
130 }
131 }
132}
133
134} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
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
Kernel::Logger & g_log
Definition: Algorithm.h:451
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.
double m_ZSliceThickness
The thickness of a Z slice in m.
int m_numXSlices
The number of slices in X.
double m_slabThickness
The thickness of the sample in m.
double m_slabHeight
The height of the sample in m.
double m_XSliceThickness
The thickness of an X slice in m.
void defineProperties() override
A virtual function in which additional properties of an algorithm should be declared.
double m_slabWidth
The width of the sample in m.
void initialiseCachedDistances() override
Calculate the distances for L1 and element size for each element in the sample.
int m_numZSlices
The number of slices in Z.
void retrieveProperties() override
Fetch the properties and set the appropriate member variables.
double m_YSliceThickness
The thickness of a Y slice in m.
int m_numYSlices
The number of slices in Y.
std::string sampleXML() override
Returns the XML string describing the sample, which can be used by the ShapeFactory.
virtual int interceptSurface(Geometry::Track &) const =0
virtual bool isValid(const Kernel::V3D &) const =0
Defines a track as a start point and a direction.
Definition: Track.h:165
LType::const_iterator cbegin() const
Returns an interator to the start of the set of links (const version)
Definition: Track.h:206
Exception for errors associated with the instrument definition.
Definition: Exception.h:220
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
Class for 3D vectors.
Definition: V3D.h:34
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234