[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[927] | 3 | // $Id: radspec.cc,v 1.5 2000-04-14 07:28:13 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"
|
---|
[927] | 24 | /*!
|
---|
| 25 | \defgroup SkyT SkyT module
|
---|
| 26 | This module contains classes and functions which define
|
---|
| 27 | several radiation spectra and filter responses
|
---|
| 28 | */
|
---|
[601] | 29 |
|
---|
[909] | 30 | /*!
|
---|
[927] | 31 | * \class SOPHYA::RadSpectra
|
---|
| 32 | * \ingroup SkyT
|
---|
[909] | 33 | * This class is an abstract base class for radiation emission spectra. The flux() function returns the value of the flux (the spectral <BR>
|
---|
| 34 | * energy distribution) as a function of the frequency. As in the SpectralResponse class, the () operator has been redefined <BR>
|
---|
| 35 | * at this level, so that the user can access the flux value, either by calling the function or directly by using this operator. <BR>
|
---|
| 36 | * For all the sub-classes, \nu is given in units of Hz and
|
---|
| 37 | * the flux is returned in units of W/m^2/sr/Hz.
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 |
|
---|
[601] | 41 | //----------------
|
---|
| 42 | // Constructor --
|
---|
| 43 | //----------------
|
---|
[909] | 44 | /*! Default constructor */
|
---|
| 45 | /*!
|
---|
| 46 | The constructor takes as an argument the minimum
|
---|
| 47 | and the maximum frequency of the spectrum, if any. <BR>
|
---|
| 48 | In the case the user does not want to specify these
|
---|
| 49 | values, there are set respectively to 0. and 9.E49
|
---|
| 50 | by default.
|
---|
| 51 | */
|
---|
[601] | 52 | RadSpectra::RadSpectra(double numin, double numax)
|
---|
| 53 | {
|
---|
| 54 | _numin = numin;
|
---|
| 55 | _numax = numax;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | //--------------
|
---|
| 60 | // Destructor --
|
---|
| 61 | //--------------
|
---|
| 62 | RadSpectra::~RadSpectra()
|
---|
| 63 | {
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | // ---------------------------
|
---|
| 67 | // -- Function Definitions --
|
---|
| 68 | // ---------------------------
|
---|
| 69 |
|
---|
| 70 | double
|
---|
| 71 | RadSpectra::minFreq() const
|
---|
| 72 | {
|
---|
| 73 | return _numin;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | double
|
---|
| 77 | RadSpectra::maxFreq() const
|
---|
| 78 | {
|
---|
| 79 | return _numax;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | double
|
---|
| 83 | RadSpectra::meanFreq() const
|
---|
| 84 | {
|
---|
| 85 | double result = (_numax+_numin)/2.;
|
---|
| 86 | return result;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
[909] | 90 | /*
|
---|
| 91 | The peakFreq() function returns the value of the
|
---|
| 92 | frequency for the maximum value of the flux
|
---|
| 93 | */
|
---|
[601] | 94 | double
|
---|
| 95 | RadSpectra::peakFreq() const
|
---|
| 96 | {
|
---|
| 97 | double maxAnswer = -1.e99;
|
---|
| 98 | double maxNu = -10;
|
---|
| 99 | double nu;
|
---|
| 100 | for (int i=1; i<1000;i++)
|
---|
| 101 | {
|
---|
| 102 | nu=(_numax-_numin)*i/1000.+_numin;
|
---|
| 103 | double lookForMax = flux(nu);
|
---|
| 104 | if(maxAnswer <= lookForMax) {
|
---|
| 105 | maxAnswer= lookForMax;
|
---|
| 106 | maxNu = nu;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | return maxNu;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | void
|
---|
| 113 | RadSpectra::setMinMaxFreq(double numin, double numax)
|
---|
| 114 | {
|
---|
| 115 | _numin = numin;
|
---|
| 116 | _numax = numax;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // the RadSpectra_fluxFunction function is used to call TrpzInteg double(double)
|
---|
| 120 | // (integration over a range of frequencies)
|
---|
| 121 | static RadSpectra* _raypourfinteg = NULL;
|
---|
| 122 | static double RadSpectra_fluxFunction(double nu)
|
---|
| 123 | {
|
---|
| 124 | return(_raypourfinteg->flux(nu));
|
---|
| 125 | }
|
---|
[909] | 126 | /*!
|
---|
| 127 | The integratedFlux() function performs the integration
|
---|
| 128 | of the flux function in a frequency range <BR> defined by
|
---|
| 129 | f1 and f2.
|
---|
| 130 | */
|
---|
[601] | 131 | double
|
---|
| 132 | RadSpectra::integratedFlux(double f1, double f2) const
|
---|
| 133 | {
|
---|
[668] | 134 | if(f1 < this->minFreq()) f1 = this->minFreq();
|
---|
| 135 | if(f2 > this->maxFreq()) f2 = this->maxFreq();
|
---|
| 136 | _raypourfinteg = const_cast<RadSpectra *>(this);
|
---|
| 137 | TrpzInteg I(RadSpectra_fluxFunction , f1, f2);
|
---|
| 138 | double val = (double)I;
|
---|
| 139 | _raypourfinteg = NULL; // On ne peut pas faire ca avant la destruction de I
|
---|
| 140 | return(val);
|
---|
[601] | 141 | }
|
---|
[909] | 142 |
|
---|
| 143 | /*!
|
---|
| 144 | Same than integratedFlux() over the frequency range
|
---|
| 145 | of definition of the flux function
|
---|
| 146 | */
|
---|
[601] | 147 | double
|
---|
| 148 | RadSpectra::integratedFlux() const
|
---|
| 149 | {
|
---|
[668] | 150 | return integratedFlux(this->minFreq(),this->maxFreq());
|
---|
[601] | 151 | }
|
---|
| 152 |
|
---|
| 153 | // integration using the logarithm !!
|
---|
| 154 | // Carefull!! Base 10....
|
---|
| 155 | static RadSpectra* _rayIntLog = NULL;
|
---|
| 156 |
|
---|
| 157 | static double RadSpectra_logFluxFunction(double tau)
|
---|
| 158 | {
|
---|
| 159 | double value = _rayIntLog->flux(pow(10,tau))*pow(10,tau);
|
---|
| 160 | return(value);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[909] | 163 | /*!
|
---|
| 164 | The logIntegratedFlux() function performs the integration
|
---|
| 165 | of the flux function in a frequency range <BR> defined by
|
---|
| 166 | f1 and f2. The integration is here performed
|
---|
| 167 | on the logarithm of the flux function.
|
---|
| 168 | */
|
---|
[601] | 169 | double
|
---|
| 170 | RadSpectra::logIntegratedFlux(double f1, double f2) const
|
---|
| 171 | {
|
---|
[668] | 172 | if(f1 < this->minFreq()) f1 = this->minFreq();
|
---|
| 173 | if(f2 > this->maxFreq()) f2 = this->maxFreq();
|
---|
| 174 |
|
---|
[601] | 175 | double f1Log = log10(f1);
|
---|
| 176 | double f2Log = log10(f2);
|
---|
| 177 | if(f1Log < -1.e99) f1Log = -1.e99;
|
---|
| 178 | if(f2Log > 1.e99) f2Log = 1.e99;
|
---|
| 179 | _rayIntLog = const_cast<RadSpectra *>(this);
|
---|
| 180 | TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log);
|
---|
| 181 | double value = (double)I * log(10.);
|
---|
| 182 | _rayIntLog = NULL;
|
---|
| 183 | return(value);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[909] | 186 | /*!
|
---|
| 187 | same than logIntegratedFlux over the frequency range
|
---|
| 188 | of definition of the flux function
|
---|
| 189 | */
|
---|
[601] | 190 | double
|
---|
| 191 | RadSpectra::logIntegratedFlux() const
|
---|
| 192 | {
|
---|
| 193 | return logIntegratedFlux(_numin,_numax);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | // the RadSpectra_filteredFlux function is used to call TrpzInteg double(double)
|
---|
| 197 | // (integration over a range of frequencies with a filter)
|
---|
| 198 | static SpectralResponse* _filter = NULL ;
|
---|
| 199 | static double RadSpectra_filteredFlux(double nu)
|
---|
| 200 | {
|
---|
| 201 | double flux = _raypourfinteg->flux(nu);
|
---|
| 202 | return(flux * _filter->transmission(nu));
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[909] | 205 | /*!
|
---|
| 206 | The filteredIntegratedFlux() function performs the integration
|
---|
| 207 | of the flux function in a frequency range <BR> defined by
|
---|
| 208 | f1 and f2 convolved by a SpectralResponse filter.
|
---|
| 209 | */
|
---|
[601] | 210 | double
|
---|
| 211 | RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter, double f1, double f2) const
|
---|
| 212 | {
|
---|
| 213 | _raypourfinteg = const_cast<RadSpectra *>(this);
|
---|
| 214 | _filter = const_cast<SpectralResponse *>(&filter);
|
---|
[668] | 215 | if(f1 < this->minFreq()) f1 = this->minFreq();
|
---|
| 216 | if(f2 > this->maxFreq()) f2 = this->maxFreq();
|
---|
| 217 |
|
---|
[607] | 218 | TrpzInteg I(RadSpectra_filteredFlux,f1,f2);
|
---|
| 219 | double val = (double)I;
|
---|
[601] | 220 | _raypourfinteg = NULL;
|
---|
| 221 | _filter = NULL;
|
---|
[607] | 222 | return(val);
|
---|
[601] | 223 | }
|
---|
| 224 |
|
---|
[909] | 225 | /*!
|
---|
| 226 | Same than filteredIntegratedFlux() over the frequency range
|
---|
| 227 | defined as: <BR>
|
---|
| 228 | min_freq = MAX(minfreq_flux, minfreq_filter), <BR>
|
---|
| 229 | max_freq = MIN(maxfreq_flux, maxfreq_filter), <BR>
|
---|
| 230 | where:
|
---|
| 231 | <UL>
|
---|
| 232 | <LI> minfreq_flux is the minimum frequency of the flux definition
|
---|
| 233 | <LI> maxfreq_flux is the maximum frequency of the flux definition
|
---|
| 234 | <LI> minfreq_filter is the minimum frequency of the filter definition
|
---|
| 235 | <LI> maxfreq_filter is the maximum frequency of the filter definition
|
---|
| 236 | </UL>
|
---|
| 237 | */
|
---|
[601] | 238 | double
|
---|
| 239 | RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter)
|
---|
| 240 | {
|
---|
| 241 | double minOfMin = filter.minFreq();
|
---|
| 242 | double maxOfMax = filter.maxFreq();
|
---|
| 243 | if(minOfMin < this->minFreq()) minOfMin = this->minFreq();
|
---|
| 244 | if(maxOfMax > this->maxFreq()) maxOfMax = this->maxFreq();
|
---|
| 245 | return(filteredIntegratedFlux(filter, minOfMin, maxOfMax ) );
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 | // the RadSpectraVec_filteredFlux function is used to call TrpzInteg double(double)
|
---|
| 250 | // (integration over a range of frequencies with a filter)
|
---|
| 251 | static double RadSpectra_logFilteredFlux(double tau)
|
---|
| 252 | {
|
---|
| 253 | double nu = pow(10,tau);
|
---|
| 254 | double flux = _raypourfinteg->flux(nu)*nu;
|
---|
[668] | 255 | double result = flux * _filter->transmission(nu);
|
---|
| 256 | return(result);
|
---|
[601] | 257 | }
|
---|
| 258 |
|
---|
| 259 |
|
---|
[909] | 260 | /*!
|
---|
| 261 | * The filteredIntegratedFlux() function performs the integration
|
---|
| 262 | * of the flux function in a frequency range <BR> defined by
|
---|
| 263 | * f1 and f2 convolved by a SpectralResponse filter (using the
|
---|
| 264 | * logarithm of the function).
|
---|
| 265 | */
|
---|
[601] | 266 | double
|
---|
| 267 | RadSpectra::filteredLogIntFlux(SpectralResponse const& filter, double f1, double f2) const
|
---|
| 268 | {
|
---|
| 269 |
|
---|
| 270 | _raypourfinteg = NULL;
|
---|
| 271 | _filter = NULL;
|
---|
[668] | 272 | if(f1 < this->minFreq()) f1 = this->minFreq();
|
---|
| 273 | if(f2 > this->maxFreq()) f2 = this->maxFreq();
|
---|
| 274 |
|
---|
[601] | 275 | double f1Log = log10(f1);
|
---|
| 276 | double f2Log = log10(f2);
|
---|
| 277 | if(f1Log < -1.e99) f1Log = -1.e99;
|
---|
| 278 | if(f2Log > 1.e99) f2Log = 1.e99;
|
---|
| 279 | _raypourfinteg = const_cast<RadSpectra *>(this);
|
---|
| 280 | _filter = const_cast<SpectralResponse *>(&filter);
|
---|
| 281 | TrpzInteg I(RadSpectra_logFilteredFlux,f1Log,f2Log);
|
---|
[607] | 282 | double val = (double)I;
|
---|
[601] | 283 | _raypourfinteg = NULL;
|
---|
| 284 | _filter = NULL;
|
---|
[607] | 285 | return(val* log(10.));
|
---|
[601] | 286 | }
|
---|
| 287 |
|
---|
| 288 | double
|
---|
| 289 | RadSpectra::filteredLogIntFlux(SpectralResponse const& filter)
|
---|
| 290 | {
|
---|
| 291 | return(filteredLogIntFlux(filter, filter.minFreq(), filter.maxFreq() ) );
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 |
|
---|
[668] | 296 |
|
---|
[601] | 297 | void
|
---|
| 298 | RadSpectra::Print(ostream& os) const
|
---|
| 299 | {
|
---|
| 300 | // os << "RadSpectra::Print (" << typeid(*this).name()
|
---|
| 301 | // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 302 | os << "RadSpectra::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 303 | os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
|
---|
| 304 | os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
|
---|
| 305 |
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 |
|
---|