Mantid
Loading...
Searching...
No Matches
AnyShapeAbsorption.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 +
9#include "MantidAPI/Run.h"
15
16namespace Mantid::Algorithms {
17
18// Register the algorithm into the AlgorithmFactory
19DECLARE_ALGORITHM(AnyShapeAbsorption)
20
21using namespace Kernel;
22using namespace Geometry;
23using namespace API;
24
26
28 auto moreThanZero = std::make_shared<BoundedValidator<double>>();
29 moreThanZero->setLower(0.001);
30 declareProperty("ElementSize", 1.0, moreThanZero, "The size of one side of an integration element cube in mm");
31}
32
35 m_cubeSide = getProperty("ElementSize"); // in mm
36 m_cubeSide *= 0.001; // now in m
37}
38
40 // Returning an empty string signals to the base class that it should
41 // use the object already attached to the sample.
42 return std::string();
43}
44
48 // First, check if a 'gauge volume' has been defined. If not, it's the same as
49 // the sample.
50 auto integrationVolume = std::shared_ptr<const IObject>(m_sampleObject->clone());
51 if (m_inputWS->run().hasProperty("GaugeVolume")) {
52 integrationVolume = constructGaugeVolume();
53 }
54
55 auto raster = Geometry::Rasterize::calculate(m_beamDirection, *integrationVolume, m_cubeSide);
56 m_sampleVolume = raster.totalvolume;
57 if (raster.l1.size() == 0)
58 throw std::runtime_error("Failed to rasterize shape");
59 // move over the information
60 m_numVolumeElements = raster.l1.size();
61 m_L1s = std::move(raster.l1);
62 m_elementPositions = std::move(raster.position);
63 m_elementVolumes = std::move(raster.volume);
64}
65
66std::shared_ptr<const Geometry::IObject> AnyShapeAbsorption::constructGaugeVolume() {
67 g_log.information("Calculating scattering within the gauge volume defined on "
68 "the input workspace");
69
70 // Retrieve and create the gauge volume shape
71 std::shared_ptr<const Geometry::IObject> volume =
72 ShapeFactory().createShape(m_inputWS->run().getProperty("GaugeVolume")->value());
73
74 return volume;
75}
76
77} // 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.
std::string sampleXML() override
Returns the XML string describing the sample, which can be used by the ShapeFactory.
void defineProperties() override
A virtual function in which additional properties of an algorithm should be declared.
void retrieveProperties() override
Fetch the properties and set the appropriate member variables.
std::shared_ptr< const Geometry::IObject > constructGaugeVolume()
Create the gague volume for the correction.
double m_cubeSide
The length of the side of an element cube in m.
void initialiseCachedDistances() override
Calculate the distances for L1 and element size for each element in the sample.
virtual IObject * clone() const =0
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
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...
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
MANTID_GEOMETRY_DLL Raster calculate(const Kernel::V3D &beamDirection, const IObject &shape, const double cubeSizeInMetre)
Definition: Rasterize.cpp:181