source: Sophya/trunk/SophyaLib/SkyT/specresp.cc@ 2327

Last change on this file since 2327 was 2144, checked in by ansari, 23 years ago

Correction appels ambigus a pow() ds fichiers (pow(10,x) ---> pow(10.,x) , copies depuis base cvs ESTEC modifie par M. Reinecke, 31/7/2002

File size: 4.8 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: specresp.cc,v 1.6 2002-07-31 10:25:34 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 <typeinfo>
18#include <math.h>
19#include "specresp.h"
20#include "integ.h"
21#include "tvector.h"
22
23/*!
24 * \class SOPHYA::SpectralResponse
25 \ingroup SkyT
26 SpectralResponse corresponds to a detector filter's
27 response as a function of the frequency.
28 The SpectralResponse class is an abstract class.
29 The virtual constructor takes as arguments the
30 minimum and maximum values of the frequency range on
31 which the detector response is defined
32 */
33//----------------
34// Constructor --
35//----------------
36SpectralResponse::SpectralResponse(double numin, double numax)
37{
38 _numin = numin;
39 _numax = numax;
40}
41
42
43//--------------
44// Destructor --
45//--------------
46SpectralResponse::~SpectralResponse()
47{
48}
49
50// ---------------------------
51// -- Function Definitions --
52// ---------------------------
53
54
55double
56SpectralResponse::minFreq() const
57{
58 return _numin;
59}
60
61double
62SpectralResponse::maxFreq() const
63{
64 return _numax;
65}
66
67double
68SpectralResponse::meanFreq() const
69{
70 return (_numax+_numin)/2.;
71}
72
73
74// To change min-max frequency
75void
76SpectralResponse::setMinMaxFreq(double numin, double numax)
77{
78 _numin = numin;
79 _numax = numax;
80}
81
82
83// peakFreq returns the value of the frequency for the
84// peak of the spectrum.
85double
86SpectralResponse::peakFreq() const
87{
88 double maxAnswer = -1.e99;
89 double maxNu = -10;
90 double nu;
91 for (int i=1; i<1000;i++)
92 {
93 nu=(_numax-_numin)*i/1000.+_numin;
94 double lookForMax =transmission(nu);
95 if(maxAnswer <= lookForMax) {
96 maxAnswer= lookForMax;
97 maxNu = nu;
98 }
99 }
100 return maxNu;
101}
102
103
104double
105SpectralResponse::peakTransmission() const
106{
107 double nuPeak = this->peakFreq();
108 return transmission(nuPeak);
109}
110
111static SpectralResponse* _mySpecResp = NULL;
112
113static double SpectralResponse_transmission(double nu)
114{
115 return(_mySpecResp->transmission(nu));
116}
117
118
119/*!
120 This function performs the integration
121 of the transmission function in its frequency range
122 (defined when instanciating an object of on of the
123 subclasses)
124*/
125double
126SpectralResponse::IntegratedSpect() const
127{
128 double value = this->IntegratedSpect(_numin, _numax);
129 return value;
130}
131
132/*!
133 The IntegratedSpect function performs the integration
134 of the transmission function in a frequency range <BR> defined by
135 numin and numax.
136*/
137double
138SpectralResponse::IntegratedSpect(double numin, double numax) const
139{
140 if(numin < this->minFreq()) numin = this->minFreq();
141 if(numax > this->maxFreq()) numax = this->maxFreq();
142
143
144 _mySpecResp = const_cast<SpectralResponse *>(this);
145 TrpzInteg I(SpectralResponse_transmission , numin, numax);
146 double val = (double)I;
147 _mySpecResp= NULL;
148 return(val);
149}
150
151
152static SpectralResponse* _myLogSpecResp = NULL;
153
154static double SpectralResponse_logTransmission(double tau)
155{
156 double value = _myLogSpecResp->transmission(pow(10.,tau))*pow(10.,tau);
157 return(value);
158}
159
160/*!
161 The logIntegratedSpect function performs the integration
162 of the logarithm of the transmission function in a frequency range <BR> defined by
163 numin and numax.
164*/
165double
166SpectralResponse::logIntegratedSpect(double numin, double numax) const
167{
168 if(numin <= this->minFreq()) numin = this->minFreq();
169 if(numax >= this->maxFreq()) numax = this->maxFreq();
170 if(numin == 0) numin = 1.e-99;
171 double f1Log = log10(numin);
172 double f2Log = log10(numax);
173 if(f1Log < -1.e99) f1Log = -1.e99;
174 if(f2Log > 1.e99) f2Log = 1.e99;
175 _myLogSpecResp = const_cast<SpectralResponse *>(this);
176 TrpzInteg I(SpectralResponse_logTransmission ,f1Log,f2Log);
177 double val = (double)I;
178 _myLogSpecResp= NULL;
179 return(val*log(10.));
180}
181
182/*!
183 Same than IntegratedSpect(numin,numax) over its
184 frequency range defined at the initialisation
185*/
186double
187SpectralResponse::logIntegratedSpect() const
188{
189 double value = this->logIntegratedSpect(_numin, _numax);
190 return value;
191}
192
193
194void
195SpectralResponse::Print(ostream& os) const
196{
197
198 // os << "SpectralResponse::Print (" << typeid(*this).name()
199 //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
200 os << "SpectralResponse::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
201 os << "MeanFreq= " << meanFreq() << " Transmission= " << transmission(meanFreq()) << endl;
202 os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
203
204}
Note: See TracBrowser for help on using the repository browser.