Mantid
Loading...
Searching...
No Matches
PeakHKLErrors.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7/*
8 * PeakHKLErrors.h
9 *
10 * Created on: Jan 26, 2013
11 * Author: ruth
12 */
13
14#pragma once
15#include "MantidKernel/System.h"
16
17#include "MantidAPI/IFunction.h"
20#include "MantidCrystal/DllConfig.h"
24#include "MantidKernel/Matrix.h"
25
26namespace Mantid {
27namespace Crystal {
28
34class MANTID_CRYSTAL_DLL PeakHKLErrors : public API::ParamFunction, public API::IFunction1D {
35public:
37
38 std::string name() const override { return std::string("PeakHKLErrors"); };
39
40 virtual int version() const { return 1; };
41
42 const std::string category() const override { return "Calibration"; };
43
44 void function1D(double *out, const double *xValues, const size_t nData) const override;
45
46 void functionDeriv1D(Mantid::API::Jacobian *out, const double *xValues, const size_t nData) override;
47
48 void init() override;
49
67 static DataObjects::Peak createNewPeak(const DataObjects::Peak &peak_old, const Geometry::Instrument_sptr &instrNew,
68 double T0, double L0);
69
70 static void cLone(std::shared_ptr<Geometry::ParameterMap> &pmap,
71 const std::shared_ptr<const Geometry::IComponent> &component,
72 std::shared_ptr<const Geometry::ParameterMap> &pmapSv);
73
74 void getRun2MatMap(DataObjects::PeaksWorkspace_sptr &Peaks, const std::string &OptRuns,
75 std::map<int, Mantid::Kernel::Matrix<double>> &Res) const;
76 size_t nAttributes() const override { return (size_t)2; }
77
78 static Kernel::Matrix<double> DerivRotationMatrixAboutRegAxis(double theta, char axis);
79
80 static Kernel::Matrix<double> RotationMatrixAboutRegAxis(double theta, char axis);
81
82 std::shared_ptr<Geometry::Instrument> getNewInstrument(const DataObjects::PeaksWorkspace_sptr &peaksWs) const;
83
84 std::vector<std::string> getAttributeNames() const override { return {"OptRuns", "PeakWorkspaceName"}; }
85
86 IFunction::Attribute getAttribute(const std::string &attName) const override {
87 if (attName == "OptRuns")
88 return IFunction::Attribute(OptRuns);
89
90 if (attName == "PeakWorkspaceName")
91 return IFunction::Attribute(PeakWorkspaceName);
92
93 throw std::invalid_argument("Not a valid attribute name");
94 }
95
96 void setAttribute(const std::string &attName, const IFunction::Attribute &value) override {
97 if (attName == "OptRuns") {
98 OptRuns = value.asString();
99
100 if (OptRuns.empty())
101 return;
102
103 if (OptRuns.at(0) != '/')
104 OptRuns = "/" + OptRuns;
105
106 if (OptRuns.at(OptRuns.size() - 1) != '/')
107 OptRuns += "/";
108
109 if (initMode == 1) {
110 setUpOptRuns();
111 initMode = 2;
112 } else if (initMode == 2) // Woops cannot do twice
113 throw std::invalid_argument("OptRuns can only be set once");
114
115 return;
116 }
117
118 if (attName == "PeakWorkspaceName") {
119 PeakWorkspaceName = value.asString();
120 return;
121 }
122
123 throw std::invalid_argument("Not a valid attribute name");
124 }
125
126 bool hasAttribute(const std::string &attName) const override {
127 if (attName == "OptRuns")
128 return true;
129
130 if (attName == "PeakWorkspaceName")
131 return true;
132
133 return false;
134 }
135
136private:
137 std::string OptRuns;
138
139 std::string PeakWorkspaceName;
140
141 int initMode; // 0 not invoked, 1 invoked but no OptRuns , 2 invoked and
142 // OptRuns setup
143
144 void setUpOptRuns();
145
146 mutable std::shared_ptr<Geometry::Instrument> instChange;
147 mutable bool hasParameterMap = false;
149 mutable std::shared_ptr<const Geometry::ParameterMap> pmapSv;
150};
151} // namespace Crystal
152} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
This is a specialization of IFunction for functions of one real argument.
Definition: IFunction1D.h:43
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
Implements the part of IFunction interface dealing with parameters.
Definition: ParamFunction.h:33
size_t nAttributes() const override
Returns the number of attributes associated with the function.
Definition: PeakHKLErrors.h:76
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
Definition: PeakHKLErrors.h:84
std::shared_ptr< Geometry::Instrument > instChange
std::string name() const override
Returns the function's name.
Definition: PeakHKLErrors.h:38
IFunction::Attribute getAttribute(const std::string &attName) const override
Return a value of attribute attName.
Definition: PeakHKLErrors.h:86
virtual int version() const
Definition: PeakHKLErrors.h:40
bool hasAttribute(const std::string &attName) const override
Check if attribute attName exists.
const std::string category() const override
The categories the Fit function belong to.
Definition: PeakHKLErrors.h:42
void setAttribute(const std::string &attName, const IFunction::Attribute &value) override
Set a value to attribute attName.
Definition: PeakHKLErrors.h:96
std::shared_ptr< const Geometry::ParameterMap > pmapSv
Structure describing a single-crystal peak.
Definition: Peak.h:34
Numerical Matrix class.
Definition: Matrix.h:42
Class for 3D vectors.
Definition: V3D.h:34
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
Helper class which provides the Collimation Length for SANS instruments.
Generate a tableworkspace to store the calibration results.