| [601] | 1 | //--------------------------------------------------------------------------
 | 
|---|
 | 2 | // File and Version Information:
 | 
|---|
| [668] | 3 | //      $Id: radspec.cc,v 1.3 1999-11-29 14:16:06 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 "machdefs.h"
 | 
|---|
 | 18 | #include <iostream.h>
 | 
|---|
 | 19 | #include <typeinfo>
 | 
|---|
 | 20 | #include <math.h>
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "radspec.h"
 | 
|---|
 | 23 | #include "integ.h"
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | //----------------
 | 
|---|
 | 26 | // Constructor --
 | 
|---|
 | 27 | //----------------
 | 
|---|
 | 28 | RadSpectra::RadSpectra(double numin, double numax)
 | 
|---|
 | 29 | {
 | 
|---|
 | 30 |   _numin = numin;
 | 
|---|
 | 31 |   _numax = numax;
 | 
|---|
 | 32 | }
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | //--------------
 | 
|---|
 | 36 | // Destructor --
 | 
|---|
 | 37 | //--------------
 | 
|---|
 | 38 | RadSpectra::~RadSpectra()
 | 
|---|
 | 39 | {
 | 
|---|
 | 40 | }
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | //              ---------------------------
 | 
|---|
 | 43 | //              --  Function Definitions --
 | 
|---|
 | 44 | //              ---------------------------
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | double 
 | 
|---|
 | 47 | RadSpectra::minFreq()  const
 | 
|---|
 | 48 | {
 | 
|---|
 | 49 |   return _numin;
 | 
|---|
 | 50 | }
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | double 
 | 
|---|
 | 53 | RadSpectra::maxFreq()  const
 | 
|---|
 | 54 | {
 | 
|---|
 | 55 |   return _numax;
 | 
|---|
 | 56 | }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | double 
 | 
|---|
 | 59 | RadSpectra::meanFreq()  const
 | 
|---|
 | 60 | {
 | 
|---|
 | 61 |   double result = (_numax+_numin)/2.;
 | 
|---|
 | 62 |   return result;
 | 
|---|
 | 63 | }
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | // peakFreq returns the value of the frequency for the
 | 
|---|
 | 68 | // peak of the spectrum. 
 | 
|---|
 | 69 | double 
 | 
|---|
 | 70 | RadSpectra::peakFreq()  const
 | 
|---|
 | 71 | {
 | 
|---|
 | 72 |   double maxAnswer = -1.e99;
 | 
|---|
 | 73 |   double maxNu = -10;
 | 
|---|
 | 74 |   double nu;
 | 
|---|
 | 75 |   for (int i=1; i<1000;i++)
 | 
|---|
 | 76 |     {
 | 
|---|
 | 77 |       nu=(_numax-_numin)*i/1000.+_numin;
 | 
|---|
 | 78 |       double lookForMax = flux(nu);
 | 
|---|
 | 79 |       if(maxAnswer <= lookForMax) {
 | 
|---|
 | 80 |         maxAnswer= lookForMax;
 | 
|---|
 | 81 |         maxNu    = nu;
 | 
|---|
 | 82 |       }
 | 
|---|
 | 83 |     }
 | 
|---|
 | 84 |   return maxNu;  
 | 
|---|
 | 85 | }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | // To change min-max frequency
 | 
|---|
 | 88 | void
 | 
|---|
 | 89 | RadSpectra::setMinMaxFreq(double numin, double numax)
 | 
|---|
 | 90 | {
 | 
|---|
 | 91 |   _numin = numin;
 | 
|---|
 | 92 |   _numax = numax;
 | 
|---|
 | 93 | }
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | // the RadSpectra_fluxFunction function is used to call TrpzInteg double(double) 
 | 
|---|
 | 96 | // (integration over a range of frequencies)
 | 
|---|
 | 97 | static RadSpectra* _raypourfinteg = NULL;
 | 
|---|
 | 98 | static double RadSpectra_fluxFunction(double nu)
 | 
|---|
 | 99 | {
 | 
|---|
 | 100 |    return(_raypourfinteg->flux(nu));   
 | 
|---|
 | 101 | }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | double 
 | 
|---|
 | 104 | RadSpectra::integratedFlux(double f1, double f2)  const
 | 
|---|
 | 105 | {
 | 
|---|
| [668] | 106 | //   cout << endl;
 | 
|---|
 | 107 | //   cout <<  this->minFreq() << " = " << this->maxFreq() << endl;
 | 
|---|
 | 108 | //   cout <<  f1 << " = " << f2 << endl;
 | 
|---|
 | 109 |   if(f1 < this->minFreq()) f1 = this->minFreq();
 | 
|---|
 | 110 |   if(f2 > this->maxFreq()) f2 = this->maxFreq();
 | 
|---|
 | 111 |   _raypourfinteg = const_cast<RadSpectra *>(this);
 | 
|---|
 | 112 |   TrpzInteg I(RadSpectra_fluxFunction , f1, f2);  
 | 
|---|
 | 113 |   double val = (double)I;
 | 
|---|
 | 114 |   _raypourfinteg = NULL;  // On ne peut pas faire ca avant la destruction de I
 | 
|---|
 | 115 |   return(val);        
 | 
|---|
| [601] | 116 | }
 | 
|---|
 | 117 | double 
 | 
|---|
 | 118 | RadSpectra::integratedFlux()  const
 | 
|---|
 | 119 | {
 | 
|---|
| [668] | 120 |   return integratedFlux(this->minFreq(),this->maxFreq());
 | 
|---|
| [601] | 121 | }
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | // integration using the logarithm !!
 | 
|---|
 | 124 | // Carefull!! Base 10....
 | 
|---|
 | 125 | static RadSpectra* _rayIntLog = NULL;
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 | static double RadSpectra_logFluxFunction(double tau)
 | 
|---|
 | 128 | {
 | 
|---|
 | 129 |   double value = _rayIntLog->flux(pow(10,tau))*pow(10,tau);
 | 
|---|
 | 130 |   return(value);   
 | 
|---|
 | 131 | }
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 | double 
 | 
|---|
 | 134 | RadSpectra::logIntegratedFlux(double f1, double f2)  const
 | 
|---|
 | 135 | {
 | 
|---|
| [668] | 136 |   if(f1 < this->minFreq()) f1 = this->minFreq();
 | 
|---|
 | 137 |   if(f2 > this->maxFreq()) f2 = this->maxFreq();
 | 
|---|
 | 138 | 
 | 
|---|
| [601] | 139 |   double f1Log = log10(f1);
 | 
|---|
 | 140 |   double f2Log = log10(f2);
 | 
|---|
 | 141 |   if(f1Log < -1.e99) f1Log = -1.e99;
 | 
|---|
 | 142 |   if(f2Log > 1.e99)  f2Log = 1.e99;
 | 
|---|
 | 143 |   _rayIntLog = const_cast<RadSpectra *>(this);
 | 
|---|
 | 144 |   TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log);
 | 
|---|
 | 145 |   double value = (double)I * log(10.);
 | 
|---|
 | 146 |   _rayIntLog = NULL;
 | 
|---|
 | 147 |   return(value);        
 | 
|---|
 | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | double 
 | 
|---|
 | 151 | RadSpectra::logIntegratedFlux()  const
 | 
|---|
 | 152 | {
 | 
|---|
 | 153 |   return logIntegratedFlux(_numin,_numax);
 | 
|---|
 | 154 | }
 | 
|---|
 | 155 | 
 | 
|---|
 | 156 | // the RadSpectra_filteredFlux function is used to call TrpzInteg double(double) 
 | 
|---|
 | 157 | // (integration over a range of frequencies with a filter)
 | 
|---|
 | 158 | static SpectralResponse* _filter = NULL ;
 | 
|---|
 | 159 | static double RadSpectra_filteredFlux(double nu) 
 | 
|---|
 | 160 | {
 | 
|---|
 | 161 |   double flux = _raypourfinteg->flux(nu);
 | 
|---|
 | 162 |   return(flux * _filter->transmission(nu));
 | 
|---|
 | 163 | }
 | 
|---|
 | 164 | 
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 | double 
 | 
|---|
 | 167 | RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter, double f1, double f2) const
 | 
|---|
 | 168 | {
 | 
|---|
 | 169 |   _raypourfinteg = const_cast<RadSpectra *>(this);
 | 
|---|
 | 170 |   _filter = const_cast<SpectralResponse *>(&filter);
 | 
|---|
| [668] | 171 |    if(f1 < this->minFreq()) f1 = this->minFreq();
 | 
|---|
 | 172 |    if(f2 > this->maxFreq()) f2 = this->maxFreq();
 | 
|---|
 | 173 | 
 | 
|---|
| [607] | 174 |   TrpzInteg I(RadSpectra_filteredFlux,f1,f2);
 | 
|---|
 | 175 |   double val = (double)I;
 | 
|---|
| [601] | 176 |   _raypourfinteg = NULL;
 | 
|---|
 | 177 |   _filter = NULL;
 | 
|---|
| [607] | 178 |   return(val);        
 | 
|---|
| [601] | 179 | }
 | 
|---|
 | 180 | 
 | 
|---|
 | 181 | double 
 | 
|---|
 | 182 | RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter)
 | 
|---|
 | 183 | {
 | 
|---|
 | 184 |   double minOfMin = filter.minFreq();
 | 
|---|
 | 185 |   double maxOfMax = filter.maxFreq();
 | 
|---|
 | 186 |   if(minOfMin < this->minFreq()) minOfMin = this->minFreq();
 | 
|---|
 | 187 |   if(maxOfMax > this->maxFreq()) maxOfMax = this->maxFreq();  
 | 
|---|
 | 188 |   return(filteredIntegratedFlux(filter, minOfMin, maxOfMax ) );
 | 
|---|
 | 189 | }
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 | 
 | 
|---|
 | 192 | // the RadSpectraVec_filteredFlux function is used to call TrpzInteg double(double) 
 | 
|---|
 | 193 | // (integration over a range of frequencies with a filter)
 | 
|---|
 | 194 | static double RadSpectra_logFilteredFlux(double tau) 
 | 
|---|
 | 195 | {
 | 
|---|
 | 196 |   double nu = pow(10,tau);
 | 
|---|
 | 197 |   double flux = _raypourfinteg->flux(nu)*nu;
 | 
|---|
| [668] | 198 |   double result = flux * _filter->transmission(nu);
 | 
|---|
 | 199 |   return(result);
 | 
|---|
| [601] | 200 | }
 | 
|---|
 | 201 | 
 | 
|---|
 | 202 | 
 | 
|---|
 | 203 | double 
 | 
|---|
 | 204 | RadSpectra::filteredLogIntFlux(SpectralResponse const& filter, double f1, double f2) const
 | 
|---|
 | 205 | {
 | 
|---|
 | 206 |   
 | 
|---|
 | 207 |    _raypourfinteg = NULL;
 | 
|---|
 | 208 |    _filter = NULL;
 | 
|---|
| [668] | 209 |    if(f1 < this->minFreq()) f1 = this->minFreq();
 | 
|---|
 | 210 |    if(f2 > this->maxFreq()) f2 = this->maxFreq();
 | 
|---|
 | 211 |    
 | 
|---|
| [601] | 212 |    double f1Log = log10(f1);
 | 
|---|
 | 213 |    double f2Log = log10(f2);
 | 
|---|
 | 214 |    if(f1Log < -1.e99) f1Log = -1.e99;
 | 
|---|
 | 215 |    if(f2Log > 1.e99)  f2Log = 1.e99;
 | 
|---|
 | 216 |    _raypourfinteg = const_cast<RadSpectra *>(this);
 | 
|---|
 | 217 |    _filter = const_cast<SpectralResponse *>(&filter);
 | 
|---|
 | 218 |    TrpzInteg I(RadSpectra_logFilteredFlux,f1Log,f2Log);  
 | 
|---|
| [607] | 219 |    double val = (double)I;
 | 
|---|
| [601] | 220 |    _raypourfinteg = NULL;
 | 
|---|
 | 221 |    _filter = NULL;
 | 
|---|
| [607] | 222 |    return(val* log(10.));        
 | 
|---|
| [601] | 223 | }
 | 
|---|
 | 224 | 
 | 
|---|
 | 225 | double 
 | 
|---|
 | 226 | RadSpectra::filteredLogIntFlux(SpectralResponse const& filter)
 | 
|---|
 | 227 | {
 | 
|---|
 | 228 |   return(filteredLogIntFlux(filter, filter.minFreq(), filter.maxFreq() ) );
 | 
|---|
 | 229 | }
 | 
|---|
 | 230 | 
 | 
|---|
 | 231 | 
 | 
|---|
 | 232 | 
 | 
|---|
| [668] | 233 | 
 | 
|---|
| [601] | 234 | void
 | 
|---|
 | 235 | RadSpectra::Print(ostream& os) const
 | 
|---|
 | 236 | {
 | 
|---|
 | 237 |   //  os << "RadSpectra::Print (" << typeid(*this).name() 
 | 
|---|
 | 238 |   //     << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
 | 
|---|
 | 239 |   os << "RadSpectra::Print  - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
 | 
|---|
 | 240 |   os << "MeanFreq= " << meanFreq() << "  Emission= " << flux(meanFreq()) << endl;
 | 
|---|
 | 241 |   os << "PeakFreq= " << peakFreq() << "  Emission= " << flux(peakFreq()) << endl;
 | 
|---|
 | 242 | 
 | 
|---|
 | 243 | }
 | 
|---|
 | 244 | 
 | 
|---|
 | 245 | 
 | 
|---|