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