| [601] | 1 | //--------------------------------------------------------------------------
 | 
|---|
 | 2 | // File and Version Information:
 | 
|---|
| [2615] | 3 | //      $Id: specrespvector.cc,v 1.11 2004-09-10 09:54:40 cmv Exp $
 | 
|---|
| [601] | 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 | //---------------
 | 
|---|
| [2615] | 17 | #include "sopnamsp.h"
 | 
|---|
| [601] | 18 | #include "machdefs.h"
 | 
|---|
| [2322] | 19 | #include <iostream>
 | 
|---|
| [601] | 20 | #include <math.h>
 | 
|---|
 | 21 | // #include <typeinfo>
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | #include "specrespvector.h"
 | 
|---|
 | 24 | #include "pexceptions.h"
 | 
|---|
| [806] | 25 | #include "fioarr.h"
 | 
|---|
| [601] | 26 | //----------------
 | 
|---|
 | 27 | // Constructor --
 | 
|---|
 | 28 | //----------------
 | 
|---|
| [909] | 29 | /*! 
 | 
|---|
 | 30 |  * \class SOPHYA::SpecRespVec
 | 
|---|
| [927] | 31 |  \ingroup SkyT
 | 
|---|
| [909] | 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 | */
 | 
|---|
| [668] | 36 | SpecRespVec::SpecRespVec()
 | 
|---|
 | 37 |         : SpectralResponse()
 | 
|---|
 | 38 | {
 | 
|---|
 | 39 | }
 | 
|---|
 | 40 | 
 | 
|---|
| [909] | 41 | /*! Constructor: 
 | 
|---|
 | 42 |   \param nu  vector of the frequencies
 | 
|---|
 | 43 |   \param fdenu  vector of the corresponding transmission values of the filter
 | 
|---|
 | 44 | */
 | 
|---|
| [601] | 45 | SpecRespVec::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;
 | 
|---|
| [669] | 52 |   _size = nu.NElts();
 | 
|---|
 | 53 |   if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
 | 
|---|
 | 54 | }
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | SpecRespVec::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;
 | 
|---|
| [601] | 63 |   _numin = nu(0);
 | 
|---|
 | 64 |   _numax = nu(nu.NElts()-1);
 | 
|---|
| [668] | 65 |   _size = nu.NElts();
 | 
|---|
| [601] | 66 |   if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
 | 
|---|
 | 67 | }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | //--------------
 | 
|---|
 | 71 | // Destructor --
 | 
|---|
 | 72 | //--------------
 | 
|---|
 | 73 | SpecRespVec::~SpecRespVec()
 | 
|---|
 | 74 | {
 | 
|---|
 | 75 | }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | //              ---------------------------
 | 
|---|
 | 78 | //              --  Function Definitions --
 | 
|---|
 | 79 | //              ---------------------------
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | 
 | 
|---|
| [909] | 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 | */
 | 
|---|
| [601] | 87 | double 
 | 
|---|
 | 88 | SpecRespVec::transmission(double nu)  const 
 | 
|---|
 | 89 | {
 | 
|---|
 | 90 |   if ( (nu < _numin) || (nu > _numax) ) return(0.);
 | 
|---|
| [610] | 91 |   double value = 0.;
 | 
|---|
| [601] | 92 |   int sizeVecOfNu = _vecOfNu.NElts();
 | 
|---|
| [610] | 93 |   if(nu <=  _vecOfNu(0)) return _vecOfFDeNu(0);
 | 
|---|
| [601] | 94 |   if(nu >=  _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |   for (int i=1; i<sizeVecOfNu; i++)
 | 
|---|
 | 97 |     {
 | 
|---|
| [610] | 98 |       if(nu < _vecOfNu(i))
 | 
|---|
| [601] | 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 | }
 | 
|---|
| [668] | 125 | 
 | 
|---|
 | 126 | 
 | 
|---|
| [2344] | 127 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| [668] | 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 | 
 | 
|---|
| [669] | 146 |   // TVector<T> has Persistence Manager
 | 
|---|
 | 147 |   s << dobj->getNuVec();
 | 
|---|
 | 148 |   {
 | 
|---|
 | 149 |   Vector& xv2 = dobj->getTNuVec();
 | 
|---|
 | 150 |   cout << xv2 ;
 | 
|---|
| [806] | 151 |   FIO_TArray<double> vio2(&xv2);
 | 
|---|
| [669] | 152 |   vio2.Write(s);
 | 
|---|
 | 153 |   }
 | 
|---|
| [668] | 154 | }
 | 
|---|
 | 155 | 
 | 
|---|
| [2344] | 156 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| [668] | 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 |     {
 | 
|---|
| [669] | 168 |     dobj= new SpecRespVec();
 | 
|---|
 | 169 |     ownobj= true;
 | 
|---|
| [668] | 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 
 | 
|---|
| [806] | 176 |   FIO_TArray<double> vio(&(dobj->getNuVec()));
 | 
|---|
| [669] | 177 |   vio.Read(s);
 | 
|---|
| [806] | 178 |   FIO_TArray<double> vio2(&(dobj->getTNuVec()));
 | 
|---|
| [669] | 179 |   vio2.Read(s);
 | 
|---|
| [668] | 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
 | 
|---|