17#include "MantidTypes/SpectrumDefinition.h"
47 "Workspace to have divergence calculated from");
49 auto positiveParameter = std::make_shared<Kernel::BoundedValidator<double>>();
50 positiveParameter->setLower(0.);
51 positiveParameter->setLowerExclusive(
false);
53 declareProperty(
"alpha", 0., positiveParameter,
"Vertical divergence parameter");
54 declareProperty(
"beta0", 0., positiveParameter,
"Horizontal divergence parameter");
55 declareProperty(
"beta1", 0., positiveParameter,
"Other horizontal divergence parameter");
58 "Workspace containing the divergence of each detector/spectrum");
72 const double horizontal = alpha * alpha;
73 const double vertical_numerator = 4. * (beta0 * beta0 + beta1 * beta1);
77 DataObjects::create<DataObjects::Workspace2D>(*inputWS, HistogramData::Points(1));
80 const auto &spectrumInfo = inputWS->spectrumInfo();
81 const auto samplepos = spectrumInfo.samplePosition();
82 const auto &componentInfo = inputWS->componentInfo();
83 const auto &detectorInfo = inputWS->detectorInfo();
84 size_t numspec = inputWS->getNumberHistograms();
85 double solidangletotal = 0.;
86 for (
size_t i = 0; i < numspec; ++i) {
88 const double twotheta = spectrumInfo.isMonitor(i) ? 0.0 : spectrumInfo.twoTheta(i);
89 const double sintwotheta = sin(twotheta);
91 const double vertical = vertical_numerator / (sintwotheta * sintwotheta);
94 auto &spectrumDefinition = spectrumInfo.spectrumDefinition(i);
97 const double solidangle =
98 std::accumulate(spectrumDefinition.cbegin(), spectrumDefinition.cend(), 0.,
99 [&componentInfo, &detectorInfo, &samplepos](
const auto sum,
const auto &
index) {
100 if (!detectorInfo.isMasked(index.first)) {
101 return sum + componentInfo.solidAngle(index.first, samplepos);
106 solidangletotal += solidangle;
107 const double deltatwotheta = sqrt(solidangle);
110 const double divergence = .5 * sqrt(deltatwotheta * deltatwotheta + horizontal + vertical);
111 divergenceWS->mutableX(i)[0] =
static_cast<double>(i);
112 if (spectrumInfo.isMonitor(i))
113 divergenceWS->mutableY(i)[0] = 0.;
115 divergenceWS->mutableY(i)[0] = divergence;
117 g_log.
notice() <<
"total solid angle " << solidangletotal <<
"\n";
119 setProperty(
"OutputWorkspace", divergenceWS);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
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.
A property class for workspaces.
EstimateDivergence : Calculate the instrument divergence according to Windsor.
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void notice(const std::string &msg)
Logs at notice level.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.