| 1 | //--------------------------------------------------------------------------
|
|---|
| 2 | // File and Version Information:
|
|---|
| 3 | // $Id: radspecvector.cc,v 1.3 1999-11-21 23:25:46 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 "radspecvector.h"
|
|---|
| 23 | #include "pexceptions.h"
|
|---|
| 24 |
|
|---|
| 25 | //----------------
|
|---|
| 26 | // Constructor --
|
|---|
| 27 | //----------------
|
|---|
| 28 | RadSpectraVec::RadSpectraVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
|---|
| 29 | : RadSpectra(numin, numax)
|
|---|
| 30 | {
|
|---|
| 31 | if(nu.NElts() != fdenu.NElts())
|
|---|
| 32 | throw SzMismatchError("RadSpectraVec::RadSpectraVec() - Non equal vector sizes");
|
|---|
| 33 | _vecOfNu = nu;
|
|---|
| 34 | _vecOfFDeNu = fdenu;
|
|---|
| 35 | _numin = nu(0);
|
|---|
| 36 | _numax = nu(nu.NElts()-1);
|
|---|
| 37 | if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | //--------------
|
|---|
| 42 | // Destructor --
|
|---|
| 43 | //--------------
|
|---|
| 44 | RadSpectraVec::~RadSpectraVec()
|
|---|
| 45 | {
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | // ---------------------------
|
|---|
| 49 | // -- Function Definitions --
|
|---|
| 50 | // ---------------------------
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | double
|
|---|
| 56 | RadSpectraVec::flux(double nu) const
|
|---|
| 57 | {
|
|---|
| 58 | if ( (nu < _numin) || (nu > _numax) ) return(0.);
|
|---|
| 59 | double value = 0.;
|
|---|
| 60 | int sizeVecOfNu = _vecOfNu.NElts();
|
|---|
| 61 | if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
|
|---|
| 62 | if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
|
|---|
| 63 |
|
|---|
| 64 | for (int i=1; i<sizeVecOfNu; i++)
|
|---|
| 65 | {
|
|---|
| 66 | if(nu < _vecOfNu(i))
|
|---|
| 67 | {
|
|---|
| 68 | double up = _vecOfFDeNu(i) ;
|
|---|
| 69 | double down = _vecOfFDeNu(i-1);
|
|---|
| 70 | double xmin = _vecOfNu(i-1);
|
|---|
| 71 | double xmax = _vecOfNu(i);
|
|---|
| 72 | double a = ((up-down)/(xmax-xmin));
|
|---|
| 73 | value = a*nu+(up-a*xmax);
|
|---|
| 74 | return value;
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | return _vecOfFDeNu(sizeVecOfNu-1);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | void
|
|---|
| 82 | RadSpectraVec::Print(ostream& os) const
|
|---|
| 83 | {
|
|---|
| 84 | // os << "RadSpectraVec::Print (" << typeid(*this).name()
|
|---|
| 85 | // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
|---|
| 86 | os << "RadSpectraVec::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
|---|
| 87 | os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
|
|---|
| 88 | os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
|
|---|
| 89 |
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|