| [601] | 1 | //-------------------------------------------------------------------------- | 
|---|
|  | 2 | // File and Version Information: | 
|---|
| [607] | 3 | //      $Id: specresp.cc,v 1.2 1999-11-20 21:00:52 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" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | //---------------- | 
|---|
|  | 23 | // Constructor -- | 
|---|
|  | 24 | //---------------- | 
|---|
|  | 25 | SpectralResponse::SpectralResponse(double numin, double numax) | 
|---|
|  | 26 | { | 
|---|
|  | 27 | _numin = numin; | 
|---|
|  | 28 | _numax = numax; | 
|---|
|  | 29 | } | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
|  | 32 | //-------------- | 
|---|
|  | 33 | // Destructor -- | 
|---|
|  | 34 | //-------------- | 
|---|
|  | 35 | SpectralResponse::~SpectralResponse() | 
|---|
|  | 36 | { | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | //              --------------------------- | 
|---|
|  | 40 | //              --  Function Definitions -- | 
|---|
|  | 41 | //              --------------------------- | 
|---|
|  | 42 |  | 
|---|
|  | 43 |  | 
|---|
|  | 44 | double | 
|---|
|  | 45 | SpectralResponse::minFreq()  const | 
|---|
|  | 46 | { | 
|---|
|  | 47 | return _numin; | 
|---|
|  | 48 | } | 
|---|
|  | 49 |  | 
|---|
|  | 50 | double | 
|---|
|  | 51 | SpectralResponse::maxFreq()  const | 
|---|
|  | 52 | { | 
|---|
|  | 53 | return _numax; | 
|---|
|  | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 | double | 
|---|
|  | 57 | SpectralResponse::meanFreq()  const | 
|---|
|  | 58 | { | 
|---|
|  | 59 | return (_numax+_numin)/2.; | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
|  | 62 |  | 
|---|
|  | 63 |  | 
|---|
|  | 64 | // peakFreq returns the value of the frequency for the | 
|---|
|  | 65 | // peak of the spectrum. | 
|---|
|  | 66 | double | 
|---|
|  | 67 | SpectralResponse::peakFreq()  const | 
|---|
|  | 68 | { | 
|---|
|  | 69 | double maxAnswer = -1.e99; | 
|---|
|  | 70 | double maxNu = -10; | 
|---|
|  | 71 | double nu; | 
|---|
|  | 72 | for (int i=1; i<1000;i++) | 
|---|
|  | 73 | { | 
|---|
|  | 74 | nu=(_numax-_numin)*i/1000.+_numin; | 
|---|
|  | 75 | double lookForMax =transmission(nu); | 
|---|
|  | 76 | if(maxAnswer <= lookForMax) { | 
|---|
|  | 77 | maxAnswer= lookForMax; | 
|---|
|  | 78 | maxNu    = nu; | 
|---|
|  | 79 | } | 
|---|
|  | 80 | } | 
|---|
|  | 81 | return maxNu; | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 |  | 
|---|
|  | 85 | double | 
|---|
|  | 86 | SpectralResponse::peakTransmission()  const | 
|---|
|  | 87 | { | 
|---|
|  | 88 | double nuPeak = this->peakFreq(); | 
|---|
|  | 89 | return transmission(nuPeak); | 
|---|
|  | 90 | } | 
|---|
|  | 91 |  | 
|---|
|  | 92 | static SpectralResponse* _mySpecResp = NULL; | 
|---|
|  | 93 |  | 
|---|
|  | 94 | static double SpectralResponse_transmission(double nu) | 
|---|
|  | 95 | { | 
|---|
|  | 96 | return(_mySpecResp->transmission(nu)); | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 |  | 
|---|
|  | 100 | double | 
|---|
|  | 101 | SpectralResponse::IntegratedSpect()  const | 
|---|
|  | 102 | { | 
|---|
|  | 103 | double value = this->IntegratedSpect(_numin, _numax); | 
|---|
|  | 104 | return value; | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | double | 
|---|
|  | 108 | SpectralResponse::IntegratedSpect(double numin, double numax) const | 
|---|
|  | 109 | { | 
|---|
|  | 110 | _mySpecResp = const_cast<SpectralResponse *>(this); | 
|---|
|  | 111 | if(numin <= _numin) numin = _numin; | 
|---|
|  | 112 | if(numax >= _numax) numax = _numax; | 
|---|
|  | 113 | TrpzInteg I(SpectralResponse_transmission , numin, numax); | 
|---|
| [607] | 114 | double val = (double)I; | 
|---|
| [601] | 115 | _mySpecResp= NULL; | 
|---|
| [607] | 116 | return(val); | 
|---|
| [601] | 117 | } | 
|---|
|  | 118 |  | 
|---|
|  | 119 |  | 
|---|
|  | 120 | static SpectralResponse* _myLogSpecResp = NULL; | 
|---|
|  | 121 |  | 
|---|
|  | 122 | static double SpectralResponse_logTransmission(double tau) | 
|---|
|  | 123 | { | 
|---|
|  | 124 | double value =  _myLogSpecResp->transmission(pow(10,tau))*pow(10,tau); | 
|---|
|  | 125 | return(value); | 
|---|
|  | 126 | } | 
|---|
|  | 127 |  | 
|---|
|  | 128 | double | 
|---|
|  | 129 | SpectralResponse::logIntegratedSpect(double numin, double numax) const | 
|---|
|  | 130 | { | 
|---|
|  | 131 | if(numin <= _numin) numin = _numin; | 
|---|
|  | 132 | if(numax >= _numax) numax = _numax; | 
|---|
|  | 133 | if(numin == 0) numin = 1.e-99; | 
|---|
|  | 134 | double f1Log = log10(numin); | 
|---|
|  | 135 | double f2Log = log10(numax); | 
|---|
|  | 136 | if(f1Log < -1.e99) f1Log = -1.e99; | 
|---|
|  | 137 | if(f2Log > 1.e99)  f2Log = 1.e99; | 
|---|
|  | 138 | _myLogSpecResp = const_cast<SpectralResponse *>(this); | 
|---|
|  | 139 | TrpzInteg I(SpectralResponse_logTransmission ,f1Log,f2Log); | 
|---|
| [607] | 140 | double val = (double)I; | 
|---|
| [601] | 141 | _myLogSpecResp= NULL; | 
|---|
| [607] | 142 | return(val*log(10.)); | 
|---|
| [601] | 143 | } | 
|---|
|  | 144 |  | 
|---|
|  | 145 | double | 
|---|
|  | 146 | SpectralResponse::logIntegratedSpect()  const | 
|---|
|  | 147 | { | 
|---|
|  | 148 | double value = this->logIntegratedSpect(_numin, _numax); | 
|---|
|  | 149 | return value; | 
|---|
|  | 150 | } | 
|---|
|  | 151 |  | 
|---|
|  | 152 |  | 
|---|
|  | 153 | void | 
|---|
|  | 154 | SpectralResponse::Print(ostream& os) const | 
|---|
|  | 155 | { | 
|---|
|  | 156 |  | 
|---|
|  | 157 | //   os << "SpectralResponse::Print (" << typeid(*this).name() | 
|---|
|  | 158 | //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl; | 
|---|
|  | 159 | os << "SpectralResponse::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl; | 
|---|
|  | 160 | os << "MeanFreq= " << meanFreq() << "  Transmission= " << transmission(meanFreq()) << endl; | 
|---|
|  | 161 | os << "PeakFreq= " << peakFreq() << "  Transmission= " << transmission(peakFreq()) << endl; | 
|---|
|  | 162 |  | 
|---|
|  | 163 | } | 
|---|