source: branches/newfiller/src/Lorentzian1D2.tcc@ 2412

Last change on this file since 2412 was 1706, checked in by WataruKawasaki, 15 years ago

New Development: No

JIRA Issue: Yes (CAS-1800)

Ready to Release: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sdfit

Description: bug fix for Lorentzian profile class


File size: 2.8 KB
Line 
1//# Lorentzian1D2.cc: One dimensional Lorentzian class specialized for AutoDiff
2//# Copyright (C) 2001,2002
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: aips2-request@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25//#
26//# $Id: Lorentzian1D2.tcc 20253 2008-02-23 15:15:00Z gervandiepen $
27
28//# Includes
29#include "Lorentzian1D.h"
30#include <casa/BasicMath/Math.h>
31
32namespace casa { //# NAMESPACE CASA - BEGIN
33
34//# Constructors
35
36//# Operators
37template<class T>
38AutoDiff<T> Lorentzian1D<AutoDiff<T> >::
39eval(typename Function<AutoDiff<T> >::FunctionArg x) const {
40 AutoDiff<T> tmp;
41 if (this->param_p[this->HEIGHT].nDerivatives() > 0) tmp = this->param_p[this->HEIGHT];
42 else if (this->param_p[this->CENTER].nDerivatives() > 0) tmp = this->param_p[this->CENTER];
43 else if (this->param_p[this->WIDTH].nDerivatives() > 0) tmp = this->param_p[this->WIDTH];
44 T x_norm = (x[0] - this->param_p[this->CENTER].value())/
45 this->param_p[this->WIDTH].value()/this->fwhm2int.value();
46 T exponential = T(1.0)/(T(1.0) + x_norm*x_norm);
47 // function value
48 tmp.value() = this->param_p[this->HEIGHT].value() * exponential;
49 // get derivatives (assuming either all or none)
50 if (tmp.nDerivatives()>0) {
51 for (uInt j=0; j<tmp.nDerivatives(); j++) tmp.deriv(j) = 0.0;
52 // derivative wrt height
53 T dev = exponential;
54 if (this->param_p.mask(this->HEIGHT)) tmp.deriv(this->HEIGHT) = dev;
55 // derivative wrt center
56 T dev2 = this->param_p[this->HEIGHT].value()*dev*dev*T(2.0)*x_norm/
57 this->param_p[this->WIDTH].value();
58 if (this->param_p.mask(this->CENTER)) tmp.deriv(this->CENTER) = dev2/this->fwhm2int.value();
59 // derivative wrt width
60 if (this->param_p.mask(this->WIDTH)) tmp.deriv(this->WIDTH) = dev2*x_norm;
61 }
62 return tmp;
63}
64
65//# Member functions
66
67} //# NAMESPACE CASA - END
68
Note: See TracBrowser for help on using the repository browser.