-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndirectDataAnalysisAddingFitType.html
205 lines (161 loc) · 12.4 KB
/
IndirectDataAnalysisAddingFitType.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Adding a new fitting function to IDA</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="_static/bootstrap-sphinx.css?v=fadd4351" />
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=77160d70" />
<script src="_static/documentation_options.js?v=a8da1a53"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="IndirectDataAnalysis File Structure" href="IndirectDataAnalysisFileStructure.html" />
<link rel="prev" title="Index Property" href="IndexProperty.html" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59110517-1', 'auto');
ga('send', 'pageview');
</script>
</head><body>
<div id="navbar" class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.mantidproject.org">
</a>
<span class="navbar-text navbar-version pull-left"><b>main</b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li class="divider-vertical"></li>
<li><a href="index.html">Home</a></li>
<li><a href="https://download.mantidproject.org">Download</a></li>
<li><a href="https://docs.mantidproject.org">User Documentation</a></li>
<li><a href="http://www.mantidproject.org/contact">Contact Us</a></li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<p>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="nav-item nav-item-0"><a href="index.html">Documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">Adding a new fitting function to IDA</a></li>
</ul>
</div> </p>
</div>
<div class="container">
<div class="row">
<div class="body col-md-12 content" role="main">
<section id="adding-a-new-fitting-function-to-ida">
<span id="ida-addingfittype-ref"></span><h1>Adding a new fitting function to IDA<a class="headerlink" href="#adding-a-new-fitting-function-to-ida" title="Link to this heading">¶</a></h1>
<p>The tabs in Indirect Data Analysis use each fit spectra to a predefined list of functions, adding new functions to the
list of available ones can seem daunting at first but it can be done by following some steps.</p>
<section id="function-q">
<h2>Function(Q)<a class="headerlink" href="#function-q" title="Link to this heading">¶</a></h2>
<p>In the <cite>FitTabConstants.h</cite> file, there are sets of maps of {“Fit function class name”, “Fit function class initialization string”}, e.g.
<cite>{std::string(“TeixeiraWater”), std::string(“name=TeixeiraWater, Tau=1, L=1.5, constraints=(Tau>0, L>0)”)}</cite>. To add
a new fit function to Function(Q) you simply need to add it to this list of available functions. Currently, we divide up the
functions into Width, EISF, and All with the intent that the list of functions would change depending on what data is
loaded into the tab, however as it is not yet implemented for the workspace input it uses the list for All.</p>
</section>
<section id="msd">
<h2>MSD<a class="headerlink" href="#msd" title="Link to this heading">¶</a></h2>
<p>The fit function strings for MSD are also stored in the <cite>FitTabConstants.h</cite> file.</p>
</section>
<section id="iqtfit">
<h2>IqtFit<a class="headerlink" href="#iqtfit" title="Link to this heading">¶</a></h2>
<p>The fitting functions in IqtFit are hard coded into the template browser. These should be moved into the <cite>FitTabConstants.h</cite> file to
allow us to add more functions easily in the future.</p>
</section>
<section id="convolution">
<h2>Convolution<a class="headerlink" href="#convolution" title="Link to this heading">¶</a></h2>
<p>Convolution has the most involved process of adding a function to it’s library and it needs to be added in its entirety.</p>
<p>Firstly, in <cite>ConvTypes.h</cite> add the function name to the enumerated list FitType e.g. <cite>TeixeiraWater</cite>, and in the paramID
enum add an entry for each parameter in the function along with a unique prefix denoting which function they are for.
e.g. <cite>TW_HEIGHT, TW_DIFFCOEFF, TW_TAU, TW_CENTRE</cite>. Make sure to preserve the ordering of the current enum and
add the parameters of the function along with each other.</p>
<p>Secondly, in ConvTypes.cpp add QDependency for the function as either true or false in the <cite>FitTypeQDepends</cite> map based on if
the function is Q dependant.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="n">FitType</span><span class="o">::</span><span class="n">TeixeiraWater</span><span class="p">,</span><span class="w"> </span><span class="nb">true</span><span class="p">},</span>
</pre></div>
</div>
<p>Then, in the FitTypeEnumToString and FitTypeStringToEnum add the mapping of FitType from the enum type onto the function name</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="n">FitType</span><span class="o">::</span><span class="n">TeixeiraWater</span><span class="p">,</span><span class="w"> </span><span class="s">"TeixeiraWaterSQE"</span><span class="p">}</span>
<span class="p">{</span><span class="s">"TeixeiraWaterSQE"</span><span class="p">,</span><span class="w"> </span><span class="n">FitType</span><span class="o">::</span><span class="n">TeixeiraWater</span><span class="p">}</span>
</pre></div>
</div>
<p>After that, in the g_paramName add ParamID from the header and parameter names for each parameter in the function. The order of these
is important so add them in the same order as they appear in the header. Make sure the function is in the right range. If it is Lorentzian
add it between the range from LOR1_AMPLITUDE to LOR2_FWHM_2 and if it is a fit function add it between the range from TW_HEIGHT to IIRD_CENTRE and
if it is a background function add it between the range from FLAT_BG_A0 to LINEAR_BG_A1. Note that, background functions have <em>_BG_</em> format.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="n">ParamID</span><span class="o">::</span><span class="n">TW_HEIGHT</span><span class="p">,</span><span class="w"> </span><span class="s">"Height"</span><span class="p">},</span>
<span class="p">{</span><span class="n">ParamID</span><span class="o">::</span><span class="n">TW_DIFFCOEFF</span><span class="p">,</span><span class="w"> </span><span class="s">"DiffCoeff"</span><span class="p">},</span>
<span class="p">{</span><span class="n">ParamID</span><span class="o">::</span><span class="n">TW_TAU</span><span class="p">,</span><span class="w"> </span><span class="s">"Tau"</span><span class="p">},</span>
<span class="p">{</span><span class="n">ParamID</span><span class="o">::</span><span class="n">TW_CENTRE</span><span class="p">,</span><span class="w"> </span><span class="s">"Centre"</span><span class="p">},</span>
</pre></div>
</div>
<p>Moreover, to tie it all together add param ranges to g_typeMap in the form
<cite>{FitType, {“Function name displayed in tab”, “Function class name”, {ParamID::first, ParamID::last}}}</cite> this allows the template
to construct a function out of the related parameters. There are several places where this can be added, those being FitType,
LorentzianType, and BackgroundType. Convolution can run fits with one of each Fit, Lorentzian, and Background but only one of each.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="n">FitType</span><span class="o">::</span><span class="n">TeixeiraWater</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="s">"Teixeira Water SQE"</span><span class="p">,</span><span class="w"> </span><span class="s">"TeixeiraWaterSQE"</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="n">ParamID</span><span class="o">::</span><span class="n">TW_HEIGHT</span><span class="p">,</span><span class="w"> </span><span class="n">ParamID</span><span class="o">::</span><span class="n">TW_CENTRE</span><span class="p">}}},</span>
</pre></div>
</div>
<p>Finally, in <cite>FitTabConstants.h</cite> add the fit function name and shortened key to the <cite>FUNCTION_STRINGS</cite> variable. This key will be used in the output
workspace from the fit.</p>
<p>In ConvFunctionModel add the build function string function</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="nf">ConvFunctionModel::buildTeixeiraFunctionString</span><span class="p">()</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="s">"name=TeixeiraWaterSQE, Height=1, DiffCoeff=2.3, Tau=1.25, Centre=0, "</span>
<span class="w"> </span><span class="s">"constraints=(Height>0, DiffCoeff>0, Tau>0)"</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>and then add else if case to buildPeaksFunctionString, buildLorentzianPeaksString or buildFitTypeString.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">m_fitType</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">FitType</span><span class="o">::</span><span class="n">TeixeiraWater</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">functions</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">buildTeixeiraFunctionString</span><span class="p">());</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
</section>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<ul class="nav navbar-nav" style=" float: right;">
<li>
<a href="IndexProperty.html" title="Previous Chapter: Index Property"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm hidden-tablet">« Index Property</span>
</a>
</li>
<li>
<a href="IndirectDataAnalysisFileStructure.html" title="Next Chapter: IndirectDataAnalysis File Structure"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm hidden-tablet">IndirectDataA... »</span>
</a>
</li>
<li><a href="#">Back to top</a></li>
</ul>
<p>
</p>
</div>
</footer>
</body>
</html>