casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Lorentzian1D.h
Go to the documentation of this file.
00001 //# Lorentzian1D.h: A one-dimensional Lorentzian class
00002 //# Copyright (C) 1995,1996,1997,2001,2002,2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: Lorentzian1D.h 20229 2010-02-15 12:19:06Z Wataru.Kawasaki $
00027 
00028 #ifndef SCIMATH_LORENTZIAN1D_H
00029 #define SCIMATH_LORENTZIAN1D_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/Lorentzian1DParam.h>
00034 #include <scimath/Functionals/Function1D.h>
00035 #include <scimath/Mathematics/AutoDiff.h>
00036 #include <scimath/Mathematics/AutoDiffMath.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward declarations
00041 
00042 // <summary> A one dimensional Lorentzian class.</summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tLorentzian1D" 
00047 // demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //   <li> <linkto class="Lorentzian1DParam">Lorentzian1DParam</linkto>
00052 //   <li> <linkto class="Function">Function</linkto>
00053 // </prerequisite>
00054 
00055 // <etymology> 
00056 // A Lorentzian1D functional is designed exclusively for calculating a
00057 // Lorentzian (or Normal) distribution in one dimension. Other classes exist
00058 // for calculating these functions in two
00059 // (<linkto class=Lorentzian2D>Lorentzian2D</linkto>) and N 
00060 // (<linkto class=LorentzianND>LorentzianND</linkto>) dimensions.
00061 // </etymology>
00062 
00063 // <synopsis> 
00064 // A <src>Lorentzian1D</src> is described by a height, center, and width. Its
00065 // fundamental operation is evaluating itself at some <src>x</src>.
00066 // The parameters (height, center and width) may be changed at run time. 
00067 //
00068 // The width of the Lorentzian (for the constructors or the <src>setWidth
00069 // </src> function) is always specified in terms of the full width at half
00070 // maximum (FWHM). It is always positive and attempts to set a non-positive
00071 // width will throw an assertion when in debug mode.
00072 //
00073 // The peak height of the Lorentzian can be specified at construction time or
00074 // by using the <src> setHeight </src> function. Alternatively the <src>
00075 // setFlux </src> function can be used to implicitly set the peak height by
00076 // specifying the integrated area under the Lorentzian. The height (or flux)
00077 // can be positive, negative or zero, as this class makes no assumptions on
00078 // what quantity the height represents.
00079 //
00080 // <note role=tip> Changing the width of the Lorentzian will not affect
00081 // its peak height but will change its flux. So you should always set the
00082 // width before setting the flux. </note>
00083 //
00084 // The parameter interface (see 
00085 // <linkto class="Lorentzian1DParam">Lorentzian1DParam</linkto> class), 
00086 // is used to provide an interface to the
00087 // <linkto module="Fitting">Fitting</linkto> classes. 
00088 //
00089 // There are 3 parameters that are used to describe the Lorentzian:
00090 // <ol>
00091 // <li> The height of the Lorentzian. This is identical to the value 
00092 //      returned using the <src>height()</src> member function.
00093 // <li> The center of the Lorentzian in the x direction. This is identical to
00094 //      the value returned using the <src>center()</src> member function. 
00095 // <li> The width (FWHM) of the Lorentzian. To aid convergence of
00096 //      the non-linear fitting routines this parameter is allowed to be
00097 //      negative. This does not affect the shape of the Lorentzian as the
00098 //      square of the width is used when evaluating the function.
00099 // </ol>
00100 //
00101 // An enumeration for the <src>HEIGHT</src>, <src>WIDTH</src> and
00102 // <src>CENTER</src> parameter index is provided, enabling the setting
00103 // and reading of parameters with the <src>[]</src> operator. The 
00104 // <src>mask()</src> methods can be used to check and set the parameter masks.
00105 //
00106 // </synopsis>
00107 
00108 // <example>
00109 // <srcblock>
00110 //    Lorentzian<Double> gf(5.0, 25.0, 7);
00111 //    gf(25);            // = 5.0
00112 //    gf[HEIGHT](1.0);
00113 //    gf.setWidth(2.0);                
00114 //    gf[CENTER](0.0);
00115 //    gf(1);             // = 0.5*height = 0.5
00116 // </srcblock>
00117 // </example>
00118 
00119 // <templating arg=T>
00120 //  <li> T should have standard numerical operators and exp() function. Current
00121 //      implementation only tested for real types.
00122 //  <li> To obtain derivatives, the derivatives should be defined.
00123 // </templating>
00124 
00125 // <thrown>
00126 //    <li> Assertion in debug mode if attempt is made to set a negative width
00127 //    <li> AipsError if incorrect parameter number specified.
00128 //    <li> Assertion in debug mode if operator(Vector<>) with empty Vector
00129 // </thrown>
00130 
00131 // <todo asof="2001/08/19">
00132 //   <li> Lorentzians that know about their DFT's could be required eventually.
00133 // </todo>
00134 
00135 template<class T> class Lorentzian1D : public Lorentzian1DParam<T> {
00136 public:
00137   //# Enumerations
00138   
00139   //# Constructors
00140   // Constructs the one dimensional Lorentzians. Defaults:
00141   // height=1, center=0, width(FWHM)=1.
00142   // <note role=warning> Could not use default arguments
00143   // that worked both with gcc and IRIX </note>
00144   // <group>
00145   Lorentzian1D() : Lorentzian1DParam<T>() {};
00146   explicit Lorentzian1D(const T &height) : Lorentzian1DParam<T>(height) {};
00147   Lorentzian1D(const T &height, const T &center) :
00148     Lorentzian1DParam<T>(height, center) {};
00149   Lorentzian1D(const T &height, const T &center, const T &width) :
00150     Lorentzian1DParam<T>(height, center, width) {};
00151   // </group>
00152 
00153   // Copy constructor (deep copy)
00154   // <group>
00155   Lorentzian1D(const Lorentzian1D<T> &other) : Lorentzian1DParam<T>(other) {};
00156   template <class W>
00157     Lorentzian1D(const Lorentzian1D<W> &other) : Lorentzian1DParam<T>(other) {}
00158   // </group>
00159 
00160   // Copy assignment (deep copy)
00161   Lorentzian1D<T> &operator=(const Lorentzian1D<T> &other) {
00162     Lorentzian1DParam<T>::operator=(other); return *this; };
00163     
00164   // Destructor
00165   virtual ~Lorentzian1D() {};
00166 
00167   //# Operators    
00168   // Evaluate the Lorentzian at <src>x</src>.
00169   // <group>
00170   virtual T eval(typename Function1D<T>::FunctionArg x) const;
00171   // </group>
00172 
00173   //# Member functions
00174   // Return a copy of this object from the heap. The caller is responsible 
00175   // for deleting this pointer.
00176   // <group>
00177   virtual Function<T> *clone() const { return new Lorentzian1D<T>(*this); };
00178   virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
00179     return new Lorentzian1D<typename FunctionTraits<T>::DiffType>(*this); };
00180   virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
00181     return new Lorentzian1D<typename FunctionTraits<T>::BaseType>(*this); };
00182   // </group>
00183 
00184   //# Make members of parent classes known.
00185 protected:
00186   using Lorentzian1DParam<T>::param_p;
00187 public:
00188   using Lorentzian1DParam<T>::HEIGHT;
00189   using Lorentzian1DParam<T>::CENTER;
00190   using Lorentzian1DParam<T>::WIDTH;
00191   using Lorentzian1DParam<T>::fwhm2int;
00192 };
00193 
00194 
00195 #define Lorentzian1D_PS Lorentzian1D
00196 
00197 // <summary> Partial specialization of Lorentzian1D for <src>AutoDiff</src>
00198 // </summary>
00199 
00200 // <synopsis>
00201 // <note role=warning> The name <src>Lorentzian1D_PS</src> is only for cxx2html
00202 // documentation problems. Use <src>Lorentzian1D</src> in your code.</note>
00203 // </synopsis>
00204 
00205 template <class T> class Lorentzian1D_PS<AutoDiff<T> > : 
00206 public Lorentzian1DParam<AutoDiff<T> >
00207 {
00208 public:
00209   //# Constructors
00210   // Constructs one dimensional Lorentzians.
00211   // <group>
00212   Lorentzian1D_PS() : Lorentzian1DParam<AutoDiff<T> >() {};
00213   explicit Lorentzian1D_PS(const AutoDiff<T> &height) :
00214     Lorentzian1DParam<AutoDiff<T> >(height) {};
00215   Lorentzian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center) :
00216     Lorentzian1DParam<AutoDiff<T> >(height, center) {};
00217   Lorentzian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center,
00218                   const AutoDiff<T> &width) :
00219     Lorentzian1DParam<AutoDiff<T> >(height, center, width) {};
00220   // </group>
00221 
00222   // Copy constructor (deep copy)
00223   // <group>
00224   Lorentzian1D_PS(const Lorentzian1D_PS &other) :
00225     Lorentzian1DParam<AutoDiff<T> >(other) {};
00226   template <class W>
00227   Lorentzian1D_PS(const Lorentzian1D_PS<W> &other) :
00228     Lorentzian1DParam<AutoDiff<T> >(other) {}
00229   // </group>
00230 
00231   // Copy assignment (deep copy)
00232   Lorentzian1D_PS<AutoDiff<T> > &
00233     operator=(const Lorentzian1D_PS<AutoDiff<T> > &other) {
00234     Lorentzian1DParam<AutoDiff<T> >::operator=(other); return *this; };
00235     
00236   // Destructor
00237   virtual ~Lorentzian1D_PS() {};
00238 
00239   //# Operators    
00240   // Evaluate the Lorentzian and its derivatives at <src>x</src>.
00241   // <group>
00242   virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
00243   // </group>
00244 
00245   //# Member functions
00246   // Return a copy of this object from the heap. The caller is responsible 
00247   // for deleting this pointer.
00248   // <group>
00249   virtual Function<AutoDiff<T> > *clone() const {
00250     return new Lorentzian1D<AutoDiff<T> >(*this); };
00251   virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType>
00252     *cloneAD() const {
00253     return new Lorentzian1D<typename FunctionTraits<AutoDiff<T> >::DiffType>
00254       (*this); };
00255   virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType>
00256     *cloneNonAD() const {
00257     return new Lorentzian1D<typename FunctionTraits<AutoDiff<T> >::BaseType>
00258       (*this); };
00259   // </group>
00260 
00261   //# Make members of parent classes known.
00262 protected:
00263   using Lorentzian1DParam<AutoDiff<T> >::param_p;
00264 public:
00265   using Lorentzian1DParam<AutoDiff<T> >::HEIGHT;
00266   using Lorentzian1DParam<AutoDiff<T> >::CENTER;
00267   using Lorentzian1DParam<AutoDiff<T> >::WIDTH;
00268   using Lorentzian1DParam<AutoDiff<T> >::fwhm2int;
00269 };
00270 
00271 #undef Lorentzian1D_PS
00272 
00273 
00274 } //# NAMESPACE CASA - END
00275 
00276 #ifndef CASACORE_NO_AUTO_TEMPLATES
00277 #include "Lorentzian1D.tcc"
00278 #include "Lorentzian1D2.tcc"
00279 #endif //# CASACORE_NO_AUTO_TEMPLATES
00280 #endif