1 | //--------------------------------------------------------------------------
|
---|
2 | // File and Version Information:
|
---|
3 | // $Id: specrespvector.cc,v 1.13 2007-04-27 16:17:01 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>
|
---|
19 | #include <math.h>
|
---|
20 | // #include <typeinfo>
|
---|
21 |
|
---|
22 | #include "specrespvector.h"
|
---|
23 | #include "pexceptions.h"
|
---|
24 | #include "fioarr.h"
|
---|
25 |
|
---|
26 | namespace SOPHYA {
|
---|
27 |
|
---|
28 | //----------------
|
---|
29 | // Constructor --
|
---|
30 | //----------------
|
---|
31 | /*!
|
---|
32 | * \class SpecRespVec
|
---|
33 | \ingroup SkyT
|
---|
34 | One may also want to defined the filter of a detector by two vectors:
|
---|
35 | one for the frequencies and one for the corresponding transmission values.
|
---|
36 | In this case on should use the SpecRespVec class !
|
---|
37 | */
|
---|
38 | SpecRespVec::SpecRespVec()
|
---|
39 | : SpectralResponse()
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | /*! Constructor:
|
---|
44 | \param nu vector of the frequencies
|
---|
45 | \param fdenu vector of the corresponding transmission values of the filter
|
---|
46 | */
|
---|
47 | SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
---|
48 | : SpectralResponse(numin, numax)
|
---|
49 | {
|
---|
50 | if(nu.NElts() != fdenu.NElts())
|
---|
51 | throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
|
---|
52 | _vecOfNu = nu;
|
---|
53 | _vecOfFDeNu = fdenu;
|
---|
54 | _size = nu.NElts();
|
---|
55 | }
|
---|
56 |
|
---|
57 | SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu)
|
---|
58 | : SpectralResponse()
|
---|
59 | {
|
---|
60 | if(nu.NElts() != fdenu.NElts())
|
---|
61 | throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
|
---|
62 | _vecOfNu = nu;
|
---|
63 | _vecOfFDeNu = fdenu;
|
---|
64 | _numin = nu(0);
|
---|
65 | _numax = nu(nu.NElts()-1);
|
---|
66 | _size = nu.NElts();
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | //--------------
|
---|
71 | // Destructor --
|
---|
72 | //--------------
|
---|
73 | SpecRespVec::~SpecRespVec()
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 | // ---------------------------
|
---|
78 | // -- Function Definitions --
|
---|
79 | // ---------------------------
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 | /*! The transmission function extrapolates the transmission values for the
|
---|
84 | frequencies that are not present in the nu vector <BR>
|
---|
85 | given at the instanciation of the class.
|
---|
86 | */
|
---|
87 | double
|
---|
88 | SpecRespVec::transmission(double nu) const
|
---|
89 | {
|
---|
90 | if ( (nu < _numin) || (nu > _numax) ) return(0.);
|
---|
91 | double value = 0.;
|
---|
92 | int sizeVecOfNu = _vecOfNu.NElts();
|
---|
93 | if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
|
---|
94 | if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
95 |
|
---|
96 | for (int i=1; i<sizeVecOfNu; i++)
|
---|
97 | {
|
---|
98 | if(nu < _vecOfNu(i))
|
---|
99 | {
|
---|
100 | double up = _vecOfFDeNu(i) ;
|
---|
101 | double down = _vecOfFDeNu(i-1);
|
---|
102 | double xmin = _vecOfNu(i-1);
|
---|
103 | double xmax = _vecOfNu(i);
|
---|
104 | double a = ((up-down)/(xmax-xmin));
|
---|
105 | value = a*nu+(up-a*xmax);
|
---|
106 | return value;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | return value;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 | void
|
---|
115 | SpecRespVec::Print(ostream& os) const
|
---|
116 | {
|
---|
117 |
|
---|
118 | // os << "SpecRespVec::Print (" << typeid(*this).name()
|
---|
119 | //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
120 | os << "SpecRespVec ::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
121 | os << "MeanFreq= " << meanFreq() << " Transmission= " << transmission(meanFreq()) << endl;
|
---|
122 | os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
128 | void
|
---|
129 | ObjFileIO<SpecRespVec>::WriteSelf(POutPersist& s) const
|
---|
130 | {
|
---|
131 | if(dobj == NULL)
|
---|
132 | {
|
---|
133 | cout << " ObjFileIO<SpecRespVec>::WriteSelf:: dobj= null " << endl;
|
---|
134 | return;
|
---|
135 | }
|
---|
136 |
|
---|
137 | int_4 version, nothing;
|
---|
138 | version = 1;
|
---|
139 | nothing = 0; // Reserved for future use
|
---|
140 | s.PutI4(version);
|
---|
141 | s.PutI4(nothing);
|
---|
142 |
|
---|
143 | s.PutR8(dobj->minFreq());
|
---|
144 | s.PutR8(dobj->maxFreq());
|
---|
145 |
|
---|
146 | // TVector<T> has Persistence Manager
|
---|
147 | s << dobj->getNuVec();
|
---|
148 | {
|
---|
149 | Vector& xv2 = dobj->getTNuVec();
|
---|
150 | cout << xv2 ;
|
---|
151 | FIO_TArray<double> vio2(&xv2);
|
---|
152 | vio2.Write(s);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
157 | void
|
---|
158 | ObjFileIO<SpecRespVec>::ReadSelf(PInPersist& s)
|
---|
159 | {
|
---|
160 | int_4 version, nothing;
|
---|
161 | version = 1;
|
---|
162 | nothing = 0; // Reserved for future use
|
---|
163 | s.GetI4(version);
|
---|
164 | s.GetI4(nothing);
|
---|
165 |
|
---|
166 | if(dobj == NULL)
|
---|
167 | {
|
---|
168 | dobj= new SpecRespVec();
|
---|
169 | ownobj= true;
|
---|
170 | }
|
---|
171 | r_8 minf, maxf;
|
---|
172 | s.GetR8(minf);
|
---|
173 | s.GetR8(maxf);
|
---|
174 | dobj->setMinMaxFreq(minf, maxf);
|
---|
175 | // TVector<T> has Persistence Manager
|
---|
176 | FIO_TArray<double> vio(&(dobj->getNuVec()));
|
---|
177 | vio.Read(s);
|
---|
178 | FIO_TArray<double> vio2(&(dobj->getTNuVec()));
|
---|
179 | vio2.Read(s);
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
184 | #pragma define_template ObjFileIO<SpecRespVec>
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
188 | template class ObjFileIO<SpecRespVec>;
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | } // FIN namespace SOPHYA
|
---|