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

GPS.cxx

Go to the documentation of this file.
00001 // GPS.cxx: implementation of the GPS class.
00002 // $Id: GPS.cxx,v 1.4 2001/10/31 23:20:05 srobinsn Exp $
00004 
00005 #include "flux/GPS.h"
00006 
00007 #include "flux/Orbit.h"
00008 #include "CLHEP/Random/RandFlat.h"
00009 
00010 #include <iomanip>
00011 
00012 //--------------------
00013 #include <string>
00014 
00015 #include "flux/FluxMgr.h"
00016 #include "flux/FluxSource.h"
00017 #include "SpectrumFactoryTable.h"
00018 #include "flux/GPS.h"
00019 
00020 #include "dom/DOM_Document.hpp"
00021 #include "dom/DOM_Element.hpp"
00022 #include "xml/Dom.h"
00023 #include "facilities/error.h"
00024 #include "xml/IFile.h"
00025 #include "flux/CompositeSource.h"
00026 
00027 #include "flux/FluxSource.h"
00028 
00029 #include "dom/DOM_Document.hpp"
00030 #include "dom/DOM_Element.hpp"
00031 #include "xml/XmlParser.h"
00032 //#include "ISpectrumFactory.h"
00033 #include <map>
00034 #include <list>
00035 
00036 #include <iostream>
00037 #include <algorithm>
00038 //------------------------
00039 
00040 // static declaration
00041 
00042 GPS*    GPS::s_instance = 0;
00043 
00044 GPS::GPS() 
00045 : m_orbit(new Orbit),
00046   m_expansion(-1.),    // default expansion: random orbit for now
00047   m_time(0.), 
00048   m_orbittime(m_time),
00049   m_sampleintvl(0.001),
00050   m_rotangles(std::make_pair<double,double>(0.,0.))
00051 {}
00052 
00053 GPS::Coords::Coords( double alat, double alon, double apitch
00054                     , double ayaw, double aroll, GPStime atime, double aphase) 
00055                     : m_time(atime), m_lat(alat), m_lon(alon), 
00056                     m_pitch(apitch), m_yaw(ayaw), m_roll(aroll), m_phase(aphase)
00057 {}
00058 
00059 GPS::Coords::Coords(){}
00060 
00061 
00062 GPS::~GPS ()
00063 { delete m_orbit; }
00064 
00065 
00066 double  GPS::pitch () const
00067 { 
00068     return orbit()->pitch( orbittime() ); 
00069 }
00070 
00071 double  GPS::yaw () const
00072 { 
00073     return orbit()->yaw( orbittime() );   
00074 }
00075 
00076 double   GPS::roll () const
00077 { 
00078     return orbit()->roll( orbittime() ); 
00079 }
00080 
00081 const Orbit*   GPS::orbit () const 
00082 {
00083     return m_orbit;
00084 }
00085 
00086 Orbit*   GPS::orbit () 
00087 {
00088     return m_orbit;
00089 }
00090 
00091 void GPS::synch ()
00092 {
00093     static bool first=true;
00094     bool changed=  false;
00095 
00096     if (Scheduler::instance()->running()) {
00097         time( Scheduler::instance()->elapsed_time() );
00098         changed = true; // maybe have threshold before nofitying?
00099     }
00100     if (expansion() < 0.) {
00101         static GPStime  last_time = time();
00102         if ((time() - last_time) > m_sampleintvl) {
00103             orbittime( RandFlat::shoot(orbit()->period()) );
00104             orbit()->ascendingLon(RandFlat::shoot(360.));
00105             last_time = time();
00106             changed = true;
00107 
00108         }
00109     }
00110     else if( expansion()>0 ) {
00111         orbittime( time()*expansion() );
00112         changed=true; 
00113     }
00114     
00115     // notify observers if changed (or first time thru)
00116     if( changed || first) notifyObservers();
00117     first=false;
00118     
00119 }
00120 
00121 double   GPS::lat () const
00122 {
00123     return orbit()->latitude( orbittime() ); 
00124 }
00125 
00126 double  GPS::lon () const
00127 { 
00128     return orbit()->longitude( orbittime() ); 
00129 }
00130 
00131 GPStime GPS::time ()  const
00132 { 
00133     return m_time;
00134 }
00135 
00136 double   GPS::phase () const
00137 {
00138     // compute orbital phase based upon current time
00139     return orbit()->phase( orbittime() );
00140 }
00141 
00142 double   GPS::expansion () const
00143 {
00144     return m_expansion;
00145 }
00146 
00147 void    GPS::orbit ( Orbit* o )
00148 {
00149     if (o == 0) return;
00150     delete m_orbit;
00151     m_orbit = o;
00152 }
00153 
00154 
00155 void GPS::pass ( double t )
00156 { 
00157     if (!Scheduler::instance()->running())      {
00158         time(time() + t);
00159     }   // cannot pass when scheduler is in control!
00160 }
00161 
00162 void GPS::phase ( double p )
00163 {
00164     // jump to a particular point in the orbit
00165     double  pd = orbit()->period();
00166     if (pd != 0.) orbit()->startphase(p - 2.*M_PI*time()/pd);
00167 }
00168 
00169 void GPS::expansion ( double e )
00170 {
00171     m_expansion = e; 
00172 }
00173 
00174 void GPS::pitch ( double p )
00175 {
00176     m_orbit->setpitch(p);
00177 }
00178 
00179 void GPS::yaw ( double y )
00180 {
00181     m_orbit->setyaw(y);
00182 }
00183 
00184 void GPS::roll ( double r )
00185 {
00186     m_orbit->setroll(r);
00187 }
00188 
00189 void GPS::lat ( double l )
00190 {
00191     m_orbit->setlatitude(l);
00192 }
00193 
00194 void GPS::lon ( double l )
00195 {
00196     m_orbit->setlongitude(l);
00197 }
00198 
00199 void GPS::time ( GPStime t )
00200 {
00201     m_time = t;
00202 }
00203 
00204 GPS*    GPS::instance() 
00205 { return (s_instance != 0) ? s_instance : (s_instance = new GPS()); }
00206 
00207 void GPS::kill()
00208 {
00209     delete s_instance;
00210     s_instance = 0;
00211 }
00212 
00213 GPS::Coords GPS::state () const
00214 {
00215     return GPS::Coords( lat(),lon(),pitch(),yaw(),roll(),time(), orbit()->phase(time()) );
00216 }
00217 
00218 void GPS::orbittime ( GPStime t ) 
00219 {
00220     m_orbittime = t;
00221 }
00222 
00223 GPStime GPS::orbittime () const
00224 {
00225     return m_orbittime;
00226 }
00227 
00228 void    GPS::sampleintvl ( GPStime s )
00229 {
00230     m_sampleintvl = s;
00231 }
00232 
00233 GPStime  GPS::sampleintvl () const
00234 {
00235     return m_sampleintvl;
00236 }
00237 
00238 void    GPS::setState ( const GPS::Coords& c )
00239 {
00240     m_orbit->setlatitude(c.lat());
00241     m_orbit->setlongitude(c.lon());
00242     m_orbit->setpitch(c.pitch());
00243     m_orbit->setyaw(c.yaw());
00244     m_orbit->setroll(c.roll());
00245     if (c.time() > 0.) time(c.time());  // if the time is relevant, use that time
00246 }
00247 void GPS::ascendingLon(double lon)
00248 {
00249     m_orbit->ascendingLon(lon);
00250 }
00251 double GPS::ascendingLon()const
00252 {
00253     return m_orbit->ascendingLon();
00254 }
00255 void    GPS::printOn(std::ostream& out) const
00256 {
00257     out << "GPS: time=" << time() 
00258         << ", lat, lon=" 
00259         << std::setprecision(4) << lat() << ", " << lon() 
00260         << std::endl;
00261 }
00262 
00263 
00264 //transformation
00265 std::pair<double,double> GPS::galToGlast(std::pair<double,double> galcoords){
00266 
00267 
00268 
00269         //lat, lon, sidereal??? time becomes J2000.0 coordinates here:
00270         double ra=((orbittime()/(24.0*60.0*60.0))*360.0)+lon();
00271         if(ra > 360.0) ra-=360.0;
00272         if(ra < 0.0 ) ra+=360.0;
00273         double dec=lat();
00274 
00275     //can consider GLAST to be zenith-pointing here....m_rotangles takes care of the rest...
00276 double pi = 3.141592653589793238;
00277 //double ra=0;
00278 //double dec=0;
00279 double b,l,otherl,cosl,cosb,sinb,sinl,cosra,sinra,cosdec,sindec;
00280 double radperdeg=(2.0*pi)/360.0;
00281 cosra=cos(ra*radperdeg);
00282 sinra=sin(ra*radperdeg);
00283 
00284 cosdec=cos(dec*radperdeg);
00285 sindec=sin(dec*radperdeg);
00286 double cosbcosl=(cosdec*cosra*-0.0548755)+(cosdec*sinra*-0.87343711)+(sindec*-0.4838349858);
00287 double cosbsinl=(cosdec*cosra*0.49410945)+(cosdec*sinra*-0.444829589)+(sindec*0.7469822518);
00288 sinb=(cosdec*cosra*-0.8676661358)+(cosdec*sinra*-0.198076386)+(sindec*0.4559837957);
00289 b=asin(sinb); //BUT WHAT OF b < -90 or > 90?
00290 cosb=cos(b);
00291 cosl=cosbcosl/cosb;
00292 sinl=cosbsinl/cosb;
00293 otherl=acos(cosl);
00294 l=asin(sinl);
00295 //if(l - otherl >= 0.001) std::cout << "unequal stuff! " << std::endl;
00296 b=b/radperdeg;
00297 l=l/radperdeg;
00298 
00299 double sourceb=galcoords.first;
00300 double sourcel=galcoords.second;
00301 //determine how far off the azimuth the source is
00302 double theta = sqrt(pow(b-sourceb,2)+pow(l-sourcel,2));
00303 //phi is 0, since we have no info on which direction GLAST is azimuthally rotated
00304 double phi=0.0;
00305 //returned data is in (theta,phi) format - same as explicit direction declaration
00306 //std::cout << "b=" << b <<" sourceb=" << sourceb <<" l=" << l <<" sourcel=" << sourcel << std::endl
00307 //<< " theta=" << theta << " phi=" << phi << std::endl;
00308 return std::make_pair<double,double>(theta,phi);
00309 
00310 }
00311 
00312 
00313 //access m_rotangles
00314 std::pair<double,double> GPS::rotateAngles(){
00315         return m_rotangles;
00316 
00317 }
00318 
00319  //set m_rotangles
00320 void GPS::rotateAngles(std::pair<double,double> coords){
00321         m_rotangles=coords;
00322 }
00323 

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