casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Gaussian1DParam.h
Go to the documentation of this file.
1 //# Gaussian1DParam.h: Parameter handling for one-dimensional Gaussian class
2 //# Copyright (C) 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_GAUSSIAN1DPARAM_H
29 #define SCIMATH_GAUSSIAN1DPARAM_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 
40 // <summary> Parameter handling for one dimensional Gaussian class.</summary>
41 
42 // <use visibility=local>
43 
44 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tGaussian1D"
45 // demos="">
46 // </reviewed>
47 
48 // <prerequisite>
49 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class
50 // <li> <linkto class="Function1D">Function1D</linkto> class
51 // </prerequisite>
52 
53 // <etymology>
54 // A 1-dimensional Gaussian's parameters.
55 // </etymology>
56 
57 // <synopsis>
58 // A <src>Gaussian1D</src> is described by a height, center, and width.
59 // The parameters (height, center and width) may be changed at run time.
60 //
61 // The width of the Gaussian (for the constructors or the <src>setWidth
62 // </src> function) is always specified in terms of the full width at half
63 // maximum (FWHM). It is always positive and attempts to set a non-positive
64 // width will throw an assertion when in debug mode.
65 //
66 // The peak height of the Gaussian can be specified at construction time or
67 // by using the <src> setHeight </src> function. Alternatively the <src>
68 // setFlux </src> function can be used to implicitly set the peak height by
69 // specifying the integrated area under the Gaussian. The height (or flux)
70 // can be positive, negative or zero, as this class makes no assumptions on
71 // what quantity the height represents.
72 //
73 // <note role=tip> Changing the width of the Gaussian will not affect
74 // its peak height but will change its flux. So you should always set the
75 // width before setting the flux. </note>
76 //
77 // The parameter interface (see
78 // <linkto class="FunctionParam">FunctionParam</linkto> class),
79 // is used to provide an interface to the
80 // <linkto module="Fitting">Fitting</linkto> classes.
81 //
82 // There are 3 parameters that are used to describe the Gaussian:
83 // <ol>
84 // <li> The height of the Gaussian. This is identical to the value
85 // returned using the <src>height()</src> member function.
86 // <li> The center of the Gaussian in the x direction. This is identical to
87 // the value returned using the <src>center()</src> member function.
88 // <li> The width (FWHM) of the Gaussian. To aid convergence of
89 // the non-linear fitting routines this parameter is allowed to be
90 // negative. This does not affect the shape of the Gaussian as the
91 // square of the width is used when evaluating the function.
92 // </ol>
93 //
94 // An enumeration for the <src>HEIGHT</src>, <src>WIDTH</src> and
95 // <src>CENTER</src> parameter index is provided, enabling the setting
96 // and reading of parameters with the <src>[]</src> operator. The
97 // <src>mask()</src> methods can be used to check and set the parameter masks.
98 //
99 // This class is in general used implicitly by the <src>Gaussian1D</src>
100 // class only.
101 // </synopsis>
102 
103 // <example>
104 // <srcblock>
105 // Gaussian1D<Double> gf(5.0, 25.0, 7);
106 // gf(25); // = 5.0
107 // gf.setHeight(1.0);
108 // gf[WIDTH](2.0);
109 // gf[CENTER](0.0);
110 // gf(1); // = 0.5*height = 0.5
111 // </srcblock>
112 // </example>
113 
114 // <templating arg=T>
115 // <li> T should have standard numerical operators and exp() function. Current
116 // implementation only tested for real types (and their AutoDiffs).
117 // </templating>
118 
119 // <thrown>
120 // <li> Assertion in debug mode if attempt is made to set a negative width
121 // <li> AipsError if incorrect parameter number specified.
122 // </thrown>
123 
124 // <todo asof="2001/08/19">
125 // <li> Gaussians that know about their DFT's could be required eventually.
126 // </todo>
127 
128 template<class T> class Gaussian1DParam : public Function1D<T> {
129 public:
130  //# Enumerations
131  enum { HEIGHT=0, CENTER, WIDTH };
132 
133  //# Constructors
134  // Constructs the one dimensional Gaussians. Defaults:
135  // height=1, center=0, width(FWHM)=1.
136  // <note role=warning> Could not use default arguments
137  // that worked both with gcc and IRIX and all templates</note>
138  // <group>
139  Gaussian1DParam();
140  explicit Gaussian1DParam(const T &height);
141  Gaussian1DParam(const T &height, const T &center);
142  Gaussian1DParam(const T &height, const T &center, const T &width);
143  // </group>
144 
145  // Copy constructor (deep copy)
146  // <group>
147  Gaussian1DParam(const Gaussian1DParam<T> &other);
148  template <class W>
150  Function1D<T>(other),
151  fwhm2int(T(1.0)/sqrt(log(T(16.0)))) {}
152  // </group>
153  // Copy assignment (deep copy)
155 
156  // Destructor
157  virtual ~Gaussian1DParam();
158 
159  //# Operators
160 
161  //# Member functions
162  // Give name of function
163  virtual const String &name() const { static String x("gaussian1d");
164  return x; }
165 
166  // Get or set the peak height of the Gaussian
167  // <group>
168  T height() const { return param_p[HEIGHT]; }
169  void setHeight(const T &height) { param_p[HEIGHT] = height; }
170  // </group>
171 
172  // Get or set the analytical integrated area underneath the Gaussian.
173  // Use these functions as an alternative to the height functions.
174  // <group>
175  T flux() const;
176  void setFlux(const T &flux);
177  // </group>
178 
179  // Get or set the center ordinate of the Gaussian
180  // <group>
181  T center() const { return param_p[CENTER]; }
182  void setCenter(const T &cnter) { param_p[CENTER] = cnter; }
183  // </group>
184 
185  // Get or set the FWHM of the Gaussian.
186  // <group>
187  T width() const { return param_p[WIDTH]; }
188  void setWidth(const T &width) { param_p[WIDTH] = width; }
189  // </group>
190 
191 protected:
192  // Constant to scale halfwidth at 1/e to FWHM
194 
195  //# Make members of parent classes known.
196 protected:
198 public:
200 };
201 
202 
203 } //# NAMESPACE CASACORE - END
204 
205 #ifndef CASACORE_NO_AUTO_TEMPLATES
206 #include <casacore/scimath/Functionals/Gaussian1DParam.tcc>
207 #endif //# CASACORE_NO_AUTO_TEMPLATES
208 #endif
FunctionParam< T > param_p
The parameters and masks.
Definition: Function.h:332
LatticeExprNode log(const LatticeExprNode &expr)
T center() const
Get or set the center ordinate of the Gaussian.
virtual const String & name() const
Give name of function.
T width() const
Get or set the FWHM of the Gaussian.
T height() const
Get or set the peak height of the Gaussian.
void setFlux(const T &flux)
void setHeight(const T &height)
virtual ~Gaussian1DParam()
Destructor.
T fwhm2int
Constant to scale halfwidth at 1/e to FWHM.
LatticeExprNode sqrt(const LatticeExprNode &expr)
Gaussian1DParam(const Gaussian1DParam< W > &other)
Numerical functional interface class for 1 dimension.
Definition: Function1D.h:75
void setCenter(const T &cnter)
T flux() const
Get or set the analytical integrated area underneath the Gaussian.
Gaussian1DParam< T > & operator=(const Gaussian1DParam< T > &other)
Copy assignment (deep copy)
String: the storage and methods of handling collections of characters.
Definition: String.h:225
void setWidth(const T &width)
Gaussian1DParam()
Constructs the one dimensional Gaussians.
Parameter handling for one dimensional Gaussian class.