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