22#include "boost/lexical_cast.hpp"
29using namespace Kernel;
31using namespace Geometry;
32using namespace DataObjects;
38 std::make_shared<WorkspaceUnitValidator>(
"Wavelength")),
39 "Name the workspace to calculate the resolution for, for "
40 "each pixel and wavelength");
42 "Name of the newly created workspace which contains the Q resolution.");
43 auto positiveDouble = std::make_shared<BoundedValidator<double>>();
44 positiveDouble->setLower(0);
45 declareProperty(
"DeltaR", 0.0, positiveDouble,
"Virtual ring width on the detector (mm).");
46 declareProperty(
"SampleApertureRadius", 0.0, positiveDouble,
"Sample aperture radius, R2 (mm).");
47 declareProperty(
"SourceApertureRadius", 0.0, positiveDouble,
"Source aperture radius, R1 (mm).");
49 std::make_shared<WorkspaceUnitValidator>(
"Wavelength")),
50 "Moderator time spread (microseconds) as a"
51 "function of wavelength (Angstroms).");
52 declareProperty(
"CollimationLength", 0.0, positiveDouble,
"Collimation length (m)");
53 declareProperty(
"AccountForGravity",
false,
"Whether to correct for the effects of gravity");
54 declareProperty(
"ExtraLength", 0.0, positiveDouble,
"Additional length for gravity correction.");
70 const bool doGravity =
getProperty(
"AccountForGravity");
90 const auto &xInterpolate = sigmaModeratorVSwavelength->points(0);
91 const auto &yInterpolate = sigmaModeratorVSwavelength->y(0);
94 if (sigmaModeratorVSwavelength->isHistogramData()) {
95 g_log.
notice() <<
"mid-points of SigmaModerator histogram bins will be "
96 "used for interpolation.";
99 for (
size_t i = 0; i < xInterpolate.size(); ++i) {
100 lookUpTable.
addPoint(xInterpolate[i], yInterpolate[i]);
104 const V3D samplePos = inWS->getInstrument()->getSample()->getPos();
105 const V3D sourcePos = inWS->getInstrument()->getSource()->getPos();
106 const V3D SSD = samplePos - sourcePos;
107 const double L1 = SSD.
norm();
112 if (LCollim == 0.0) {
114 LCollim = collimationLengthEstimator.provideCollimationLength(inWS);
116 "collimation length was estimated to be "
122 const auto numberOfSpectra =
static_cast<int>(inWS->getNumberHistograms());
125 const auto &spectrumInfo = inWS->spectrumInfo();
126 for (
int i = 0; i < numberOfSpectra; i++) {
128 if (!spectrumInfo.hasDetectors(i)) {
129 g_log.
information() <<
"Workspace index " << i <<
" has no detector assigned to it - discarding\n";
134 if (spectrumInfo.isMonitor(i) || spectrumInfo.isMasked(i))
137 const double L2 = spectrumInfo.l2(i);
143 const double theta = spectrumInfo.twoTheta(i);
144 double sinTheta = sin(0.5 * theta);
145 double factor = 4.0 * M_PI * sinTheta;
147 const auto &xIn = inWS->x(i);
148 const size_t xLength = xIn.size();
151 std::unique_ptr<GravitySANSHelper> grav;
153 grav = std::make_unique<GravitySANSHelper>(spectrumInfo, i,
getProperty(
"ExtraLength"));
157 auto &yOut = outWS->mutableY(i);
159 for (
size_t j = 0; j < xLength - 1; j++) {
161 const double wl = (xIn[j + 1] + xIn[j]) / 2.0;
166 double sinThetaGrav = grav->calcSinTheta(wl);
167 factor = 4.0 * M_PI * sinThetaGrav;
169 const double q = factor / wl;
172 const double sigmaSpreadFromBin = xIn[j + 1] - xIn[j];
175 auto sigmaQ = calculator.
getSigmaQValue(lookUpTable.
value(wl), waveLengthIndependentFactor, q, wl,
176 sigmaSpreadFromBin, L1, L2);
181 progress.report(
"Computing Q resolution");
185 outWS->setYUnitLabel(
"QResolution");
197 duplicate->initialize();
198 duplicate->setProperty<
Workspace_sptr>(
"InputWorkspace", inputWorkspace);
199 duplicate->execute();
201 return std::dynamic_pointer_cast<MatrixWorkspace>(temp);
214 rebinned->initialize();
215 rebinned->setProperty(
"WorkspaceToRebin", sigmaModerator);
216 rebinned->setProperty(
"WorkspaceToMatch", inputWorkspace);
217 rebinned->setPropertyValue(
"OutputWorkspace",
"SigmaModeratorRebinned");
230 auto inst = inWS->getInstrument();
231 if (inst->getName().empty()) {
232 throw std::invalid_argument(
"TOFSANSResolutionByPixel: The input workspace "
233 "does not contain an instrument");
#define DECLARE_ALGORITHM(classname)
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Base class from which all concrete algorithm classes should be derived.
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
Helper class which provides the uncertainty calculations for the TOFSANSResolutionByPixel class.
double getSigmaQValue(double moderatorValue, double wavlengthIndependentFactor, double q, double wavelength, double deltaWavelength, double l1, double l2) const
double getWavelengthIndependentFactor(double r1, double r2, double deltaR, double lCollim, double l2) const
Calculates the wavelength-independent prefactor for the resolutin calculation.
TOFSANSResolutionByPixel()
Default constructor.
Mantid::API::MatrixWorkspace_sptr setupOutputWorkspace(const Mantid::API::MatrixWorkspace_sptr &inputWorkspace)
Create an output workspace.
void init() override
Initialisation code.
Mantid::API::MatrixWorkspace_sptr getModeratorWorkspace(const Mantid::API::MatrixWorkspace_sptr &inputWorkspace)
Get the moderator workspace.
void checkInput(const Mantid::API::MatrixWorkspace_sptr &inWS)
Check input.
void exec() override
Execution code.
virtual double getTOFResolution(double wl)
Return the TOF resolution for a particular wavelength.
double m_wl_resolution
Wavelength resolution (constant for all wavelengths)
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Provide interpolation over a series of points.
double value(const double &at) const
get interpolated value at location at
void addPoint(const double &xx, const double &yy)
add data point
void notice(const std::string &msg)
Logs at notice level.
void information(const std::string &msg)
Logs at information level.
double norm() const noexcept
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
@ Input
An input workspace.
@ Output
An output workspace.