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"
16
17namespace Mantid::Algorithms {
18
19// Register the algorithm into the AlgorithmFactory
20DECLARE_ALGORITHM(AnyShapeAbsorption)
21
22using namespace Kernel;
23using namespace Geometry;
24using namespace API;
26
28
30 auto moreThanZero = std::make_shared<BoundedValidator<double>>();
31 moreThanZero->setLower(0.001);
32 declareProperty("ElementSize", 1.0, moreThanZero, "The size of one side of an integration element cube in mm");
33}
34
37 m_cubeSide = getProperty("ElementSize"); // in mm
38 m_cubeSide *= 0.001; // now in m
39}
40
42 // Returning an empty string signals to the base class that it should
43 // use the object already attached to the sample.
44 return std::string();
45}
46
50 // First, check if a 'gauge volume' has been defined. If not, it's the same as
51 // the sample.
52 IObject_const_sptr integrationVolume;
53 if (m_inputWS->run().hasProperty("GaugeVolume")) {
54 integrationVolume = constructGaugeVolume();
55 } else {
56 try {
57 auto beamProfile = BeamProfileFactory::createBeamProfile(*m_inputWS->getInstrument(), Mantid::API::Sample());
58 integrationVolume = beamProfile->getIntersectionWithSample(*m_sampleObject);
59 } catch (const std::invalid_argument &) {
60 // If createBeamProfile fails, the beam parameters are not defined
61 // If getIntersectionWithSample fails, the beam misses the object
62 // In either case we will just fall back to using the whole sample below.
63 }
64 if (integrationVolume == nullptr) {
65 // If the beam profile is not defined, use the sample object
66 integrationVolume = IObject_const_sptr(m_sampleObject->clone());
67 }
68 }
69
70 auto raster = Geometry::Rasterize::calculate(m_beamDirection, *integrationVolume, *m_sampleObject, m_cubeSide);
71 m_sampleVolume = raster.totalvolume;
72 if (raster.l1.size() == 0)
73 throw std::runtime_error("Failed to rasterize shape");
74 // move over the information
75 m_numVolumeElements = raster.l1.size();
76 m_L1s = std::move(raster.l1);
77 m_elementPositions = std::move(raster.position);
78 m_elementVolumes = std::move(raster.volume);
79}
80
81std::shared_ptr<const Geometry::IObject> AnyShapeAbsorption::constructGaugeVolume() {
82 g_log.information("Calculating scattering within the gauge volume defined on "
83 "the input workspace");
84
85 // Retrieve and create the gauge volume shape
86 std::shared_ptr<const Geometry::IObject> volume =
87 ShapeFactory().createShape(m_inputWS->run().getProperty("GaugeVolume")->value());
88
89 return volume;
90}
91
92} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
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.
Definition Sample.h:33
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.
static std::unique_ptr< IBeamProfile > createBeamProfile(const Geometry::Instrument &instrument, const API::Sample &sample)
virtual IObject * clone() 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...
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
Kernel::Logger g_log("DetermineSpinStateOrder")
MANTID_GEOMETRY_DLL Raster calculate(const Kernel::V3D &beamDirection, const IObject &integShape, const IObject &sampleShape, const double cubeSizeInMetre)
std::shared_ptr< const IObject > IObject_const_sptr
Typdef for a shared pointer to a const object.
Definition IObject.h:95