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