Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

SkyDir.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/astro/src/SkyDir.cxx,v 1.2 2002/08/13 10:01:16 srobinsn Exp $
00002 
00003 // Include files
00004 #include "astro/SkyDir.h"
00005 
00006 namespace astro {
00007     SkyDir::SkyDir(double param1, double param2, CoordSystem inputType){
00008         if(inputType == GALACTIC){
00009             double  l = param1*M_PI/180;
00010             double  b = param2*M_PI/180;
00011             
00012             //here we construct the cartesian galactic vector
00013             Hep3Vector gamgal( cos(l)*cos(b) , sin(l)*cos(b) , sin(b) );
00014             
00015             //get the transformation matrix from galactic to celestial coordinates.
00016             HepRotation galToCel = s_celestialToGalactic.inverse();
00017             //and do the transform to get the cartesian celestial vector
00018             m_dir = galToCel*gamgal;
00019             
00020         }else if(inputType == CELESTIAL){
00021             double ra = param1*M_PI/180;
00022             double dec = param2*M_PI/180;
00023             
00024             //here we construct the cartesian celestial vector
00025             m_dir = Hep3Vector( cos(ra)*cos(dec), sin(ra)*cos(dec) , sin(dec) );        
00026             
00027         }else{
00028             //improper coordinate system declaration - default things and say so.
00029             throw("Improper coordinate System declaration in SkyDir" );
00030             
00031             m_dir = Hep3Vector(0,0,1);
00032         }
00033     }
00034     
00035     SkyDir::SkyDir(Hep3Vector dir):
00036     m_dir(dir){
00037     }
00038     
00039     HepRotation SkyDir::s_celestialToGalactic = HepRotation().rotateZ(-282.25*M_PI/180).rotateX(-62.6*M_PI/180).rotateZ(33.*M_PI/180);
00040     
00041     std::pair<double,double> SkyDir::setGalCoordsFromDir() const{
00042         
00043         //do the transform to get the galactic celestial vector
00044         Hep3Vector pointingin(s_celestialToGalactic*m_dir);
00045         
00046         // pointingin is the galactic cartesian pointing vector,
00047         //where yhat points at the galactic origin.
00048         // we want to make this into l and b now.
00049         double l = atan2(pointingin.y(), pointingin.x());
00050         double b = asin(pointingin.z());
00051         
00052         l *= 360./M_2PI;
00053         b *= 360./M_2PI;
00054         
00055         return std::make_pair<double,double>(l,b);
00056     }
00057     
00058     
00059     double SkyDir::l ()const{
00060         return setGalCoordsFromDir().first;
00061     }
00062     
00063     double SkyDir::b ()const{
00064         return setGalCoordsFromDir().second;
00065     }
00066     
00067     double SkyDir::ra ()const{
00068         double ra=atan2(m_dir.y(), m_dir.x())*180/M_PI;    
00069         //fold RA into the range (0,360)
00070         while(ra < 0) ra+=360.;
00071         while(ra > 360) ra -= 360.;
00072         return ra;
00073     }
00074     
00075     double SkyDir::dec ()const{
00076         return asin(m_dir.z())*180/M_PI;
00077     }
00078     
00079 } //namespace astro

Generated on Wed Aug 14 10:09:35 2002 for astro by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001