22#include <boost/math/special_functions/round.hpp>
30using namespace CurveFitting;
32using namespace Kernel;
38Logger
g_log(
"SCDPanelErrors");
76 if (detname.compare(
"none") == 0.0)
81 if (inst->getName().compare(
"CORELLI") == 0.0 && detname !=
"moderator")
82 detname.append(
"/sixteenpack");
84 if (
x != 0.0 ||
y != 0.0 ||
z != 0.0) {
88 alg1->setLogging(
false);
90 alg1->setPropertyValue(
"ComponentName", detname);
92 alg1->setProperty(
"X",
x);
93 alg1->setProperty(
"Y",
y);
94 alg1->setProperty(
"Z",
z);
95 alg1->setPropertyValue(
"RelativePosition",
"1");
102 algx->setChild(
true);
103 algx->setLogging(
false);
105 algx->setPropertyValue(
"ComponentName", detname);
106 algx->setProperty(
"X", 1.0);
107 algx->setProperty(
"Y", 0.0);
108 algx->setProperty(
"Z", 0.0);
109 algx->setProperty(
"Angle", rotx);
110 algx->setPropertyValue(
"RelativeRotation",
"1");
117 algy->setChild(
true);
118 algy->setLogging(
false);
120 algy->setPropertyValue(
"ComponentName", detname);
121 algy->setProperty(
"X", 0.0);
122 algy->setProperty(
"Y", 1.0);
123 algy->setProperty(
"Z", 0.0);
124 algy->setProperty(
"Angle", roty);
125 algy->setPropertyValue(
"RelativeRotation",
"1");
132 algz->setChild(
true);
133 algz->setLogging(
false);
135 algz->setPropertyValue(
"ComponentName", detname);
136 algz->setProperty(
"X", 0.0);
137 algz->setProperty(
"Y", 0.0);
138 algz->setProperty(
"Z", 1.0);
139 algz->setProperty(
"Angle", rotz);
140 algz->setPropertyValue(
"RelativeRotation",
"1");
145 std::shared_ptr<const Geometry::RectangularDetector> rectDet =
146 std::dynamic_pointer_cast<const Geometry::RectangularDetector>(comp);
149 auto oldscalex =
pmap.getDouble(rectDet->getName(),
"scalex");
150 auto oldscaley =
pmap.getDouble(rectDet->getName(),
"scaley");
151 double relscalex =
scalex;
152 double relscaley =
scaley;
153 if (!oldscalex.empty())
154 relscalex /= oldscalex[0];
155 if (!oldscaley.empty())
156 relscaley /= oldscaley[0];
157 pmap.addDouble(rectDet.get(),
"scalex",
scalex);
158 pmap.addDouble(rectDet.get(),
"scaley",
scaley);
166void SCDPanelErrors::eval(
double xshift,
double yshift,
double zshift,
double xrotate,
double yrotate,
double zrotate,
167 double scalex,
double scaley,
double *out,
const double *xValues,
const size_t nData,
168 double tShift)
const {
175 std::shared_ptr<API::Workspace> cloned =
m_workspace->clone();
178 auto inputP = std::dynamic_pointer_cast<DataObjects::PeaksWorkspace>(cloned);
187 auto inst = inputP->getInstrument();
189 for (
int i = 0; i < inputP->getNumberPeaks(); i++) {
191 V3D hkl =
V3D(boost::math::iround(peak.
getH()), boost::math::iround(peak.
getK()), boost::math::iround(peak.
getL()));
194 if (hkl ==
V3D(0, 0, 0))
195 throw std::runtime_error(
"unindexed peak");
199 wl.
initialize(peak2.
getL1(), 0, {{UnitParams::l2, peak2.getL2()}, {UnitParams::twoTheta, peak2.getScattering()}});
200 peak2.setWavelength(wl.singleFromTOF(peak.
getTOF() + tShift));
201 V3D Q3 = peak2.getQSampleFrame();
202 out[i * 3] = Q3[0] - Q2[0];
203 out[i * 3 + 1] = Q3[1] - Q2[1];
204 out[i * 3 + 2] = Q3[2] - Q2[2];
205 }
catch (std::runtime_error &) {
208 out[i * 3 + 1] = 0.15;
209 out[i * 3 + 2] = 0.15;
220void SCDPanelErrors::function1D(
double *out,
const double *xValues,
const size_t nData)
const {
221 const double xshift = getParameter(
"XShift");
222 const double yshift = getParameter(
"YShift");
223 const double zshift = getParameter(
"ZShift");
224 const double xrotate = getParameter(
"XRotate");
225 const double yrotate = getParameter(
"YRotate");
226 const double zrotate = getParameter(
"ZRotate");
227 const double scalex = getParameter(
"ScaleWidth");
228 const double scaley = getParameter(
"ScaleHeight");
229 const double tShift = getParameter(
"T0Shift");
230 eval(xshift, yshift, zshift, xrotate, yrotate, zrotate,
scalex,
scaley, out, xValues, nData, tShift);
240void SCDPanelErrors::functionDeriv1D(
API::Jacobian *out,
const double *xValues,
const size_t nData) {
242 this->calNumericalDeriv(domain, *out);
246void SCDPanelErrors::clear()
const { m_setupFinished =
false; }
253 if (attName ==
"FileName") {
254 std::string fileName =
value.asUnquotedString();
255 if (fileName.empty()) {
256 storeAttributeValue(
"FileName",
Attribute(
"",
true));
260 std::string
error = fval.isValid(fileName);
262 storeAttributeValue(attName,
Attribute(fileName,
true));
263 storeAttributeValue(
"Workspace",
Attribute(
""));
269 }
else if (attName ==
"Workspace") {
270 std::string wsName =
value.asString();
271 if (!wsName.empty()) {
272 storeAttributeValue(attName,
value);
273 storeAttributeValue(
"FileName",
Attribute(
"",
true));
274 loadWorkspace(wsName);
278 m_setupFinished =
false;
286void SCDPanelErrors::load(
const std::string &fname) {
288 loadAlg->initialize();
289 loadAlg->setChild(
true);
290 loadAlg->setLogging(
false);
292 loadAlg->setPropertyValue(
"Filename", fname);
293 loadAlg->setPropertyValue(
"OutputWorkspace",
"_SCDPanelErrors_fit_data_");
295 }
catch (std::runtime_error &) {
296 throw std::runtime_error(
"Unable to load Nexus file for SCDPanelErrors function.");
301 loadWorkspace(resData);
308void SCDPanelErrors::loadWorkspace(
const std::string &wsName)
const {
317void SCDPanelErrors::loadWorkspace(std::shared_ptr<API::Workspace> ws)
const {
318 m_workspace = std::move(ws);
319 m_setupFinished =
false;
325void SCDPanelErrors::setupData()
const {
326 if (m_setupFinished) {
327 g_log.
debug() <<
"Re-setting isn't required.";
332 std::string wsName = getAttribute(
"Workspace").asString();
334 throw std::invalid_argument(
"Data not set for function " + this->name());
336 loadWorkspace(wsName);
339 m_bank = getAttribute(
"Bank").asString();
341 g_log.
debug() <<
"Setting up " << m_workspace->getName() <<
" bank " << m_bank <<
'\n';
343 m_setupFinished =
true;
double value
The value of the point.
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Mantid::API::IFunction::Attribute Attribute
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
1D domain - a wrapper around an array of doubles.
Attribute is a non-fitting parameter.
void declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue)
Declare a single attribute.
virtual void setAttribute(const std::string &name, const Attribute &)
Set a value to attribute attName.
Represents the Jacobian in IFitFunction::functionDeriv.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
Base Workspace Abstract Class.
void moveDetector(double x, double y, double z, double rotx, double roty, double rotz, double scalex, double scaley, std::string detname, const API::Workspace_sptr &inputW) const
Move detectors with parameters.
std::string m_bank
Stores bank.
static const int defaultIndexValue
The default value for the workspace index.
std::shared_ptr< API::Workspace > m_workspace
Temporary workspace holder.
SCDPanelErrors()
Constructor.
void setupData() const
Fill in the workspace and bank names.
void eval(double xshift, double yshift, double zshift, double xrotate, double yrotate, double zrotate, double scalex, double scaley, double *out, const double *xValues, const size_t nData, double tShift) const
Evaluate the function for a list of arguments and given scaling factor.
double getL() const override
Get the L index of the peak.
double getK() const override
Get the K index of the peak.
double getH() const override
Get the H index of the peak.
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Structure describing a single-crystal peak.
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
double getTOF() const override
Calculate the time of flight (in microseconds) of the neutrons for this peak, using the geometry of t...
int getDetectorID() const
Get the ID of the detector at the center of the peak
Class to implement UB matrix.
Kernel::V3D qFromHKL(const Kernel::V3D &hkl) const
Return Q-sample coordinates from hkl.
Records the filename and the description of failure.
FileValidator is a validator that checks that a filepath is valid.
void debug(const std::string &msg)
Logs at debug level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void initialize(const double &_l1, const int &_emode, const UnitParametersMap ¶ms)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
MANTID_API_DLL void applyRectangularDetectorScaleToComponentInfo(Geometry::ComponentInfo &componentInfo, Geometry::IComponent *componentId, const double scaleX, const double scaleY)
Helpers for resizing RectangularDetectors.
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
Generate a tableworkspace to store the calibration results.
adjust instrument component position and orientation
: detector size scale at y-direction