Mantid
Loading...
Searching...
No Matches
RefinePowderInstrumentParameters.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#pragma once
8
22#include "MantidHistogramData/HistogramX.h"
23#include "MantidHistogramData/HistogramY.h"
24#include "MantidKernel/System.h"
25
26namespace Mantid {
27namespace CurveFitting {
28namespace Algorithms {
29
41class MANTID_CURVEFITTING_DLL RefinePowderInstrumentParameters final : public API::Algorithm,
43public:
45
47 const std::string name() const override { return "RefinePowderInstrumentParameters"; }
49 const std::string summary() const override { return "Parameters include Dtt1, Dtt1t, Dtt2t, Zero, Zerot. "; }
50
52 int version() const override { return 2; }
53
55 const std::string category() const override { return "Diffraction\\Fitting"; }
56
57private:
58 // Implement abstract Algorithm methods
59 void init() override;
60 // Implement abstract Algorithm methods
61 void exec() override;
62
63 //---------------- Processing Input ---------------------
65 void importParametersFromTable(const DataObjects::TableWorkspace_sptr &parameterWS,
66 std::map<std::string, double> &parameters);
67
69 void importMonteCarloParametersFromTable(const DataObjects::TableWorkspace_sptr &tablews,
70 const std::vector<std::string> &parameternames,
71 std::vector<double> &stepsizes, std::vector<double> &lowerbounds,
72 std::vector<double> &upperbounds);
73
75 void genPeakCentersWorkspace(bool montecarlo, size_t numbestfit);
76
78 void genPeaksFromTable(const DataObjects::TableWorkspace_sptr &peakparamws);
79
80 //--------------- Processing Output ------------------
82 DataObjects::TableWorkspace_sptr genOutputInstrumentParameterTable();
83
85 DataObjects::TableWorkspace_sptr genMCResultTable();
86
87 //--------------- Fit and MC methods -------------------
89 void fitInstrumentParameters();
90
92 double calculateFunctionStatistic(const API::IFunction_sptr &func, const API::MatrixWorkspace_sptr &dataws,
93 size_t workspaceindex);
94
96 bool fitFunction(const API::IFunction_sptr &func, double &gslchi2);
97
100
102 std::string parseFitResult(API::IAlgorithm_sptr fitalg, double &chi2);
103
105 void refineInstrumentParametersMC(const DataObjects::TableWorkspace_sptr &parameterWS, bool fit2 = false);
106
108 void doParameterSpaceRandomWalk(std::vector<std::string> parnames, std::vector<double> lowerbounds,
109 std::vector<double> upperbounds, std::vector<double> stepsizes, size_t maxsteps,
110 double stepsizescalefactor, bool fit2);
111
113 void getD2TOFFuncParamNames(std::vector<std::string> &parnames);
114
116 double calculateD2TOFFunction(const API::IFunction_sptr &func, const API::FunctionDomain1DVector &domain,
117 API::FunctionValues &values, const Mantid::HistogramData::HistogramY &rawY,
118 const Mantid::HistogramData::HistogramE &rawE);
119
121 // double calculateDspaceValue(std::vector<int> hkl, double lattice);
122
124 void calculateThermalNeutronSpecial(const API::IFunction_sptr &m_Function,
125 const Mantid::HistogramData::HistogramX &xVals, std::vector<double> &vec_n);
126
127 //--------------- Class Variables -------------------
130
133
135 std::map<std::vector<int>, double> m_PeakErrors;
136
138 std::map<std::string, double> m_FuncParameters;
140 std::map<std::string, double> m_OrigParameters;
141
143 std::vector<std::string> m_PeakFunctionParameterNames;
146 std::vector<std::pair<double, std::vector<double>>> m_BestMCParameters;
149 std::vector<std::pair<double, std::vector<double>>> m_BestFitParameters;
151 std::vector<std::pair<double, double>> m_BestFitChi2s;
154
157
160
163
166};
167
170inline double linearInterpolateX(double x0, double xf, double y0, double yf, double y) {
171 double x = ((xf - x0) * y - (xf * y0 - x0 * yf)) / (yf - y0);
172 return x;
173}
174
177inline double linearInterpolateY(double x0, double xf, double y0, double yf, double x) {
178 double y = ((xf * y0 - x0 * yf) + x * (yf - y0)) / (xf - x0);
179 return y;
180}
181
182} // namespace Algorithms
183} // namespace CurveFitting
184} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Class for marking algorithms as deprecated.
Implements FunctionDomain1D with its own storage in form of a std::vector.
A class to store values calculated by a function.
RefinePowderInstrumentParameters : Algorithm to refine instrument geometry parameters only.
std::map< std::string, double > m_OrigParameters
Map to store the original (input) parameters.
std::vector< std::string > m_PeakFunctionParameterNames
Peak function parameter names.
size_t m_MinNumFittedPeaks
Minimum number of fitted peaks for refinement.
Functions::ThermalNeutronDtoTOFFunction_sptr m_Function
Modelling function.
std::map< std::string, double > m_FuncParameters
Map for function (instrument parameter)
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
std::string parseFitResult(API::IAlgorithm_sptr fitalg, double &chi2)
Parse the fitting result.
std::vector< std::pair< double, std::vector< double > > > m_BestFitParameters
N sets of the peak parameter values for the best N chi2 for MC.
std::string parseFitParameterWorkspace(API::ITableWorkspace_sptr paramws)
Parse Fit() output parameter workspace.
std::map< std::vector< int >, double > m_PeakErrors
Map for all peaks' error (fitted vs. experimental): [HKL]: Chi^2.
std::map< std::vector< int >, Functions::BackToBackExponential_sptr > m_Peaks
Map for all peaks to fit individually.
DataObjects::Workspace2D_sptr m_dataWS
Output Workspace containing the dspacing ~ TOF peak positions.
std::vector< std::pair< double, std::vector< double > > > m_BestMCParameters
N sets of the peak parameter values for the best N chi2 for MC.
std::vector< std::pair< double, double > > m_BestFitChi2s
N sets of the homemade chi2 and gsl chi2.
int version() const override
Algorithm's version for identification overriding a virtual method.
const std::string summary() const override
Summary of algorithms purpose.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
double linearInterpolateX(double x0, double xf, double y0, double yf, double y)
Formular for linear iterpolation: X = [(xf-x0)*Y - (xf*y0-x0*yf)]/(yf-y0)
double linearInterpolateY(double x0, double xf, double y0, double yf, double x)
Formula for linear interpolation: Y = ( (xf*y0-x0*yf) + x*(yf-y0) )/(xf-x0)
std::shared_ptr< ThermalNeutronDtoTOFFunction > ThermalNeutronDtoTOFFunction_sptr
std::shared_ptr< BackToBackExponential > BackToBackExponential_sptr
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
Helper class which provides the Collimation Length for SANS instruments.