-
Notifications
You must be signed in to change notification settings - Fork 121
/
AnyShapeAbsorption.cpp
84 lines (71 loc) · 2.97 KB
/
AnyShapeAbsorption.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAlgorithms/AnyShapeAbsorption.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidGeometry/Objects/CSGObject.h"
#include "MantidGeometry/Objects/ShapeFactory.h"
#include "MantidGeometry/Objects/Track.h"
#include "MantidGeometry/Rasterize.h"
#include "MantidKernel/BoundedValidator.h"
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(AnyShapeAbsorption)
using namespace Kernel;
using namespace Geometry;
using namespace API;
AnyShapeAbsorption::AnyShapeAbsorption()
: AbsorptionCorrection(), m_cubeSide(0.0) {}
void AnyShapeAbsorption::defineProperties() {
auto moreThanZero = std::make_shared<BoundedValidator<double>>();
moreThanZero->setLower(0.001);
declareProperty("ElementSize", 1.0, moreThanZero,
"The size of one side of an integration element cube in mm");
}
/// Fetch the properties and set the appropriate member variables
void AnyShapeAbsorption::retrieveProperties() {
m_cubeSide = getProperty("ElementSize"); // in mm
m_cubeSide *= 0.001; // now in m
}
std::string AnyShapeAbsorption::sampleXML() {
// Returning an empty string signals to the base class that it should
// use the object already attached to the sample.
return std::string();
}
/// Calculate the distances for L1 and element size for each element in the
/// sample
void AnyShapeAbsorption::initialiseCachedDistances() {
// First, check if a 'gauge volume' has been defined. If not, it's the same as
// the sample.
auto integrationVolume =
std::shared_ptr<const IObject>(m_sampleObject->clone());
if (m_inputWS->run().hasProperty("GaugeVolume")) {
integrationVolume = constructGaugeVolume();
}
auto raster = Geometry::Rasterize::calculate(m_beamDirection,
*integrationVolume, m_cubeSide);
m_sampleVolume = raster.totalvolume;
if (raster.l1.size() == 0)
throw std::runtime_error("Failed to rasterize shape");
// move over the information
m_numVolumeElements = raster.l1.size();
m_L1s = std::move(raster.l1);
m_elementPositions = std::move(raster.position);
m_elementVolumes = std::move(raster.volume);
}
std::shared_ptr<const Geometry::IObject>
AnyShapeAbsorption::constructGaugeVolume() {
g_log.information("Calculating scattering within the gauge volume defined on "
"the input workspace");
// Retrieve and create the gauge volume shape
std::shared_ptr<const Geometry::IObject> volume = ShapeFactory().createShape(
m_inputWS->run().getProperty("GaugeVolume")->value());
return volume;
}
} // namespace Algorithms
} // namespace Mantid