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

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

Modifs preparatoire pour Garching MAP , Reza 20/11/99

File size: 5.8 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: radspec.cc,v 1.2 1999-11-20 21:00:50 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 double val = (double)I;
109 _raypourfinteg = NULL; // On ne peut pas faire ca avant la destruction de I
110 return(val);
111}
112double
113RadSpectra::integratedFlux() const
114{
115 return integratedFlux(_numin, _numax);
116}
117
118// integration using the logarithm !!
119// Carefull!! Base 10....
120static RadSpectra* _rayIntLog = NULL;
121
122static double RadSpectra_logFluxFunction(double tau)
123{
124 double value = _rayIntLog->flux(pow(10,tau))*pow(10,tau);
125 return(value);
126}
127
128double
129RadSpectra::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
142double
143RadSpectra::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)
150static SpectralResponse* _filter = NULL ;
151static double RadSpectra_filteredFlux(double nu)
152{
153 double flux = _raypourfinteg->flux(nu);
154 return(flux * _filter->transmission(nu));
155}
156
157
158double
159RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter, double f1, double f2) const
160{
161 _raypourfinteg = const_cast<RadSpectra *>(this);
162 _filter = const_cast<SpectralResponse *>(&filter);
163 TrpzInteg I(RadSpectra_filteredFlux,f1,f2);
164 double val = (double)I;
165 _raypourfinteg = NULL;
166 _filter = NULL;
167 return(val);
168}
169
170double
171RadSpectra::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)
183static 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
191double
192RadSpectra::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);
214 double val = (double)I;
215 _raypourfinteg = NULL;
216 _filter = NULL;
217 return(val* log(10.));
218}
219
220double
221RadSpectra::filteredLogIntFlux(SpectralResponse const& filter)
222{
223 return(filteredLogIntFlux(filter, filter.minFreq(), filter.maxFreq() ) );
224}
225
226
227
228void
229RadSpectra::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
Note: See TracBrowser for help on using the repository browser.