//# Lorentzian1D.h: A one-dimensional Lorentzian class //# Copyright (C) 1995,1996,1997,2001,2002,2005 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# $Id: Lorentzian1D.h 20229 2010-02-15 12:19:06Z Wataru.Kawasaki $ #ifndef SCIMATH_LORENTZIAN1D_H #define SCIMATH_LORENTZIAN1D_H //# Includes #include #include "Lorentzian1DParam.h" #include #include #include namespace casa { //# NAMESPACE CASA - BEGIN //# Forward declarations // A one dimensional Lorentzian class. // // // // //
  • Lorentzian1DParam //
  • Function // // // A Lorentzian1D functional is designed exclusively for calculating a // Lorentzian (or Normal) distribution in one dimension. Other classes exist // for calculating these functions in two // (Lorentzian2D) and N // (LorentzianND) dimensions. // // // A Lorentzian1D is described by a height, center, and width. Its // fundamental operation is evaluating itself at some x. // The parameters (height, center and width) may be changed at run time. // // The width of the Lorentzian (for the constructors or the setWidth // function) is always specified in terms of the full width at half // maximum (FWHM). It is always positive and attempts to set a non-positive // width will throw an assertion when in debug mode. // // The peak height of the Lorentzian can be specified at construction time or // by using the setHeight function. Alternatively the // setFlux function can be used to implicitly set the peak height by // specifying the integrated area under the Lorentzian. The height (or flux) // can be positive, negative or zero, as this class makes no assumptions on // what quantity the height represents. // // Changing the width of the Lorentzian will not affect // its peak height but will change its flux. So you should always set the // width before setting the flux. // // The parameter interface (see // Lorentzian1DParam class), // is used to provide an interface to the // Fitting classes. // // There are 3 parameters that are used to describe the Lorentzian: //
      //
    1. The height of the Lorentzian. This is identical to the value // returned using the height() member function. //
    2. The center of the Lorentzian in the x direction. This is identical to // the value returned using the center() member function. //
    3. The width (FWHM) of the Lorentzian. To aid convergence of // the non-linear fitting routines this parameter is allowed to be // negative. This does not affect the shape of the Lorentzian as the // square of the width is used when evaluating the function. //
    // // An enumeration for the HEIGHT, WIDTH and // CENTER parameter index is provided, enabling the setting // and reading of parameters with the [] operator. The // mask() methods can be used to check and set the parameter masks. // //
    // // // Lorentzian gf(5.0, 25.0, 7); // gf(25); // = 5.0 // gf[HEIGHT](1.0); // gf.setWidth(2.0); // gf[CENTER](0.0); // gf(1); // = 0.5*height = 0.5 // // // //
  • T should have standard numerical operators and exp() function. Current // implementation only tested for real types. //
  • To obtain derivatives, the derivatives should be defined. // // //
  • Assertion in debug mode if attempt is made to set a negative width //
  • AipsError if incorrect parameter number specified. //
  • Assertion in debug mode if operator(Vector<>) with empty Vector // // //
  • Lorentzians that know about their DFT's could be required eventually. // template class Lorentzian1D : public Lorentzian1DParam { public: //# Enumerations //# Constructors // Constructs the one dimensional Lorentzians. Defaults: // height=1, center=0, width(FWHM)=1. // Could not use default arguments // that worked both with gcc and IRIX // Lorentzian1D() : Lorentzian1DParam() {}; explicit Lorentzian1D(const T &height) : Lorentzian1DParam(height) {}; Lorentzian1D(const T &height, const T ¢er) : Lorentzian1DParam(height, center) {}; Lorentzian1D(const T &height, const T ¢er, const T &width) : Lorentzian1DParam(height, center, width) {}; // // Copy constructor (deep copy) // Lorentzian1D(const Lorentzian1D &other) : Lorentzian1DParam(other) {}; template Lorentzian1D(const Lorentzian1D &other) : Lorentzian1DParam(other) {}; // // Copy assignment (deep copy) Lorentzian1D &operator=(const Lorentzian1D &other) { Lorentzian1DParam::operator=(other); return *this; }; // Destructor virtual ~Lorentzian1D() {}; //# Operators // Evaluate the Lorentzian at x. // virtual T eval(typename Function1D::FunctionArg x) const; // //# Member functions // Return a copy of this object from the heap. The caller is responsible // for deleting this pointer. // virtual Function *clone() const { return new Lorentzian1D(*this); }; virtual Function::DiffType> *cloneAD() const { return new Lorentzian1D::DiffType>(*this); }; virtual Function::BaseType> *cloneNonAD() const { return new Lorentzian1D::BaseType>(*this); }; // //# Make members of parent classes known. protected: using Lorentzian1DParam::param_p; public: using Lorentzian1DParam::HEIGHT; using Lorentzian1DParam::CENTER; using Lorentzian1DParam::WIDTH; using Lorentzian1DParam::fwhm2int; }; #define Lorentzian1D_PS Lorentzian1D // Partial specialization of Lorentzian1D for AutoDiff // // // The name Lorentzian1D_PS is only for cxx2html // documentation problems. Use Lorentzian1D in your code. // template class Lorentzian1D_PS > : public Lorentzian1DParam > { public: //# Constructors // Constructs one dimensional Lorentzians. // Lorentzian1D_PS() : Lorentzian1DParam >() {}; explicit Lorentzian1D_PS(const AutoDiff &height) : Lorentzian1DParam >(height) {}; Lorentzian1D_PS(const AutoDiff &height, const AutoDiff ¢er) : Lorentzian1DParam >(height, center) {}; Lorentzian1D_PS(const AutoDiff &height, const AutoDiff ¢er, const AutoDiff &width) : Lorentzian1DParam >(height, center, width) {}; // // Copy constructor (deep copy) // Lorentzian1D_PS(const Lorentzian1D_PS &other) : Lorentzian1DParam >(other) {}; template Lorentzian1D_PS(const Lorentzian1D_PS &other) : Lorentzian1DParam >(other) {}; // // Copy assignment (deep copy) Lorentzian1D_PS > & operator=(const Lorentzian1D_PS > &other) { Lorentzian1DParam >::operator=(other); return *this; }; // Destructor virtual ~Lorentzian1D_PS() {}; //# Operators // Evaluate the Lorentzian and its derivatives at x. // virtual AutoDiff eval(typename Function >::FunctionArg x) const; // //# Member functions // Return a copy of this object from the heap. The caller is responsible // for deleting this pointer. // virtual Function > *clone() const { return new Lorentzian1D >(*this); }; virtual Function >::DiffType> *cloneAD() const { return new Lorentzian1D >::DiffType> (*this); }; virtual Function >::BaseType> *cloneNonAD() const { return new Lorentzian1D >::BaseType> (*this); }; // //# Make members of parent classes known. protected: using Lorentzian1DParam >::param_p; public: using Lorentzian1DParam >::HEIGHT; using Lorentzian1DParam >::CENTER; using Lorentzian1DParam >::WIDTH; using Lorentzian1DParam >::fwhm2int; }; #undef Lorentzian1D_PS } //# NAMESPACE CASA - END #ifndef CASACORE_NO_AUTO_TEMPLATES #include "Lorentzian1D.tcc" #include "Lorentzian1D2.tcc" #endif //# CASACORE_NO_AUTO_TEMPLATES #endif