source: Sophya/trunk/SophyaLib/SkyT/specrespvector.cc@ 2743

Last change on this file since 2743 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 4.8 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: specrespvector.cc,v 1.11 2004-09-10 09:54:40 cmv 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 "sopnamsp.h"
18#include "machdefs.h"
19#include <iostream>
20#include <math.h>
21// #include <typeinfo>
22
23#include "specrespvector.h"
24#include "pexceptions.h"
25#include "fioarr.h"
26//----------------
27// Constructor --
28//----------------
29/*!
30 * \class SOPHYA::SpecRespVec
31 \ingroup SkyT
32 One may also want to defined the filter of a detector by two vectors:
33 one for the frequencies and one for the corresponding transmission values.
34 In this case on should use the SpecRespVec class !
35*/
36SpecRespVec::SpecRespVec()
37 : SpectralResponse()
38{
39}
40
41/*! Constructor:
42 \param nu vector of the frequencies
43 \param fdenu vector of the corresponding transmission values of the filter
44*/
45SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
46 : SpectralResponse(numin, numax)
47{
48 if(nu.NElts() != fdenu.NElts())
49 throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
50 _vecOfNu = nu;
51 _vecOfFDeNu = fdenu;
52 _size = nu.NElts();
53 if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
54}
55
56SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu)
57 : SpectralResponse()
58{
59 if(nu.NElts() != fdenu.NElts())
60 throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
61 _vecOfNu = nu;
62 _vecOfFDeNu = fdenu;
63 _numin = nu(0);
64 _numax = nu(nu.NElts()-1);
65 _size = nu.NElts();
66 if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
67}
68
69
70//--------------
71// Destructor --
72//--------------
73SpecRespVec::~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*/
87double
88SpecRespVec::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
114void
115SpecRespVec::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
127DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
128void
129ObjFileIO<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
156DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
157void
158ObjFileIO<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)
188template class ObjFileIO<SpecRespVec>;
189#endif
Note: See TracBrowser for help on using the repository browser.