21#include "boost/lexical_cast.hpp"
28using namespace Kernel;
30using namespace Geometry;
31using namespace DataObjects;
37 std::make_shared<WorkspaceUnitValidator>(
"Wavelength")),
38 "Name the workspace to calculate the resolution for, for "
39 "each pixel and wavelength");
41 "Name of the newly created workspace which contains the Q resolution.");
42 auto positiveDouble = std::make_shared<BoundedValidator<double>>();
43 positiveDouble->setLower(0);
44 declareProperty(
"DeltaR", 0.0, positiveDouble,
"Virtual ring width on the detector (mm).");
45 declareProperty(
"SampleApertureRadius", 0.0, positiveDouble,
"Sample aperture radius, R2 (mm).");
46 declareProperty(
"SourceApertureRadius", 0.0, positiveDouble,
"Source aperture radius, R1 (mm).");
48 std::make_shared<WorkspaceUnitValidator>(
"Wavelength")),
49 "Moderator time spread (microseconds) as a"
50 "function of wavelength (Angstroms).");
51 declareProperty(
"CollimationLength", 0.0, positiveDouble,
"Collimation length (m)");
52 declareProperty(
"AccountForGravity",
false,
"Whether to correct for the effects of gravity");
53 declareProperty(
"ExtraLength", 0.0, positiveDouble,
"Additional length for gravity correction.");
69 const bool doGravity =
getProperty(
"AccountForGravity");
89 const auto &xInterpolate = sigmaModeratorVSwavelength->points(0);
90 const auto &yInterpolate = sigmaModeratorVSwavelength->y(0);
93 if (sigmaModeratorVSwavelength->isHistogramData()) {
94 g_log.
notice() <<
"mid-points of SigmaModerator histogram bins will be "
95 "used for interpolation.";
98 for (
size_t i = 0; i < xInterpolate.size(); ++i) {
99 lookUpTable.
addPoint(xInterpolate[i], yInterpolate[i]);
103 const V3D samplePos = inWS->getInstrument()->getSample()->getPos();
104 const V3D sourcePos = inWS->getInstrument()->getSource()->getPos();
105 const V3D SSD = samplePos - sourcePos;
106 const double L1 = SSD.
norm();
111 if (LCollim == 0.0) {
113 LCollim = collimationLengthEstimator.provideCollimationLength(inWS);
115 "collimation length was estimated to be "
121 const auto numberOfSpectra =
static_cast<int>(inWS->getNumberHistograms());
124 const auto &spectrumInfo = inWS->spectrumInfo();
125 for (
int i = 0; i < numberOfSpectra; i++) {
127 if (!spectrumInfo.hasDetectors(i)) {
128 g_log.
information() <<
"Workspace index " << i <<
" has no detector assigned to it - discarding\n";
133 if (spectrumInfo.isMonitor(i) || spectrumInfo.isMasked(i))
136 const double L2 = spectrumInfo.l2(i);
142 const double theta = spectrumInfo.twoTheta(i);
143 double sinTheta = sin(0.5 * theta);
144 double factor = 4.0 * M_PI * sinTheta;
146 const auto &xIn = inWS->x(i);
147 const size_t xLength = xIn.size();
150 std::unique_ptr<GravitySANSHelper> grav;
152 grav = std::make_unique<GravitySANSHelper>(spectrumInfo, i,
getProperty(
"ExtraLength"));
156 auto &yOut = outWS->mutableY(i);
158 for (
size_t j = 0; j < xLength - 1; j++) {
160 const double wl = (xIn[j + 1] + xIn[j]) / 2.0;
165 double sinThetaGrav = grav->calcSinTheta(wl);
166 factor = 4.0 * M_PI * sinThetaGrav;
168 const double q = factor / wl;
171 const double sigmaSpreadFromBin = xIn[j + 1] - xIn[j];
174 auto sigmaQ = calculator.
getSigmaQValue(lookUpTable.
value(wl), waveLengthIndependentFactor, q, wl,
175 sigmaSpreadFromBin, L1, L2);
180 progress.report(
"Computing Q resolution");
184 outWS->setYUnitLabel(
"QResolution");
196 duplicate->initialize();
197 duplicate->setProperty<
Workspace_sptr>(
"InputWorkspace", inputWorkspace);
198 duplicate->execute();
200 return std::dynamic_pointer_cast<MatrixWorkspace>(temp);
213 rebinned->initialize();
214 rebinned->setProperty(
"WorkspaceToRebin", sigmaModerator);
215 rebinned->setProperty(
"WorkspaceToMatch", inputWorkspace);
216 rebinned->setPropertyValue(
"OutputWorkspace",
"SigmaModeratorRebinned");
229 auto inst = inWS->getInstrument();
230 if (inst->getName().empty()) {
231 throw std::invalid_argument(
"TOFSANSResolutionByPixel: The input workspace "
232 "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.