//-------------------------------------------------------------------------- // File and Version Information: // $Id: radspec.cc,v 1.1.1.1 1999-11-19 16:34:32 ansari Exp $ // // Description: // Aim of the class: To give the energy density // The unity used here is W/m^2/Hz/sr // // History (add to end): // Sophie Oct, 1999 - creation // //------------------------------------------------------------------------ //--------------- // C++ Headers -- //--------------- #include "machdefs.h" #include #include #include #include "radspec.h" #include "integ.h" //---------------- // Constructor -- //---------------- RadSpectra::RadSpectra(double numin, double numax) { _numin = numin; _numax = numax; } //-------------- // Destructor -- //-------------- RadSpectra::~RadSpectra() { } // --------------------------- // -- Function Definitions -- // --------------------------- double RadSpectra::minFreq() const { return _numin; } double RadSpectra::maxFreq() const { return _numax; } double RadSpectra::meanFreq() const { double result = (_numax+_numin)/2.; return result; } // peakFreq returns the value of the frequency for the // peak of the spectrum. double RadSpectra::peakFreq() const { double maxAnswer = -1.e99; double maxNu = -10; double nu; for (int i=1; i<1000;i++) { nu=(_numax-_numin)*i/1000.+_numin; double lookForMax = flux(nu); if(maxAnswer <= lookForMax) { maxAnswer= lookForMax; maxNu = nu; } } return maxNu; } // To change min-max frequency void RadSpectra::setMinMaxFreq(double numin, double numax) { _numin = numin; _numax = numax; } // the RadSpectra_fluxFunction function is used to call TrpzInteg double(double) // (integration over a range of frequencies) static RadSpectra* _raypourfinteg = NULL; static double RadSpectra_fluxFunction(double nu) { return(_raypourfinteg->flux(nu)); } double RadSpectra::integratedFlux(double f1, double f2) const { _raypourfinteg = const_cast(this); TrpzInteg I(RadSpectra_fluxFunction , f1, f2); _raypourfinteg = NULL; return((double)I); } double RadSpectra::integratedFlux() const { return integratedFlux(_numin, _numax); } // integration using the logarithm !! // Carefull!! Base 10.... static RadSpectra* _rayIntLog = NULL; static double RadSpectra_logFluxFunction(double tau) { double value = _rayIntLog->flux(pow(10,tau))*pow(10,tau); return(value); } double RadSpectra::logIntegratedFlux(double f1, double f2) const { double f1Log = log10(f1); double f2Log = log10(f2); if(f1Log < -1.e99) f1Log = -1.e99; if(f2Log > 1.e99) f2Log = 1.e99; _rayIntLog = const_cast(this); TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log); double value = (double)I * log(10.); _rayIntLog = NULL; return(value); } double RadSpectra::logIntegratedFlux() const { return logIntegratedFlux(_numin,_numax); } // the RadSpectra_filteredFlux function is used to call TrpzInteg double(double) // (integration over a range of frequencies with a filter) static SpectralResponse* _filter = NULL ; static double RadSpectra_filteredFlux(double nu) { double flux = _raypourfinteg->flux(nu); return(flux * _filter->transmission(nu)); } double RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter, double f1, double f2) const { _raypourfinteg = const_cast(this); _filter = const_cast(&filter); TrpzInteg I(RadSpectra_filteredFlux,f1,f2); _raypourfinteg = NULL; _filter = NULL; return((double)I); } double RadSpectra::filteredIntegratedFlux(SpectralResponse const& filter) { double minOfMin = filter.minFreq(); double maxOfMax = filter.maxFreq(); if(minOfMin < this->minFreq()) minOfMin = this->minFreq(); if(maxOfMax > this->maxFreq()) maxOfMax = this->maxFreq(); return(filteredIntegratedFlux(filter, minOfMin, maxOfMax ) ); } // the RadSpectraVec_filteredFlux function is used to call TrpzInteg double(double) // (integration over a range of frequencies with a filter) static double RadSpectra_logFilteredFlux(double tau) { double nu = pow(10,tau); double flux = _raypourfinteg->flux(nu)*nu; return(flux * _filter->transmission(nu)); } double RadSpectra::filteredLogIntFlux(SpectralResponse const& filter, double f1, double f2) const { // double f1Log = log10(f1); // double f2Log = log10(f2); // if(f1Log < -1.e99) f1Log = -1.e99; // if(f2Log > 1.e99) f2Log = 1.e99; // _rayIntLog = const_cast(this); // TrpzInteg I(RadSpectra_logFluxFunction,f1Log,f2Log); // double value = (double)I * log(10.); // return(value); // _rayIntLog = NULL; _raypourfinteg = NULL; _filter = NULL; double f1Log = log10(f1); double f2Log = log10(f2); if(f1Log < -1.e99) f1Log = -1.e99; if(f2Log > 1.e99) f2Log = 1.e99; _raypourfinteg = const_cast(this); _filter = const_cast(&filter); TrpzInteg I(RadSpectra_logFilteredFlux,f1Log,f2Log); _raypourfinteg = NULL; _filter = NULL; return((double)I* log(10.)); } double RadSpectra::filteredLogIntFlux(SpectralResponse const& filter) { return(filteredLogIntFlux(filter, filter.minFreq(), filter.maxFreq() ) ); } void RadSpectra::Print(ostream& os) const { // os << "RadSpectra::Print (" << typeid(*this).name() // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl; os << "RadSpectra::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl; os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl; os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl; }