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