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