[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[909] | 3 | // $Id: specresp.cc,v 1.4 2000-04-13 14:10:45 ansari Exp $
|
---|
[601] | 4 | //
|
---|
| 5 | // Description:
|
---|
| 6 | // Aim of the class: To give the energy density
|
---|
| 7 | // The unity used here is W/m^2/Hz/sr
|
---|
| 8 | //
|
---|
| 9 | // History (add to end):
|
---|
| 10 | // Sophie Oct, 1999 - creation
|
---|
| 11 | //
|
---|
| 12 | //------------------------------------------------------------------------
|
---|
| 13 |
|
---|
| 14 | //---------------
|
---|
| 15 | // C++ Headers --
|
---|
| 16 | //---------------
|
---|
| 17 | #include <typeinfo>
|
---|
| 18 | #include <math.h>
|
---|
| 19 | #include "specresp.h"
|
---|
| 20 | #include "integ.h"
|
---|
[668] | 21 | #include "tvector.h"
|
---|
[601] | 22 |
|
---|
[909] | 23 | /*!
|
---|
| 24 | * \class SOPHYA::SpectralResponse <BR>
|
---|
| 25 | SpectralResponse corresponds to a detector filter's
|
---|
| 26 | response as a function of the frequency.
|
---|
| 27 | The SpectralResponse class is an abstract class.
|
---|
| 28 | The virtual constructor takes as arguments the
|
---|
| 29 | minimum and maximum values of the frequency range on
|
---|
| 30 | which the detector response is defined
|
---|
| 31 | */
|
---|
[601] | 32 | //----------------
|
---|
| 33 | // Constructor --
|
---|
| 34 | //----------------
|
---|
| 35 | SpectralResponse::SpectralResponse(double numin, double numax)
|
---|
| 36 | {
|
---|
| 37 | _numin = numin;
|
---|
| 38 | _numax = numax;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | //--------------
|
---|
| 43 | // Destructor --
|
---|
| 44 | //--------------
|
---|
| 45 | SpectralResponse::~SpectralResponse()
|
---|
| 46 | {
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | // ---------------------------
|
---|
| 50 | // -- Function Definitions --
|
---|
| 51 | // ---------------------------
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | double
|
---|
| 55 | SpectralResponse::minFreq() const
|
---|
| 56 | {
|
---|
| 57 | return _numin;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | double
|
---|
| 61 | SpectralResponse::maxFreq() const
|
---|
| 62 | {
|
---|
| 63 | return _numax;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | double
|
---|
| 67 | SpectralResponse::meanFreq() const
|
---|
| 68 | {
|
---|
| 69 | return (_numax+_numin)/2.;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 |
|
---|
[668] | 73 | // To change min-max frequency
|
---|
| 74 | void
|
---|
| 75 | SpectralResponse::setMinMaxFreq(double numin, double numax)
|
---|
| 76 | {
|
---|
| 77 | _numin = numin;
|
---|
| 78 | _numax = numax;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[601] | 81 |
|
---|
| 82 | // peakFreq returns the value of the frequency for the
|
---|
| 83 | // peak of the spectrum.
|
---|
| 84 | double
|
---|
| 85 | SpectralResponse::peakFreq() const
|
---|
| 86 | {
|
---|
| 87 | double maxAnswer = -1.e99;
|
---|
| 88 | double maxNu = -10;
|
---|
| 89 | double nu;
|
---|
| 90 | for (int i=1; i<1000;i++)
|
---|
| 91 | {
|
---|
| 92 | nu=(_numax-_numin)*i/1000.+_numin;
|
---|
| 93 | double lookForMax =transmission(nu);
|
---|
| 94 | if(maxAnswer <= lookForMax) {
|
---|
| 95 | maxAnswer= lookForMax;
|
---|
| 96 | maxNu = nu;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | return maxNu;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | double
|
---|
| 104 | SpectralResponse::peakTransmission() const
|
---|
| 105 | {
|
---|
| 106 | double nuPeak = this->peakFreq();
|
---|
| 107 | return transmission(nuPeak);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | static SpectralResponse* _mySpecResp = NULL;
|
---|
| 111 |
|
---|
| 112 | static double SpectralResponse_transmission(double nu)
|
---|
| 113 | {
|
---|
| 114 | return(_mySpecResp->transmission(nu));
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
[909] | 118 | /*!
|
---|
| 119 | This function performs the integration
|
---|
| 120 | of the transmission function in its frequency range
|
---|
| 121 | (defined when instanciating an object of on of the
|
---|
| 122 | subclasses)
|
---|
| 123 | */
|
---|
[601] | 124 | double
|
---|
| 125 | SpectralResponse::IntegratedSpect() const
|
---|
| 126 | {
|
---|
| 127 | double value = this->IntegratedSpect(_numin, _numax);
|
---|
| 128 | return value;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[909] | 131 | /*!
|
---|
| 132 | The IntegratedSpect function performs the integration
|
---|
| 133 | of the transmission function in a frequency range <BR> defined by
|
---|
| 134 | numin and numax.
|
---|
| 135 | */
|
---|
[601] | 136 | double
|
---|
| 137 | SpectralResponse::IntegratedSpect(double numin, double numax) const
|
---|
| 138 | {
|
---|
[668] | 139 | if(numin < this->minFreq()) numin = this->minFreq();
|
---|
| 140 | if(numax > this->maxFreq()) numax = this->maxFreq();
|
---|
| 141 |
|
---|
| 142 |
|
---|
[601] | 143 | _mySpecResp = const_cast<SpectralResponse *>(this);
|
---|
| 144 | TrpzInteg I(SpectralResponse_transmission , numin, numax);
|
---|
[607] | 145 | double val = (double)I;
|
---|
[601] | 146 | _mySpecResp= NULL;
|
---|
[607] | 147 | return(val);
|
---|
[601] | 148 | }
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | static SpectralResponse* _myLogSpecResp = NULL;
|
---|
| 152 |
|
---|
| 153 | static double SpectralResponse_logTransmission(double tau)
|
---|
| 154 | {
|
---|
| 155 | double value = _myLogSpecResp->transmission(pow(10,tau))*pow(10,tau);
|
---|
| 156 | return(value);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[909] | 159 | /*!
|
---|
| 160 | The logIntegratedSpect function performs the integration
|
---|
| 161 | of the logarithm of the transmission function in a frequency range <BR> defined by
|
---|
| 162 | numin and numax.
|
---|
| 163 | */
|
---|
[601] | 164 | double
|
---|
| 165 | SpectralResponse::logIntegratedSpect(double numin, double numax) const
|
---|
| 166 | {
|
---|
[668] | 167 | if(numin <= this->minFreq()) numin = this->minFreq();
|
---|
| 168 | if(numax >= this->maxFreq()) numax = this->maxFreq();
|
---|
[601] | 169 | if(numin == 0) numin = 1.e-99;
|
---|
| 170 | double f1Log = log10(numin);
|
---|
| 171 | double f2Log = log10(numax);
|
---|
| 172 | if(f1Log < -1.e99) f1Log = -1.e99;
|
---|
| 173 | if(f2Log > 1.e99) f2Log = 1.e99;
|
---|
| 174 | _myLogSpecResp = const_cast<SpectralResponse *>(this);
|
---|
| 175 | TrpzInteg I(SpectralResponse_logTransmission ,f1Log,f2Log);
|
---|
[607] | 176 | double val = (double)I;
|
---|
[601] | 177 | _myLogSpecResp= NULL;
|
---|
[607] | 178 | return(val*log(10.));
|
---|
[601] | 179 | }
|
---|
| 180 |
|
---|
[909] | 181 | /*!
|
---|
| 182 | Same than IntegratedSpect(numin,numax) over its
|
---|
| 183 | frequency range defined at the initialisation
|
---|
| 184 | */
|
---|
[601] | 185 | double
|
---|
| 186 | SpectralResponse::logIntegratedSpect() const
|
---|
| 187 | {
|
---|
| 188 | double value = this->logIntegratedSpect(_numin, _numax);
|
---|
| 189 | return value;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | void
|
---|
| 194 | SpectralResponse::Print(ostream& os) const
|
---|
| 195 | {
|
---|
| 196 |
|
---|
| 197 | // os << "SpectralResponse::Print (" << typeid(*this).name()
|
---|
| 198 | //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 199 | os << "SpectralResponse::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 200 | os << "MeanFreq= " << meanFreq() << " Transmission= " << transmission(meanFreq()) << endl;
|
---|
| 201 | os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
|
---|
| 202 |
|
---|
| 203 | }
|
---|