[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[607] | 3 | // $Id: radspec.cc,v 1.2 1999-11-20 21:00:50 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 | {
|
---|
| 106 | _raypourfinteg = const_cast<RadSpectra *>(this);
|
---|
| 107 | TrpzInteg I(RadSpectra_fluxFunction , f1, f2);
|
---|
[607] | 108 | double val = (double)I;
|
---|
| 109 | _raypourfinteg = NULL; // On ne peut pas faire ca avant la destruction de I
|
---|
| 110 | return(val);
|
---|
[601] | 111 | }
|
---|
| 112 | double
|
---|
| 113 | RadSpectra::integratedFlux() const
|
---|
| 114 | {
|
---|
| 115 | return integratedFlux(_numin, _numax);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | // integration using the logarithm !!
|
---|
| 119 | // Carefull!! Base 10....
|
---|
| 120 | static RadSpectra* _rayIntLog = NULL;
|
---|
| 121 |
|
---|
| 122 | static double RadSpectra_logFluxFunction(double tau)
|
---|
| 123 | {
|
---|
| 124 | double value = _rayIntLog->flux(pow(10,tau))*pow(10,tau);
|
---|
| 125 | return(value);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | double
|
---|
| 129 | RadSpectra::logIntegratedFlux(double f1, double f2) const
|
---|
| 130 | {
|
---|
| 131 | double f1Log = log10(f1);
|
---|
| 132 | double f2Log = log10(f2);
|
---|
| 133 | if(f1Log < -1.e99) f1Log = -1.e99;
|
---|
| 134 | if(f2Log > 1.e99) f2Log = 1.e99;
|
---|
| 135 | _rayIntLog = const_cast<RadSpectra *>(this);
|
---|
| 136 | TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log);
|
---|
| 137 | double value = (double)I * log(10.);
|
---|
| 138 | _rayIntLog = NULL;
|
---|
| 139 | return(value);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | double
|
---|
| 143 | RadSpectra::logIntegratedFlux() const
|
---|
| 144 | {
|
---|
| 145 | return logIntegratedFlux(_numin,_numax);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | // the RadSpectra_filteredFlux function is used to call TrpzInteg double(double)
|
---|
| 149 | // (integration over a range of frequencies with a filter)
|
---|
| 150 | static SpectralResponse* _filter = NULL ;
|
---|
| 151 | static double RadSpectra_filteredFlux(double nu)
|
---|
| 152 | {
|
---|
| 153 | double flux = _raypourfinteg->flux(nu);
|
---|
| 154 | return(flux * _filter->transmission(nu));
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | double
|
---|
| 159 | RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter, double f1, double f2) const
|
---|
| 160 | {
|
---|
| 161 | _raypourfinteg = const_cast<RadSpectra *>(this);
|
---|
| 162 | _filter = const_cast<SpectralResponse *>(&filter);
|
---|
[607] | 163 | TrpzInteg I(RadSpectra_filteredFlux,f1,f2);
|
---|
| 164 | double val = (double)I;
|
---|
[601] | 165 | _raypourfinteg = NULL;
|
---|
| 166 | _filter = NULL;
|
---|
[607] | 167 | return(val);
|
---|
[601] | 168 | }
|
---|
| 169 |
|
---|
| 170 | double
|
---|
| 171 | RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter)
|
---|
| 172 | {
|
---|
| 173 | double minOfMin = filter.minFreq();
|
---|
| 174 | double maxOfMax = filter.maxFreq();
|
---|
| 175 | if(minOfMin < this->minFreq()) minOfMin = this->minFreq();
|
---|
| 176 | if(maxOfMax > this->maxFreq()) maxOfMax = this->maxFreq();
|
---|
| 177 | return(filteredIntegratedFlux(filter, minOfMin, maxOfMax ) );
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | // the RadSpectraVec_filteredFlux function is used to call TrpzInteg double(double)
|
---|
| 182 | // (integration over a range of frequencies with a filter)
|
---|
| 183 | static double RadSpectra_logFilteredFlux(double tau)
|
---|
| 184 | {
|
---|
| 185 | double nu = pow(10,tau);
|
---|
| 186 | double flux = _raypourfinteg->flux(nu)*nu;
|
---|
| 187 | return(flux * _filter->transmission(nu));
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | double
|
---|
| 192 | RadSpectra::filteredLogIntFlux(SpectralResponse const& filter, double f1, double f2) const
|
---|
| 193 | {
|
---|
| 194 |
|
---|
| 195 | // double f1Log = log10(f1);
|
---|
| 196 | // double f2Log = log10(f2);
|
---|
| 197 | // if(f1Log < -1.e99) f1Log = -1.e99;
|
---|
| 198 | // if(f2Log > 1.e99) f2Log = 1.e99;
|
---|
| 199 | // _rayIntLog = const_cast<RadSpectra *>(this);
|
---|
| 200 | // TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log);
|
---|
| 201 | // double value = (double)I * log(10.);
|
---|
| 202 | // return(value);
|
---|
| 203 | // _rayIntLog = NULL;
|
---|
| 204 |
|
---|
| 205 | _raypourfinteg = NULL;
|
---|
| 206 | _filter = NULL;
|
---|
| 207 | double f1Log = log10(f1);
|
---|
| 208 | double f2Log = log10(f2);
|
---|
| 209 | if(f1Log < -1.e99) f1Log = -1.e99;
|
---|
| 210 | if(f2Log > 1.e99) f2Log = 1.e99;
|
---|
| 211 | _raypourfinteg = const_cast<RadSpectra *>(this);
|
---|
| 212 | _filter = const_cast<SpectralResponse *>(&filter);
|
---|
| 213 | TrpzInteg I(RadSpectra_logFilteredFlux,f1Log,f2Log);
|
---|
[607] | 214 | double val = (double)I;
|
---|
[601] | 215 | _raypourfinteg = NULL;
|
---|
| 216 | _filter = NULL;
|
---|
[607] | 217 | return(val* log(10.));
|
---|
[601] | 218 | }
|
---|
| 219 |
|
---|
| 220 | double
|
---|
| 221 | RadSpectra::filteredLogIntFlux(SpectralResponse const& filter)
|
---|
| 222 | {
|
---|
| 223 | return(filteredLogIntFlux(filter, filter.minFreq(), filter.maxFreq() ) );
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | void
|
---|
| 229 | RadSpectra::Print(ostream& os) const
|
---|
| 230 | {
|
---|
| 231 | // os << "RadSpectra::Print (" << typeid(*this).name()
|
---|
| 232 | // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 233 | os << "RadSpectra::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 234 | os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
|
---|
| 235 | os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
|
---|
| 236 |
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 |
|
---|