1 | //--------------------------------------------------------------------------
|
---|
2 | // File and Version Information:
|
---|
3 | // $Id: specresp.cc,v 1.5 2000-04-14 07:28:13 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 | //----------------
|
---|
36 | SpectralResponse::SpectralResponse(double numin, double numax)
|
---|
37 | {
|
---|
38 | _numin = numin;
|
---|
39 | _numax = numax;
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | //--------------
|
---|
44 | // Destructor --
|
---|
45 | //--------------
|
---|
46 | SpectralResponse::~SpectralResponse()
|
---|
47 | {
|
---|
48 | }
|
---|
49 |
|
---|
50 | // ---------------------------
|
---|
51 | // -- Function Definitions --
|
---|
52 | // ---------------------------
|
---|
53 |
|
---|
54 |
|
---|
55 | double
|
---|
56 | SpectralResponse::minFreq() const
|
---|
57 | {
|
---|
58 | return _numin;
|
---|
59 | }
|
---|
60 |
|
---|
61 | double
|
---|
62 | SpectralResponse::maxFreq() const
|
---|
63 | {
|
---|
64 | return _numax;
|
---|
65 | }
|
---|
66 |
|
---|
67 | double
|
---|
68 | SpectralResponse::meanFreq() const
|
---|
69 | {
|
---|
70 | return (_numax+_numin)/2.;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | // To change min-max frequency
|
---|
75 | void
|
---|
76 | SpectralResponse::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.
|
---|
85 | double
|
---|
86 | SpectralResponse::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 |
|
---|
104 | double
|
---|
105 | SpectralResponse::peakTransmission() const
|
---|
106 | {
|
---|
107 | double nuPeak = this->peakFreq();
|
---|
108 | return transmission(nuPeak);
|
---|
109 | }
|
---|
110 |
|
---|
111 | static SpectralResponse* _mySpecResp = NULL;
|
---|
112 |
|
---|
113 | static 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 | */
|
---|
125 | double
|
---|
126 | SpectralResponse::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 | */
|
---|
137 | double
|
---|
138 | SpectralResponse::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 |
|
---|
152 | static SpectralResponse* _myLogSpecResp = NULL;
|
---|
153 |
|
---|
154 | static 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 | */
|
---|
165 | double
|
---|
166 | SpectralResponse::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 | */
|
---|
186 | double
|
---|
187 | SpectralResponse::logIntegratedSpect() const
|
---|
188 | {
|
---|
189 | double value = this->logIntegratedSpect(_numin, _numax);
|
---|
190 | return value;
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | void
|
---|
195 | SpectralResponse::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 | }
|
---|