source: branches/casa-prerelease/pre-asap/src/Lorentzian1D.h@ 2305

Last change on this file since 2305 was 1819, checked in by Kana Sugimoto, 14 years ago

New Development: No

JIRA Issue: No (merge alma branch to trunk)

Ready for Test: Yes

Interface Changes: No

Test Programs: regressions may work

Module(s): all single dish modules

Description:

Merged all changes in alma (r1386:1818) and newfiller (r1774:1818) branch.


File size: 10.2 KB
Line 
1//# Lorentzian1D.h: A one-dimensional Lorentzian class
2//# Copyright (C) 1995,1996,1997,2001,2002,2005
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: Lorentzian1D.h 20229 2010-02-15 12:19:06Z Wataru.Kawasaki $
27
28#ifndef SCIMATH_LORENTZIAN1D_H
29#define SCIMATH_LORENTZIAN1D_H
30
31//# Includes
32#include <casa/aips.h>
33#include "Lorentzian1DParam.h"
34#include <scimath/Functionals/Function1D.h>
35#include <scimath/Mathematics/AutoDiff.h>
36#include <scimath/Mathematics/AutoDiffMath.h>
37
38namespace casa { //# NAMESPACE CASA - BEGIN
39
40//# Forward declarations
41
42// <summary> A one dimensional Lorentzian class.</summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="tcornwel" date="1996/02/22" tests="tLorentzian1D"
47// demos="">
48// </reviewed>
49
50// <prerequisite>
51// <li> <linkto class="Lorentzian1DParam">Lorentzian1DParam</linkto>
52// <li> <linkto class="Function">Function</linkto>
53// </prerequisite>
54
55// <etymology>
56// A Lorentzian1D functional is designed exclusively for calculating a
57// Lorentzian (or Normal) distribution in one dimension. Other classes exist
58// for calculating these functions in two
59// (<linkto class=Lorentzian2D>Lorentzian2D</linkto>) and N
60// (<linkto class=LorentzianND>LorentzianND</linkto>) dimensions.
61// </etymology>
62
63// <synopsis>
64// A <src>Lorentzian1D</src> is described by a height, center, and width. Its
65// fundamental operation is evaluating itself at some <src>x</src>.
66// The parameters (height, center and width) may be changed at run time.
67//
68// The width of the Lorentzian (for the constructors or the <src>setWidth
69// </src> function) is always specified in terms of the full width at half
70// maximum (FWHM). It is always positive and attempts to set a non-positive
71// width will throw an assertion when in debug mode.
72//
73// The peak height of the Lorentzian can be specified at construction time or
74// by using the <src> setHeight </src> function. Alternatively the <src>
75// setFlux </src> function can be used to implicitly set the peak height by
76// specifying the integrated area under the Lorentzian. The height (or flux)
77// can be positive, negative or zero, as this class makes no assumptions on
78// what quantity the height represents.
79//
80// <note role=tip> Changing the width of the Lorentzian will not affect
81// its peak height but will change its flux. So you should always set the
82// width before setting the flux. </note>
83//
84// The parameter interface (see
85// <linkto class="Lorentzian1DParam">Lorentzian1DParam</linkto> class),
86// is used to provide an interface to the
87// <linkto module="Fitting">Fitting</linkto> classes.
88//
89// There are 3 parameters that are used to describe the Lorentzian:
90// <ol>
91// <li> The height of the Lorentzian. This is identical to the value
92// returned using the <src>height()</src> member function.
93// <li> The center of the Lorentzian in the x direction. This is identical to
94// the value returned using the <src>center()</src> member function.
95// <li> The width (FWHM) of the Lorentzian. To aid convergence of
96// the non-linear fitting routines this parameter is allowed to be
97// negative. This does not affect the shape of the Lorentzian as the
98// square of the width is used when evaluating the function.
99// </ol>
100//
101// An enumeration for the <src>HEIGHT</src>, <src>WIDTH</src> and
102// <src>CENTER</src> parameter index is provided, enabling the setting
103// and reading of parameters with the <src>[]</src> operator. The
104// <src>mask()</src> methods can be used to check and set the parameter masks.
105//
106// </synopsis>
107
108// <example>
109// <srcblock>
110// Lorentzian<Double> gf(5.0, 25.0, 7);
111// gf(25); // = 5.0
112// gf[HEIGHT](1.0);
113// gf.setWidth(2.0);
114// gf[CENTER](0.0);
115// gf(1); // = 0.5*height = 0.5
116// </srcblock>
117// </example>
118
119// <templating arg=T>
120// <li> T should have standard numerical operators and exp() function. Current
121// implementation only tested for real types.
122// <li> To obtain derivatives, the derivatives should be defined.
123// </templating>
124
125// <thrown>
126// <li> Assertion in debug mode if attempt is made to set a negative width
127// <li> AipsError if incorrect parameter number specified.
128// <li> Assertion in debug mode if operator(Vector<>) with empty Vector
129// </thrown>
130
131// <todo asof="2001/08/19">
132// <li> Lorentzians that know about their DFT's could be required eventually.
133// </todo>
134
135template<class T> class Lorentzian1D : public Lorentzian1DParam<T> {
136public:
137 //# Enumerations
138
139 //# Constructors
140 // Constructs the one dimensional Lorentzians. Defaults:
141 // height=1, center=0, width(FWHM)=1.
142 // <note role=warning> Could not use default arguments
143 // that worked both with gcc and IRIX </note>
144 // <group>
145 Lorentzian1D() : Lorentzian1DParam<T>() {};
146 explicit Lorentzian1D(const T &height) : Lorentzian1DParam<T>(height) {};
147 Lorentzian1D(const T &height, const T &center) :
148 Lorentzian1DParam<T>(height, center) {};
149 Lorentzian1D(const T &height, const T &center, const T &width) :
150 Lorentzian1DParam<T>(height, center, width) {};
151 // </group>
152
153 // Copy constructor (deep copy)
154 // <group>
155 Lorentzian1D(const Lorentzian1D<T> &other) : Lorentzian1DParam<T>(other) {};
156 template <class W>
157 Lorentzian1D(const Lorentzian1D<W> &other) : Lorentzian1DParam<T>(other) {};
158 // </group>
159
160 // Copy assignment (deep copy)
161 Lorentzian1D<T> &operator=(const Lorentzian1D<T> &other) {
162 Lorentzian1DParam<T>::operator=(other); return *this; };
163
164 // Destructor
165 virtual ~Lorentzian1D() {};
166
167 //# Operators
168 // Evaluate the Lorentzian at <src>x</src>.
169 // <group>
170 virtual T eval(typename Function1D<T>::FunctionArg x) const;
171 // </group>
172
173 //# Member functions
174 // Return a copy of this object from the heap. The caller is responsible
175 // for deleting this pointer.
176 // <group>
177 virtual Function<T> *clone() const { return new Lorentzian1D<T>(*this); };
178 virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
179 return new Lorentzian1D<typename FunctionTraits<T>::DiffType>(*this); };
180 virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
181 return new Lorentzian1D<typename FunctionTraits<T>::BaseType>(*this); };
182 // </group>
183
184 //# Make members of parent classes known.
185protected:
186 using Lorentzian1DParam<T>::param_p;
187public:
188 using Lorentzian1DParam<T>::HEIGHT;
189 using Lorentzian1DParam<T>::CENTER;
190 using Lorentzian1DParam<T>::WIDTH;
191 using Lorentzian1DParam<T>::fwhm2int;
192};
193
194
195#define Lorentzian1D_PS Lorentzian1D
196
197// <summary> Partial specialization of Lorentzian1D for <src>AutoDiff</src>
198// </summary>
199
200// <synopsis>
201// <note role=warning> The name <src>Lorentzian1D_PS</src> is only for cxx2html
202// documentation problems. Use <src>Lorentzian1D</src> in your code.</note>
203// </synopsis>
204
205template <class T> class Lorentzian1D_PS<AutoDiff<T> > :
206public Lorentzian1DParam<AutoDiff<T> >
207{
208public:
209 //# Constructors
210 // Constructs one dimensional Lorentzians.
211 // <group>
212 Lorentzian1D_PS() : Lorentzian1DParam<AutoDiff<T> >() {};
213 explicit Lorentzian1D_PS(const AutoDiff<T> &height) :
214 Lorentzian1DParam<AutoDiff<T> >(height) {};
215 Lorentzian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center) :
216 Lorentzian1DParam<AutoDiff<T> >(height, center) {};
217 Lorentzian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center,
218 const AutoDiff<T> &width) :
219 Lorentzian1DParam<AutoDiff<T> >(height, center, width) {};
220 // </group>
221
222 // Copy constructor (deep copy)
223 // <group>
224 Lorentzian1D_PS(const Lorentzian1D_PS &other) :
225 Lorentzian1DParam<AutoDiff<T> >(other) {};
226 template <class W>
227 Lorentzian1D_PS(const Lorentzian1D_PS<W> &other) :
228 Lorentzian1DParam<AutoDiff<T> >(other) {};
229 // </group>
230
231 // Copy assignment (deep copy)
232 Lorentzian1D_PS<AutoDiff<T> > &
233 operator=(const Lorentzian1D_PS<AutoDiff<T> > &other) {
234 Lorentzian1DParam<AutoDiff<T> >::operator=(other); return *this; };
235
236 // Destructor
237 virtual ~Lorentzian1D_PS() {};
238
239 //# Operators
240 // Evaluate the Lorentzian and its derivatives at <src>x</src>.
241 // <group>
242 virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
243 // </group>
244
245 //# Member functions
246 // Return a copy of this object from the heap. The caller is responsible
247 // for deleting this pointer.
248 // <group>
249 virtual Function<AutoDiff<T> > *clone() const {
250 return new Lorentzian1D<AutoDiff<T> >(*this); };
251 virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType>
252 *cloneAD() const {
253 return new Lorentzian1D<typename FunctionTraits<AutoDiff<T> >::DiffType>
254 (*this); };
255 virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType>
256 *cloneNonAD() const {
257 return new Lorentzian1D<typename FunctionTraits<AutoDiff<T> >::BaseType>
258 (*this); };
259 // </group>
260
261 //# Make members of parent classes known.
262protected:
263 using Lorentzian1DParam<AutoDiff<T> >::param_p;
264public:
265 using Lorentzian1DParam<AutoDiff<T> >::HEIGHT;
266 using Lorentzian1DParam<AutoDiff<T> >::CENTER;
267 using Lorentzian1DParam<AutoDiff<T> >::WIDTH;
268 using Lorentzian1DParam<AutoDiff<T> >::fwhm2int;
269};
270
271#undef Lorentzian1D_PS
272
273
274} //# NAMESPACE CASA - END
275
276#ifndef CASACORE_NO_AUTO_TEMPLATES
277#include "Lorentzian1D.tcc"
278#include "Lorentzian1D2.tcc"
279#endif //# CASACORE_NO_AUTO_TEMPLATES
280#endif
Note: See TracBrowser for help on using the repository browser.