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

Spectrum.cxx

Go to the documentation of this file.
00001 // Spectrum.cxx: implementation of the Spectrum class.
00002 //
00004 
00005 #include "flux/Spectrum.h"
00006 #include <cmath>
00007 
00008 // CLHEP
00009 #include "CLHEP/Random/RandomEngine.h"
00010 #include "CLHEP/Random/RandGeneral.h"
00011 
00013 // Construction/Destruction
00015 
00016 Spectrum::~Spectrum(){}
00017 
00018 //float Spectrum::fraction(float e)
00019 //{
00020 //    // this is essentially rtbis of numerical recipies
00021 //    static int JMAX=40;
00022 //    static double xacc = e*1e-3;
00023 //    static double zero = 1e-4;
00024 
00025 //    double dx,xmid, x1=0,x2=1;
00026 //    double f = (*this)(x1)-e;
00027 //    double fmid = (*this)(x2)-e;
00028 
00029 //    // Check to see if the x2 contains the root
00030 //    if(abs(fmid) < zero) return x2;
00031 //
00032 //    if (f*fmid >0.0) return 0.5; // fail?
00033 //
00034 //    double rtb = f < 0.0 ? (dx=x2-x1, x1) : (dx = x1-x2,x2);
00035 //
00036 //    for(int j=0; j< JMAX; j++) {
00037 //      fmid = (*this)(xmid=rtb+ (dx*=0.5))-e;
00038 //      if( fmid <0.0 ) rtb = xmid;
00039 //      if( abs(dx) < xacc || fmid ==0) return rtb;
00040 //    }
00041 //    return rtb; // fail
00042 //}
00043 
00044 double Spectrum::flux ( ) const {
00045   return 0.; // flag that we don't have a flux
00046 }
00047 
00048 double Spectrum::solidAngle( )const
00049 {
00050     return 1.0; // flag that doesn't calculate
00051 }
00052 
00053 void Spectrum::setPosition ( double lat, double lon, double time ) {
00054   m_lat = lat;
00055   m_lon = lon;
00056   m_time = time;
00057 }
00058 
00059 
00060  std::pair<float,float> Spectrum::dir(float energy)const
00061 {
00062 
00063     // return solid angle pair (costh, phi) for the given energy
00064     // default: random except for Earth occultation
00065     //return std::make_pair(static_cast<float>(RandFlat::shoot(-0.4,1.0)),
00066         //static_cast<float>(RandFlat::shoot(0.0, 2*M_PI)) );
00067          //here's an attempt at random default distributions as above:
00068          return std::make_pair(((rand()/32767.0)*1.4)-0.4,(rand()/32767.0)*2*M_PI);
00069     
00070 }
00071 
00072 
00073 
00074  const char * Spectrum::particleName()const{
00075          static const char x='p';
00076          return &x;
00077  }
00078 
00079 double Spectrum::energySrc(HepRandomEngine* engine)
00080 {
00081    // default implementation, which works for other Spectrum objects
00082         return (*this)(engine->flat());
00083 }
00084 
00085 std::pair<double,double> Spectrum::dir(double energy, HepRandomEngine* engine)
00086 {
00087         // default that needs fixing!
00088         return dir(energy);
00089 }
00090 
00091 void Spectrum::parseParamList(std::string input, std::vector<float>& output) const
00092 {
00093 
00094         int i=0;
00095         for(;!input.empty() && i!=std::string::npos;){
00096                 float f = ::atof( input.c_str() );
00097                 output.push_back(f);
00098                 i=input.find_first_of(",");
00099                 input= input.substr(i+1);
00100         } 
00101 }

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