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