source: Sophya/trunk/SophyaLib/SkyT/radspec.cc@ 601

Last change on this file since 601 was 601, checked in by ansari, 26 years ago

Creation module SkyT (provisoire) - Outils pour simulation du ciel

Reza 19/11/99

File size: 5.7 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: radspec.cc,v 1.1.1.1 1999-11-19 16:34:32 ansari 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 "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//----------------
28RadSpectra::RadSpectra(double numin, double numax)
29{
30 _numin = numin;
31 _numax = numax;
32}
33
34
35//--------------
36// Destructor --
37//--------------
38RadSpectra::~RadSpectra()
39{
40}
41
42// ---------------------------
43// -- Function Definitions --
44// ---------------------------
45
46double
47RadSpectra::minFreq() const
48{
49 return _numin;
50}
51
52double
53RadSpectra::maxFreq() const
54{
55 return _numax;
56}
57
58double
59RadSpectra::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.
69double
70RadSpectra::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
88void
89RadSpectra::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)
97static RadSpectra* _raypourfinteg = NULL;
98static double RadSpectra_fluxFunction(double nu)
99{
100 return(_raypourfinteg->flux(nu));
101}
102
103double
104RadSpectra::integratedFlux(double f1, double f2) const
105{
106 _raypourfinteg = const_cast<RadSpectra *>(this);
107 TrpzInteg I(RadSpectra_fluxFunction , f1, f2);
108 _raypourfinteg = NULL;
109 return((double)I);
110}
111double
112RadSpectra::integratedFlux() const
113{
114 return integratedFlux(_numin, _numax);
115}
116
117// integration using the logarithm !!
118// Carefull!! Base 10....
119static RadSpectra* _rayIntLog = NULL;
120
121static double RadSpectra_logFluxFunction(double tau)
122{
123 double value = _rayIntLog->flux(pow(10,tau))*pow(10,tau);
124 return(value);
125}
126
127double
128RadSpectra::logIntegratedFlux(double f1, double f2) const
129{
130 double f1Log = log10(f1);
131 double f2Log = log10(f2);
132 if(f1Log < -1.e99) f1Log = -1.e99;
133 if(f2Log > 1.e99) f2Log = 1.e99;
134 _rayIntLog = const_cast<RadSpectra *>(this);
135 TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log);
136 double value = (double)I * log(10.);
137 _rayIntLog = NULL;
138 return(value);
139}
140
141double
142RadSpectra::logIntegratedFlux() const
143{
144 return logIntegratedFlux(_numin,_numax);
145}
146
147// the RadSpectra_filteredFlux function is used to call TrpzInteg double(double)
148// (integration over a range of frequencies with a filter)
149static SpectralResponse* _filter = NULL ;
150static double RadSpectra_filteredFlux(double nu)
151{
152 double flux = _raypourfinteg->flux(nu);
153 return(flux * _filter->transmission(nu));
154}
155
156
157double
158RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter, double f1, double f2) const
159{
160 _raypourfinteg = const_cast<RadSpectra *>(this);
161 _filter = const_cast<SpectralResponse *>(&filter);
162 TrpzInteg I(RadSpectra_filteredFlux,f1,f2);
163 _raypourfinteg = NULL;
164 _filter = NULL;
165 return((double)I);
166}
167
168double
169RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter)
170{
171 double minOfMin = filter.minFreq();
172 double maxOfMax = filter.maxFreq();
173 if(minOfMin < this->minFreq()) minOfMin = this->minFreq();
174 if(maxOfMax > this->maxFreq()) maxOfMax = this->maxFreq();
175 return(filteredIntegratedFlux(filter, minOfMin, maxOfMax ) );
176}
177
178
179// the RadSpectraVec_filteredFlux function is used to call TrpzInteg double(double)
180// (integration over a range of frequencies with a filter)
181static double RadSpectra_logFilteredFlux(double tau)
182{
183 double nu = pow(10,tau);
184 double flux = _raypourfinteg->flux(nu)*nu;
185 return(flux * _filter->transmission(nu));
186}
187
188
189double
190RadSpectra::filteredLogIntFlux(SpectralResponse const& filter, double f1, double f2) const
191{
192
193// double f1Log = log10(f1);
194// double f2Log = log10(f2);
195// if(f1Log < -1.e99) f1Log = -1.e99;
196// if(f2Log > 1.e99) f2Log = 1.e99;
197// _rayIntLog = const_cast<RadSpectra *>(this);
198// TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log);
199// double value = (double)I * log(10.);
200// return(value);
201// _rayIntLog = NULL;
202
203 _raypourfinteg = NULL;
204 _filter = NULL;
205 double f1Log = log10(f1);
206 double f2Log = log10(f2);
207 if(f1Log < -1.e99) f1Log = -1.e99;
208 if(f2Log > 1.e99) f2Log = 1.e99;
209 _raypourfinteg = const_cast<RadSpectra *>(this);
210 _filter = const_cast<SpectralResponse *>(&filter);
211 TrpzInteg I(RadSpectra_logFilteredFlux,f1Log,f2Log);
212 _raypourfinteg = NULL;
213 _filter = NULL;
214 return((double)I* log(10.));
215}
216
217double
218RadSpectra::filteredLogIntFlux(SpectralResponse const& filter)
219{
220 return(filteredLogIntFlux(filter, filter.minFreq(), filter.maxFreq() ) );
221}
222
223
224
225void
226RadSpectra::Print(ostream& os) const
227{
228 // os << "RadSpectra::Print (" << typeid(*this).name()
229 // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
230 os << "RadSpectra::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
231 os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
232 os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
233
234}
235
236
Note: See TracBrowser for help on using the repository browser.