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