00001
00002
00003
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
00013 Hep3Vector gamgal( cos(l)*cos(b) , sin(l)*cos(b) , sin(b) );
00014
00015
00016 HepRotation galToCel = s_celestialToGalactic.inverse();
00017
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
00025 m_dir = Hep3Vector( cos(ra)*cos(dec), sin(ra)*cos(dec) , sin(dec) );
00026
00027 }else{
00028
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
00044 Hep3Vector pointingin(s_celestialToGalactic*m_dir);
00045
00046
00047
00048
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
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 }