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>
136 public:
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>
146 explicit Lorentzian1D(const T &height) : Lorentzian1DParam<T>(height) {};
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)
162 return *this;
163 };
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); };
185 // </group>
186
187 // # Make members of parent classes known.
188 protected:
190
191 public:
196};
197
198#define Lorentzian1D_PS Lorentzian1D
199
200// <summary> Partial specialization of Lorentzian1D for <src>AutoDiff</src>
201// </summary>
202
203// <synopsis>
204// <note role=warning> The name <src>Lorentzian1D_PS</src> is only for cxx2html
205// documentation problems. Use <src>Lorentzian1D</src> in your code.</note>
206// </synopsis>
207
208template <class T>
209class Lorentzian1D_PS<AutoDiff<T>> : public Lorentzian1DParam<AutoDiff<T>> {
210 public:
211 // # Constructors
212 // Constructs one dimensional Lorentzians.
213 // <group>
216 Lorentzian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center)
218 Lorentzian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center, 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) : Lorentzian1DParam<AutoDiff<T>>(other) {};
225 template <class W>
227 // </group>
228
229 // Copy assignment (deep copy)
231 Lorentzian1DParam<AutoDiff<T>>::operator=(other);
232 return *this;
233 };
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 { return new Lorentzian1D<AutoDiff<T>>(*this); };
249 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
250 return new Lorentzian1D<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
251 };
252 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
253 return new Lorentzian1D<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this);
254 };
255 // </group>
256
257 // # Make members of parent classes known.
258 protected:
259 using Lorentzian1DParam<AutoDiff<T>>::param_p;
260
261 public:
262 using Lorentzian1DParam<AutoDiff<T>>::HEIGHT;
263 using Lorentzian1DParam<AutoDiff<T>>::CENTER;
264 using Lorentzian1DParam<AutoDiff<T>>::WIDTH;
265 using Lorentzian1DParam<AutoDiff<T>>::fwhm2int;
266};
267
268#undef Lorentzian1D_PS
269
270} // namespace casacore
271
272#ifndef CASACORE_NO_AUTO_TEMPLATES
273#include "Lorentzian1D.tcc"
274#include "Lorentzian1D2.tcc"
275#endif // # CASACORE_NO_AUTO_TEMPLATES
276#endif
#define Lorentzian1D_PS
const T * FunctionArg
Definition Function1D.h:76
FunctionParam< T > param_p
Definition Function.h:337
T center() const
Get or set the center ordinate of the Lorentzian.
T width() const
Get or set the FWHM of the Lorentzian.
Lorentzian1DParam()
Constructs the one dimensional Lorentzians.
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).
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:126
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:129