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
11#include "MantidAPI/Algorithm.h"
12
15
19
20namespace Mantid {
21namespace CurveFitting {
22namespace Algorithms {
23
26class MANTID_CURVEFITTING_DLL RefinePowderInstrumentParameters3 final : public API::Algorithm {
27public:
29
31 const std::string name() const override { return "RefinePowderInstrumentParameters"; }
33 const std::string summary() const override { return "Parameters include Dtt1, Dtt1t, Dtt2t, Zero, Zerot. "; }
34
36 int version() const override { return 3; }
37 const std::vector<std::string> seeAlso() const override { return {"RefinePowderDiffProfileSeq"}; }
38
40 const std::string category() const override { return "Diffraction\\Fitting"; }
41
42private:
44 void init() override;
45
47 void exec() override;
48
50 double execFitParametersNonMC();
51
53 double execFitParametersMC();
54
56 double doSimulatedAnnealing(std::map<std::string, Parameter> inparammap);
57
59 void setupRandomWalkStrategy(std::map<std::string, Parameter> &parammap,
60 std::vector<std::vector<std::string>> &mcgroups);
61
63 void addParameterToMCMinimize(std::vector<std::string> &parnamesforMC, const std::string &parname,
64 std::map<std::string, Parameter> parammap);
65
67 void proposeNewValues(const std::vector<std::string> &mcgroup, std::map<std::string, Parameter> &curparammap,
68 std::map<std::string, Parameter> &newparammap, double currchisq);
69
71 bool acceptOrDenyChange(double curchisq, double newchisq, double temperature);
72
74 void bookKeepMCResult(std::map<std::string, Parameter> parammap, double chisq, int istep, int igroup,
75 std::map<std::string, Parameter> &bestparammap);
76 // vector<pair<double, map<string, Parameter> > > &bestresults, size_t
77 // maxnumresults);
78
80 double calculateFunction(const std::map<std::string, Parameter> &parammap, std::vector<double> &vecY);
81
83 double calculateFunctionError(const API::IFunction_sptr &function, const DataObjects::Workspace2D_sptr &dataws,
84 int wsindex);
85
87 double fitFunction(const API::IFunction_sptr &function, const DataObjects::Workspace2D_sptr &dataws, int wsindex,
88 bool powerfit);
89
91 bool doFitFunction(const API::IFunction_sptr &function, const DataObjects::Workspace2D_sptr &dataws, int wsindex,
92 const std::string &minimizer, int numiters, double &chi2, std::string &fitstatus);
93
95 void processInputProperties();
96
98 void parseTableWorkspaces();
99
101 void parseTableWorkspace(const DataObjects::TableWorkspace_sptr &tablews, std::map<std::string, Parameter> &parammap);
102
104 void setFunctionParameterValues(const API::IFunction_sptr &function, std::map<std::string, Parameter> params);
105
107 void updateFunctionParameterValues(API::IFunction_sptr function, std::map<std::string, Parameter> &params);
108
111 void setFunctionParameterFitSetups(const API::IFunction_sptr &function, std::map<std::string, Parameter> params);
112
114 DataObjects::Workspace2D_sptr genOutputWorkspace(const API::FunctionDomain1DVector &domain,
115 const API::FunctionValues &rawvalues);
116
118 DataObjects::TableWorkspace_sptr genOutputProfileTable(std::map<std::string, Parameter> parameters, double startchi2,
119 double finalchi2);
120
123 void addOrReplace(std::map<std::string, Parameter> &parameters, const std::string &parname, double parvalue);
124
125 //-------- Variables ------------------------------------------------------
128
131
134
136 enum { FIT, MONTECARLO } m_fitMode;
137
139 enum { CONSTANT, USEINPUT } m_stdMode;
140
143
146
148 std::map<std::string, Parameter> m_profileParameters;
149
152
155
160};
161
162//================================= External Functions
163//=========================================
165void convertToDict(std::vector<std::string> strvec, std::map<std::string, size_t> &lookupdict);
166
168int getStringIndex(std::map<std::string, size_t> lookupdict, const std::string &key);
169
172 std::map<std::string, std::pair<double, double>> &parvaluemap);
173
175void restoreFunctionParameterValue(std::map<std::string, std::pair<double, double>> parvaluemap,
176 const API::IFunction_sptr &function, std::map<std::string, Parameter> &parammap);
177
179void duplicateParameters(std::map<std::string, Parameter> source, std::map<std::string, Parameter> &target);
180
182void copyParametersValues(std::map<std::string, Parameter> source, std::map<std::string, Parameter> &target);
183
185double calculateFunctionChiSquare(const std::vector<double> &modelY, const std::vector<double> &dataY,
186 const std::vector<double> &dataE);
187
188} // namespace Algorithms
189} // namespace CurveFitting
190} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
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:732
double calculateFunctionChiSquare(const std::vector< double > &modelY, const std::vector< double > &dataY, const std::vector< double > &dataE)
Calculate Chi^2.
void duplicateParameters(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 copyParametersValues(std::map< std::string, Parameter > source, std::map< std::string, Parameter > &target)
Copy parameters values from source to target.
void storeFunctionParameterValue(const API::IFunction_sptr &function, std::map< std::string, std::pair< double, double > > &parvaluemap)
Store function parameter values to a map.
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.