| 1 | //--------------------------------------------------------------------------
|
|---|
| 2 | // File and Version Information:
|
|---|
| 3 | // $Id: gaussfilt.cc,v 1.9 2004-09-10 09:54:40 cmv Exp $
|
|---|
| 4 | //
|
|---|
| 5 | // Description:
|
|---|
| 6 | //
|
|---|
| 7 | // History (add to end):
|
|---|
| 8 | // Sophie Oct, 1999 - creation
|
|---|
| 9 | //
|
|---|
| 10 | //------------------------------------------------------------------------
|
|---|
| 11 |
|
|---|
| 12 | //---------------
|
|---|
| 13 | // C++ Headers --
|
|---|
| 14 | //---------------
|
|---|
| 15 | #include "sopnamsp.h"
|
|---|
| 16 | #include "machdefs.h"
|
|---|
| 17 | #include <iostream>
|
|---|
| 18 | #include <math.h>
|
|---|
| 19 |
|
|---|
| 20 | #include "gaussfilt.h"
|
|---|
| 21 |
|
|---|
| 22 | /*!
|
|---|
| 23 | * \class SOPHYA::GaussianFilter
|
|---|
| 24 | * \ingroup SkyT
|
|---|
| 25 | * Gaussian detector response
|
|---|
| 26 | */
|
|---|
| 27 | GaussianFilter::GaussianFilter()
|
|---|
| 28 | : SpectralResponse()
|
|---|
| 29 | {
|
|---|
| 30 | setParams(100, 10., 1.);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | /*! Constructor: the parameters correspond to the function defined in the
|
|---|
| 34 | <a href="#gausseq"> equation </a> below
|
|---|
| 35 | */
|
|---|
| 36 | GaussianFilter::GaussianFilter(double nu0, double s, double a, double numin, double numax)
|
|---|
| 37 | : SpectralResponse(numin, numax)
|
|---|
| 38 | {
|
|---|
| 39 | setParams(nu0, s, a);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | //--------------
|
|---|
| 44 | // Destructor --
|
|---|
| 45 | //--------------
|
|---|
| 46 | GaussianFilter::~GaussianFilter()
|
|---|
| 47 | {
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | // ---------------------------
|
|---|
| 51 | // -- Function Definitions --
|
|---|
| 52 | // ---------------------------
|
|---|
| 53 |
|
|---|
| 54 | /*! The transmission function is the wel known gaussian:
|
|---|
| 55 | <a name="gausseq"> </a>
|
|---|
| 56 | \f[
|
|---|
| 57 | \hbox{transmission}= A e^{-{({\nu-\nu_0\over s})^2}};
|
|---|
| 58 | \f]
|
|---|
| 59 | */
|
|---|
| 60 |
|
|---|
| 61 | double
|
|---|
| 62 | GaussianFilter::transmission(double nu) const
|
|---|
| 63 | {
|
|---|
| 64 | if ((nu < _numin) || (nu > _numax)) return(0.);
|
|---|
| 65 | else {
|
|---|
| 66 | double tmp = (nu-_nu0)/_s;
|
|---|
| 67 | return(_a * exp(-tmp*tmp));
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | double
|
|---|
| 72 | GaussianFilter::peakFreq() const
|
|---|
| 73 | {
|
|---|
| 74 | return(_nu0);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | double
|
|---|
| 78 | GaussianFilter::peakTransmission() const
|
|---|
| 79 | {
|
|---|
| 80 | return(_a);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | void
|
|---|
| 86 | GaussianFilter::setParams(double nu0, double s, double a)
|
|---|
| 87 | {
|
|---|
| 88 | if (s < 1.e-19) s = 1.e-19;
|
|---|
| 89 | _s = s;
|
|---|
| 90 | _nu0 = nu0;
|
|---|
| 91 | _a = a;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | void
|
|---|
| 97 | GaussianFilter::Print(ostream& os) const
|
|---|
| 98 | {
|
|---|
| 99 | os << "GaussianFilter::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
|---|
| 100 | os << " T = A * Exp(-((nu-nu0)/s)^2) : " << " nu0= " << _nu0 << " sig= "
|
|---|
| 101 | << _s << " A= " << _a << endl;
|
|---|
| 102 | os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
|---|
| 108 | void
|
|---|
| 109 | ObjFileIO<GaussianFilter>::WriteSelf(POutPersist& s) const
|
|---|
| 110 | {
|
|---|
| 111 | if(dobj == NULL)
|
|---|
| 112 | {
|
|---|
| 113 | cout << " ObjFileIO<GaussianFilter>::WriteSelf:: dobj= null " << endl;
|
|---|
| 114 | return;
|
|---|
| 115 | }
|
|---|
| 116 | int_4 version, nothing;
|
|---|
| 117 | version = 1;
|
|---|
| 118 | nothing = 0; // Reserved for future use
|
|---|
| 119 | s.PutI4(version);
|
|---|
| 120 | s.PutI4(nothing);
|
|---|
| 121 |
|
|---|
| 122 | s.PutR8(dobj->minFreq());
|
|---|
| 123 | s.PutR8(dobj->maxFreq());
|
|---|
| 124 | s.PutR8(dobj->giveNorm());
|
|---|
| 125 | s.PutR8(dobj->giveNu0());
|
|---|
| 126 | s.PutR8(dobj->giveDNu());
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
|---|
| 130 | void
|
|---|
| 131 | ObjFileIO<GaussianFilter>::ReadSelf(PInPersist& s)
|
|---|
| 132 | {
|
|---|
| 133 | int_4 version, nothing;
|
|---|
| 134 | version = 1;
|
|---|
| 135 | nothing = 0; // Reserved for future use
|
|---|
| 136 | s.GetI4(version);
|
|---|
| 137 | s.GetI4(nothing);
|
|---|
| 138 |
|
|---|
| 139 | if(dobj == NULL)
|
|---|
| 140 | {
|
|---|
| 141 | dobj= new GaussianFilter();
|
|---|
| 142 | ownobj= true;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | r_8 a, nu0, dnu, numin, numax;
|
|---|
| 146 | s.GetR8(numin);
|
|---|
| 147 | s.GetR8(numax);
|
|---|
| 148 | s.GetR8(a);
|
|---|
| 149 | s.GetR8(nu0);
|
|---|
| 150 | s.GetR8(dnu);
|
|---|
| 151 | dobj->setMinMaxFreq(numin, numax);
|
|---|
| 152 | dobj->setParams(nu0, dnu, a);
|
|---|
| 153 | // cout << " Norm - Nu0 - DNu - minFreq - maxFreq " << endl;
|
|---|
| 154 | // cout << _a << "-" << _nu0 << "-" << _s << "-" << _numin << "-" << _numax << endl;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
|---|
| 159 | #pragma define_template ObjFileIO<GaussianFilter>
|
|---|
| 160 | #endif
|
|---|
| 161 |
|
|---|
| 162 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
|---|
| 163 | template class ObjFileIO<GaussianFilter>;
|
|---|
| 164 | #endif
|
|---|