Mantid
Loading...
Searching...
No Matches
RefinePowderInstrumentParameters3.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
10
13
16#include "MantidCurveFitting/DllConfig.h"
18
19#include <span>
20
21namespace Mantid {
22namespace CurveFitting {
23namespace Algorithms {
24
27class MANTID_CURVEFITTING_DLL RefinePowderInstrumentParameters3 final : public API::Algorithm {
28public:
30
32 const std::string name() const override { return "RefinePowderInstrumentParameters"; }
34 const std::string summary() const override { return "Parameters include Dtt1, Dtt1t, Dtt2t, Zero, Zerot. "; }
35
37 int version() const override { return 3; }
38 const std::vector<std::string> seeAlso() const override { return {"RefinePowderDiffProfileSeq"}; }
39
41 const std::string category() const override { return "Diffraction\\Fitting"; }
42
43private:
45 void init() override;
46
48 void exec() override;
49
51 double execFitParametersNonMC();
52
54 double execFitParametersMC();
55
57 double doSimulatedAnnealing(std::map<std::string, Parameter> inparammap);
58
60 void setupRandomWalkStrategy(std::map<std::string, Parameter> &parammap,
61 std::vector<std::vector<std::string>> &mcgroups);
62
64 void addParameterToMCMinimize(std::vector<std::string> &parnamesforMC, const std::string &parname,
65 std::map<std::string, Parameter> parammap);
66
68 void proposeNewValues(const std::vector<std::string> &mcgroup, std::map<std::string, Parameter> &curparammap,
69 std::map<std::string, Parameter> &newparammap, double currchisq);
70
72 bool acceptOrDenyChange(double curchisq, double newchisq, double temperature);
73
75 void bookKeepMCResult(std::map<std::string, Parameter> parammap, double chisq, int istep, int igroup,
76 std::map<std::string, Parameter> &bestparammap);
77 // vector<pair<double, map<string, Parameter> > > &bestresults, size_t
78 // maxnumresults);
79
81 double calculateFunction(const std::map<std::string, Parameter> &parammap, std::vector<double> &vecY);
82
84 double calculateFunctionError(const API::IFunction_sptr &function, const DataObjects::Workspace2D_sptr &dataws,
85 int wsindex);
86
88 double fitFunction(const API::IFunction_sptr &function, const DataObjects::Workspace2D_sptr &dataws, int wsindex,
89 bool powerfit);
90
92 bool doFitFunction(const API::IFunction_sptr &function, const DataObjects::Workspace2D_sptr &dataws, int wsindex,
93 const std::string &minimizer, int numiters, double &chi2, std::string &fitstatus);
94
96 void processInputProperties();
97
99 void parseTableWorkspaces();
100
102 void parseTableWorkspace(const DataObjects::TableWorkspace_sptr &tablews, std::map<std::string, Parameter> &parammap);
103
105 void setFunctionParameterValues(const API::IFunction_sptr &function, std::map<std::string, Parameter> params);
106
108 void updateFunctionParameterValues(API::IFunction_sptr function, std::map<std::string, Parameter> &params);
109
112 void setFunctionParameterFitSetups(const API::IFunction_sptr &function, std::map<std::string, Parameter> params);
113
115 DataObjects::Workspace2D_sptr genOutputWorkspace(const API::FunctionDomain1DVector &domain,
116 const API::FunctionValues &rawvalues);
117
119 DataObjects::TableWorkspace_sptr genOutputProfileTable(std::map<std::string, Parameter> parameters, double startchi2,
120 double finalchi2);
121
124 void addOrReplace(std::map<std::string, Parameter> &parameters, const std::string &parname, double parvalue);
125
126 //-------- Variables ------------------------------------------------------
129
132
135
137 enum { FIT, MONTECARLO } m_fitMode;
138
140 enum { CONSTANT, USEINPUT } m_stdMode;
141
144
147
149 std::map<std::string, Parameter> m_profileParameters;
150
153
156
161};
162
163//================================= External Functions
164//=========================================
166void convertToDict(std::vector<std::string> strvec, std::map<std::string, size_t> &lookupdict);
167
169int getStringIndex(std::map<std::string, size_t> lookupdict, const std::string &key);
170
173 std::map<std::string, std::pair<double, double>> &parvaluemap);
174
176void restoreFunctionParameterValue(std::map<std::string, std::pair<double, double>> parvaluemap,
177 const API::IFunction_sptr &function, std::map<std::string, Parameter> &parammap);
178
180void duplicateParameters(const std::map<std::string, Parameter> &source, std::map<std::string, Parameter> &target);
181
183void copyParametersValues(const std::map<std::string, Parameter> &source, std::map<std::string, Parameter> &target);
184
186double calculateFunctionChiSquare(std::span<double const> modelY, std::span<double const> dataY,
187 std::span<double const> dataE);
188
189} // namespace Algorithms
190} // namespace CurveFitting
191} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
Implements FunctionDomain1D with its own storage in form of a std::vector.
A class to store values calculated by a function.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
Functions::ThermalNeutronDtoTOFFunction_sptr m_positionFunc
My function for peak positions.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
DataObjects::Workspace2D_sptr m_dataWS
Data workspace containg peak positions.
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
const std::string summary() const override
Summary of algorithms purpose.
DataObjects::TableWorkspace_sptr m_paramTable
TableWorkspace containing peak parameters value and fit information.
std::map< std::string, Parameter > m_profileParameters
Data structure (map of Parameters) to hold parameters.
void updateFunctionParameterValues(API::IFunction_sptr function, std::map< std::string, Parameter > &params)
Update parameter values to Parameter map from fuction map.
int version() const override
Algorithm's version for identification overriding a virtual method.
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition IFunction.h:748
void duplicateParameters(const std::map< std::string, Parameter > &source, std::map< std::string, Parameter > &target)
Copy parameters from source to target.
void convertToDict(std::vector< std::string > strvec, std::map< std::string, size_t > &lookupdict)
Convert a vector to a lookup map (dictionary)
int getStringIndex(std::map< std::string, size_t > lookupdict, const std::string &key)
Get the index from lookup dictionary (map)
void restoreFunctionParameterValue(std::map< std::string, std::pair< double, double > > parvaluemap, const API::IFunction_sptr &function, std::map< std::string, Parameter > &parammap)
Restore function parameter values to a map.
void storeFunctionParameterValue(const API::IFunction_sptr &function, std::map< std::string, std::pair< double, double > > &parvaluemap)
Store function parameter values to a map.
double calculateFunctionChiSquare(std::span< double const > modelY, std::span< double const > dataY, std::span< double const > dataE)
Calculate Chi^2.
void copyParametersValues(const std::map< std::string, Parameter > &source, std::map< std::string, Parameter > &target)
Copy parameters values from source to target.
std::shared_ptr< ThermalNeutronDtoTOFFunction > ThermalNeutronDtoTOFFunction_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.