00001
00002
00003 #include "flux/TrappedProtonSpectrum.h"
00004
00005 #include "flux/GPS.h"
00006
00007
00008 #include <cmath>
00009
00010 #include "SpectrumFactory.h"
00011
00012 static SpectrumFactory<TrappedProtonSpectrum> factory;
00013 const ISpectrumFactory& TrappedProtonSpectrumFactory = factory;
00014
00015
00016
00017 TrappedProtonSpectrum::TrappedProtonSpectrum(float lat, float lon) {
00018 init(lat,lon);
00019 }
00020
00021 TrappedProtonSpectrum::TrappedProtonSpectrum(const std::vector<float>& params)
00022 {
00023 init(params[0], params[1]);
00024 }
00025
00026
00027
00028 double TrappedProtonSpectrum::flux() const {
00029
00030 return flux(m_lat, m_lon);
00031 }
00032
00033
00034
00035 float TrappedProtonSpectrum::flux(float lat, float lon) const {
00036
00037
00038 int ilat = static_cast<int>(lat/5.+6.);
00039 float a = fmod(lat+30., 5.)/5.;
00040 int ilon = static_cast<int>(lon/5.);
00041 float b = fmod(lon, 5.)/5.;
00042 float rawflux = m_fluxTbl[ilon][ilat] * (1.-a) * (1.-b) +
00043 m_fluxTbl[ilon+1][ilat] * (1.-a) * b +
00044 m_fluxTbl[ilon][ilat+1] * a * (1.-b) +
00045 m_fluxTbl[ilon+1][ilat+1] * a * b;
00046 return 10000. * rawflux / (4.*M_PI);
00047 }
00048
00049
00050
00051 float TrappedProtonSpectrum::flux(std::pair<double,double> coords) const {
00052
00053 return flux(coords.first, coords.second);
00054 }
00055
00056
00057
00058 float TrappedProtonSpectrum::operator() (float x)const {
00059
00060 float y = 1. - x;
00061 if (y > 0.1107) return -0.09088 * log(y);
00062 else return -0.1011 * log(y/0.8004);
00063 }
00064
00065 double TrappedProtonSpectrum::calculate_rate(double old_rate) {
00066 setPosition( GPS::instance()->lat(), GPS::instance()->lon() );
00067 return flux();
00068 }
00069
00070 void TrappedProtonSpectrum::init(float lat, float lon) {
00071 m_lat = lat;
00072 m_lon = lon;
00073
00074 #include "TrappedProtonSpectrum.inc"
00075
00076
00077 for (int ii=0; ii < 73; ii++) {
00078 for (int jj=0; jj < 13; jj++) {
00079 m_fluxTbl[ii][jj] = gfluxes[jj+13*ii];
00080 }
00081 }
00082 }
00083
00084 const char * TrappedProtonSpectrum::particleName() const {
00085 return "p";
00086 }
00087
00088 std::string TrappedProtonSpectrum::title() const {
00089 return "TrappedProtonSpectrum";
00090 }