casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GaussianMultipletSpectralElement.h
Go to the documentation of this file.
00001 //# SpectralElement.h: Describes (a set of related) spectral lines
00002 //# Copyright (C) 2001,2003,2004
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 //#
00027 //# $Id: SpectralElement.h 20652 2009-07-06 05:04:32Z Malte.Marquarding $
00028 
00029 #ifndef COMPONENTS_GAUSSIANMULTIPLETSPECTRALELEMENT_H
00030 #define COMPONENTS_GAUSSIANMULTIPLETSPECTRALELEMENT_H
00031 
00032 #include <casa/Arrays/Matrix.h>
00033 #include <components/SpectralComponents/CompiledSpectralElement.h>
00034 #include <components/SpectralComponents/GaussianSpectralElement.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 // <summary>
00039 // Describes a multiplet of Gaussian shaped spectral lines
00040 // </summary>
00041 
00042 // <use visibility=export>
00043 
00044 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
00045 // </reviewed>
00046 
00047 // <prerequisite>
00048 //   <li> <linkto module=SpectralElement>SpectralElement</linkto> module
00049 //   <li> <linkto module=GaussianSpectralElement>CompiledSpectralElement</linkto> module
00050 //   <li> <linkto module=CompiledSpectralElement>CompiledSpectralElement</linkto> module
00051 // </prerequisite>
00052 //
00053 // <etymology>
00054 // From Gaussian and multiplet and spectral line and element
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // The GaussianMultipletSpectralElement class describes a multiplet
00059 // of Gaussian shaped spectral lines for describing spectral profile.
00060 //
00061 // Relationships between Gaussians in the multiplet must be specified.
00062 // Any combination of one or more of fixed relationships between line
00063 // center offsets, line amplitude ratios, and/or line width ratios can
00064 // be specified between a single reference line in the multiplet and
00065 // other (non-reference) lines in the multiplet. The constructor
00066 // takes a Vector of GaussianSpectralElements which describes the estimates
00067 // of the n Gaussians in the multiplet. These objects themselves are not
00068 // used in the fitting, but are used only to create the function that describes
00069 // the multiplet. The first element in this Vector represents the reference line
00070 // to which parameters of the other lines are constrained. In addition, the
00071 // constructor takes an n-1 x 3 Matrix<Double> describing the fixed relationships
00072 // between the reference line and the other lines in the multiplet. Each ith row
00073 // describes the fixed relationship(s) between the (i+1)th and the zeroth
00074 // (reference) Gaussian. The first element of each row describes the ratio of
00075 // amplitudes between the (i+1)th and reference Gaussian, the second element
00076 // describes the difference between the center locations of the (i+1)th and
00077 // reference Gaussian, and the third represents the ratio of the FWHM of the
00078 // (i+1)th and reference Gaussian. A value of 0 for any of these indicates there
00079 // is no fixed relationship for that parameter. At least one value must be non-zero
00080 // for each row and any combination of elements (including all of them) can be
00081 // non-zero for any row in this matrix. The values of parameters of non-reference
00082 // lines in the input vector that are constrained to the reference line are
00083 // implicitly ignored and set in the constructor according to the specified
00084 // constraint. If any of the parameters of the reference line are specified as
00085 // fixed, the corresponding parameters of any non-reference lines which have the
00086 // corresponding parameters constrained to the reference line are also implicitly
00087 // fixed. Fixing a parameter in a non-reference line that is constrained to the
00088 // corresponding parameter of the reference line that is not fixed will cause an
00089 // exception.
00090 // </synopsis>
00091 //
00092 // <example>
00093 // This is how to specify a doublet in which the only constraint is that the amplitudes
00094 // between the lines must be fixed, the first Gaussian must have an ampliute of 0.6 times
00095 // the zeroth (reference) Gaussian. Other than that, all other parameters can
00096 // vary during the fit:
00097 
00098 // GaussianSpectralElement reference(5, 25, 16);
00099 // // The amplitude value of first is ignored because of the relationship to the
00100 // // reference, but it still must be specified in the constructor and must be
00101 // // non-zero or an exception will be thrown.
00102 // GaussianSpectralElement first(1, 40, 17);
00103 // Vector<GaussianSpectralElement> pair(2);
00104 // pair[0] = reference;
00105 // pair[1] = first;
00106 // // initialize constraints matrix to have nothing constrained (all values 0)
00107 // Matrix<Double> fixedRel(1, 3, 0);
00108 // // Set the ratio of amplitudes between the first and reference (zeroth) line
00109 // // to be 0.6.
00110 // fixedRel[0][0] = 0.6
00111 // GaussianMultipletSpectralElement doublet(pair,"",fixedRel);
00112 // </example>
00113 //
00114 // <motivation>
00115 // To allow specifying constraints between different Gaussian spectral
00116 // lines for fitting, eg to support fitting of doublets.
00117 // </motivation>
00118 
00119 class GaussianMultipletSpectralElement: public CompiledSpectralElement {
00120 public:
00121 
00122         // Construct a Gaussian multiplet. The values of non-reference (non-zeroth)
00123         // estimates will be automatically adjusted if there is a fixed relationship
00124         // between a non-reference Gaussian parameter and the corresponding reference
00125         // Gaussian parameter.
00126         GaussianMultipletSpectralElement(
00127                 const Vector<GaussianSpectralElement>& estimates,
00128                 const Matrix<Double>& fixedRelationships
00129         );
00130 
00131         // copy semantics
00132         GaussianMultipletSpectralElement(
00133                 const GaussianMultipletSpectralElement& other
00134         );
00135 
00136         ~GaussianMultipletSpectralElement();
00137 
00138         SpectralElement* clone() const;
00139 
00140         // copy semantics
00141         GaussianMultipletSpectralElement &operator=(
00142                 const GaussianMultipletSpectralElement& other
00143         );
00144 
00145         Bool operator==(
00146                 const GaussianMultipletSpectralElement& other
00147         ) const;
00148 
00149         // get the gaussians
00150         const Vector<GaussianSpectralElement>& getGaussians() const;
00151 
00152         // get the constraints matrix
00153         const Matrix<Double>& getConstraints() const;
00154 
00155         //<group>
00156         // These methods must be public because the architecture of
00157         // the class hierarchy requires it and set() and setError()
00158         // must be accessible by fitters. However, it is strongly
00159         // recommended that other classes not call these methods for
00160         // object configuration but rather set them implicitly at
00161         // construction via the Vector<GaussianSpectralElement>
00162         // passed to the constructor.
00163         void set(const Vector<Double>& param);
00164 
00165         void setError(const Vector<Double> &err);
00166 
00167         void fix(const Vector<Bool>& fix);
00168         // </group>
00169         // Save to a record.
00170         Bool toRecord(RecordInterface& out) const;
00171 
00172 private:
00173         Vector<GaussianSpectralElement> _gaussians;
00174         Matrix<Double> _constraints;
00175         Matrix<uInt> _paramIndices;
00176 };
00177 
00178 ostream &operator<<(ostream &os, const GaussianMultipletSpectralElement &elem);
00179 
00180 } //# NAMESPACE CASA - END
00181 
00182 #endif
00183