Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

TrappedProtonSpectrum.cxx

Go to the documentation of this file.
00001 // $Id: TrappedProtonSpectrum.cxx,v 1.6 2001/07/15 21:03:14 burnett Exp $
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 //-------------------------- constructors
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 //-------------------------- flux() (current position)
00027 
00028 double TrappedProtonSpectrum::flux() const {
00029     // calculate flux for the current cutoff
00030     return flux(m_lat, m_lon);
00031 }
00032 
00033 //-------------------------- flux() (specified position)
00034 
00035 float TrappedProtonSpectrum::flux(float lat, float lon) const {
00036     // Flux as a function of latitude and longitude in a 600 km orbit.
00037     // Linear interpolate in a table with a 5 degree sampling grid.
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); // convert cm^2 to m^2 ster
00047 }
00048 
00049 //-------------------------- flux() (position given in a pair)
00050 
00051 float TrappedProtonSpectrum::flux(std::pair<double,double> coords) const {
00052     // Flux as a function of latitude and longitude
00053     return flux(coords.first, coords.second);
00054 }
00055 
00056 //-------------------------- operator()  sample an energy value
00057 
00058 float TrappedProtonSpectrum::operator() (float x)const {
00059     // return a random value of energy sampled from the spectrum
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"  // numerical data: energies, fluxes
00075 
00076     // table of total flux as a function of latitude and longitude
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 }

Generated at Wed Nov 21 12:20:34 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000