Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
skycoord.hh
Go to the documentation of this file.
1 /**********************************************************
2  * Package: sky coordinates (extract from the lal library)
3  * File name: skycoord.hh
4  * Author: Gabriele Vedovato (vedovato@lnl.infn.it)
5  * Release Date: 01/27/2012
6  * Version: 1.00
7  **********************************************************/
8 
9 #ifndef SKYCOORD_HH
10 #define SKYCOORD_HH
11 
12 #define LAL_DELTAGAL (0.473477302)
13 #define LAL_ALPHAGAL (3.366032942)
14 #define LAL_LGAL (0.576)
15 #define LAL_IEARTH 0.409092600600582871467239393761915655 // Earth inclination (2000),radians : LALConstants.h
16 
17 #define LAL_REARTH_SI 6378136.6 // Earth equatorial radius : LALConstants.h
18 #define LAL_EARTHFLAT (0.00335281)
19 #define LAL_HSERIES (0.0001) // value H below which we expand sqrt(1-H)
20 
21 #include <iostream>
22 #include <fstream>
23 #include <stdlib.h>
24 #include "skymap.hh"
25 
26 using namespace std;
27 
28 inline void
30 { // see LAL CelestialCoordinates.c
31  double deg2rad = TMath::Pi()/180.;
32  ilongitude*=deg2rad;
33  ilatitude*=deg2rad;
34 
35  double sinDGal = sin( LAL_DELTAGAL ); /* sin(delta_NGP) */
36  double cosDGal = cos( LAL_DELTAGAL ); /* cos(delta_NGP) */
37  double l = -LAL_LGAL; /* will be l-l(ascend) */
38  double sinB, cosB, sinL, cosL; /* sin and cos of b and l */
39  double sinD, sinA, cosA; /* sin and cos of delta and alpha */
40 
41  /* Compute intermediates. */
42  l += ilongitude;
43  sinB = sin( ilatitude );
44  cosB = cos( ilatitude );
45  sinL = sin( l );
46  cosL = cos( l );
47 
48  /* Compute components. */
49  sinD = cosB*cosDGal*sinL + sinB*sinDGal;
50  sinA = cosB*cosL;
51  cosA = sinB*cosDGal - cosB*sinL*sinDGal;
52 
53  /* Compute final results. */
54  olatitude = asin( sinD );
55  l = atan2( sinA, cosA ) + LAL_ALPHAGAL;
56 
57  /* Optional phase correction. */
58  if ( l < 0.0 )
59  l += TMath::TwoPi();
60  if ( l > 360. )
61  l -= TMath::TwoPi();
62  olongitude = l;
63 
64  double rad2deg = 180./TMath::Pi();
65  olongitude*=rad2deg;
66  olatitude*=rad2deg;
67 
68  return;
69 }
70 
71 inline void
73 { // see LAL CelestialCoordinates.c
74  double deg2rad = TMath::Pi()/180.;
75  ilongitude*=deg2rad;
76  ilatitude*=deg2rad;
77 
78  double sinDGal = sin( LAL_DELTAGAL ); /* sin(delta_NGP) */
79  double cosDGal = cos( LAL_DELTAGAL ); /* cos(delta_NGP) */
80  double a = -LAL_ALPHAGAL; /* will be alpha-alpha_NGP */
81  double sinD, cosD, sinA, cosA; /* sin and cos of delta and alpha */
82  double sinB, sinL, cosL; /* sin and cos of b and l */
83 
84  /* Compute intermediates. */
85  a += ilongitude;
86  sinD = sin( ilatitude );
87  cosD = cos( ilatitude );
88  sinA = sin( a );
89  cosA = cos( a );
90 
91  /* Compute components. */
92  sinB = cosD*cosDGal*cosA + sinD*sinDGal;
93  sinL = sinD*cosDGal - cosD*cosA*sinDGal;
94  cosL = cosD*sinA;
95 
96  /* Compute final results. */
97  olatitude = asin( sinB );
98  a = atan2( sinL, cosL ) + LAL_LGAL;
99 
100  /* Optional phase correction. */
101  if ( a < 0.0 )
102  a += TMath::TwoPi();
103  if ( a > 360. )
104  a -= TMath::TwoPi();
105  olongitude = a;
106 
107  double rad2deg = 180./TMath::Pi();
108  olongitude*=rad2deg;
109  olatitude*=rad2deg;
110 
111  return;
112 }
113 
114 inline void
116 { // see LAL CelestialCoordinates.c
117  double deg2rad = TMath::Pi()/180.;
118  ilongitude*=deg2rad;
119  ilatitude*=deg2rad;
120 
121  double sinE = sin( LAL_IEARTH ); /* sin(epsilon) */
122  double cosE = cos( LAL_IEARTH ); /* cos(epsilon) */
123  double sinB, cosB, sinL, cosL; /* sin and cos of b and l */
124  double sinD, sinA, cosA; /* sin and cos of delta and alpha */
125 
126  /* Compute intermediates. */
127  sinB = sin( ilatitude );
128  cosB = cos( ilatitude );
129  sinL = sin( ilongitude );
130  cosL = cos( ilongitude );
131 
132  /* Compute components. */
133  sinD = cosB*sinL*sinE + sinB*cosE;
134  sinA = cosB*sinL*cosE - sinB*sinE;
135  cosA = cosB*cosL;
136 
137  /* Compute final results. */
138  olatitude = asin( sinD );
139  olongitude = atan2( sinA, cosA );
140 
141  /* Optional phase correction. */
142  if ( olongitude < 0.0 )
143  olongitude += TMath::TwoPi();
144  if ( olongitude > 360. )
145  olongitude -= TMath::TwoPi();
146 
147  double rad2deg = 180./TMath::Pi();
148  olongitude*=rad2deg;
149  olatitude*=rad2deg;
150  olatitude=-olatitude;
151 
152  return;
153 }
154 
155 inline void
157 { // see LAL CelestialCoordinates.c
158  double deg2rad = TMath::Pi()/180.;
159  ilongitude*=deg2rad;
160  ilatitude*=deg2rad;
161 
162  double sinE = sin( LAL_IEARTH ); /* sin(epsilon) */
163  double cosE = cos( LAL_IEARTH ); /* cos(epsilon) */
164  double sinD, cosD, sinA, cosA; /* sin and cos of delta and alpha */
165  double sinB, sinL, cosL; /* sin and cos of b and l */
166 
167  /* Compute intermediates. */
168  sinD = sin( ilatitude );
169  cosD = cos( ilatitude );
170  sinA = sin( ilongitude );
171  cosA = cos( ilongitude );
172 
173  /* Compute components. */
174  sinB = sinD*cosE - cosD*sinA*sinE;
175  sinL = cosD*sinA*cosE + sinD*sinE;
176  cosL = cosD*cosA;
177 
178  /* Compute final results. */
179  olatitude = asin( sinB );
180  olongitude = atan2( sinL, cosL );
181 
182  /* Optional phase correction. */
183  if ( olongitude < 0.0 )
184  olongitude += TMath::TwoPi();
185  if ( olongitude > 360. )
186  olongitude -= TMath::TwoPi();
187 
188  double rad2deg = 180./TMath::Pi();
189  olongitude*=rad2deg;
190  olatitude*=rad2deg;
191  olatitude=-olatitude;
192 
193  return;
194 }
195 
196 inline void
197 GeodeticToGeocentric(double latitude, double longitude, double elevation, double& X, double& Y, double& Z) {
198 
199  double c, s; /* position components in and orthogonal to the equator */
200  double cosP, sinP; /* cosine and sine of latitude */
201  double fFac; /* ( 1 - f )^2 */
202  double x, y; /* Cartesian coordinates */
203  double maxComp, r; /* max{x,y,z}, and sqrt(x^2+y^2+z^2) */
204 
205 
206  /* Compute intermediates. */
207  fFac = 1.0 - LAL_EARTHFLAT;
208  fFac *= fFac;
209  cosP = cos( latitude );
210  sinP = sin( latitude );
211  c = sqrt( 1.0 / ( cosP*cosP + fFac*sinP*sinP ) );
212  s = fFac*c;
213  c = ( LAL_REARTH_SI*c + elevation )*cosP;
214  s = ( LAL_REARTH_SI*s + elevation )*sinP;
215 
216  /* Compute Cartesian coordinates. */
217  X = x = c*cos( longitude );
218  Y = y = c*sin( longitude );
219  Z = s;
220 
221  /* Compute the radius. */
222  maxComp = x;
223  if ( y > maxComp )
224  maxComp = y;
225  if ( s > maxComp )
226  maxComp = s;
227  x /= maxComp;
228  y /= maxComp;
229  s /= maxComp;
230  r = sqrt( x*x + y*y + s*s );
231 /*
232  // Compute the spherical coordinates, and exit.
233  location->radius = maxComp*r;
234  location->geocentric.longitude = longitude;
235  location->geocentric.latitude = asin( s / r );
236 */
237 }
238 
239 inline void
240 HeapSort( double* data, double length) {
241 
242  int i;
243  int j;
244  int k;
245  int n;
246  double temp;
247 
248  n=length;
249 
250  /* A vector of length 0 or 1 is already sorted. */
251  if(n<2)
252  {
253  cout << "A vector of length 0 or 1 is already sorted" << endl;
254  }
255 
256  /* Here is the heapsort algorithm. */
257  j=n-1;
258  n >>= 1;
259 
260  while(1){
261  if(n>0)
262  temp=data[--n];
263  else{
264  temp=data[j];
265  data[j]=data[0];
266  if(--j==0){
267  data[0]=temp;
268  break;
269  }
270  }
271  i=n;
272  k=(n << 1)+1;
273  while(k<=j){
274  if(k<j && data[k]<data[k+1])
275  k++;
276  if(temp<data[k]){
277  data[i]=data[k];
278  i=k;
279  k<<=1;
280  k++;
281  }else
282  k=j+1;
283  }
284  data[i]=temp;
285  }
286 }
287 
288 inline void
289 GeocentricToGeodetic(double X, double Y, double Z, double& latitude, double& longitude, double& elevation) {
290 
291  double x, y, z; /* normalized geocentric coordinates */
292  double pi; /* axial distance */
293 
294  /* Declare some local constants. */
295  const double rInv = 1.0 / LAL_REARTH_SI;
296  const double f1 = 1.0 - LAL_EARTHFLAT;
297  const double f2 = LAL_EARTHFLAT*( 2.0 - LAL_EARTHFLAT );
298 
299  /* See if we've been given a special set of coordinates. */
300  x = rInv*X;
301  y = rInv*Y;
302  z = rInv*Z;
303  pi = sqrt( x*x + y*y );
304  if ( pi == 0.0 ) {
305  longitude = atan2( y, x );
306  if ( z >= 0.0 ) {
307  latitude = TMath::PiOver2();
308  elevation = z - f1;
309  } else {
310  latitude = -TMath::PiOver2();
311  elevation = f1 - z;
312  }
313  elevation *= LAL_REARTH_SI;
314  }
315 
316  /* Do the general transformation even if z=0. */
317  else {
318  double za, e, f, p, q, d, v, w, g, h, t, phi, tanP;
319 
320  /* Compute intermediates variables. */
321  za = f1*fabs( z );
322  e = za - f2;
323  f = za + f2;
324  p = ( 4.0/3.0 )*( pi*pi + za*za - f2*f2 );
325  q = 8.0*f2*za;
326  d = p*p*p + pi*pi*q*q;
327  if ( d >= 0.0 ) {
328  v = pow( sqrt( d ) + pi*q, 1.0/3.0 );
329  v -= pow( sqrt( d ) - pi*q, 1.0/3.0 );
330  } else {
331  v = 2.0*sqrt( -p )*cos( acos( pi*q/( p*sqrt( -p ) ) )/3.0 );
332  }
333  w = sqrt( e*e + v*pi );
334  g = 0.5*( e + w );
335  h = pi*( f*pi - v*g )/( g*g*w );
336 
337  /* Compute t, expanding the square root if necessary. */
338  if ( fabs( h ) < LAL_HSERIES )
339  t = g*( 0.5*h + 0.375*h*h + 0.3125*h*h*h );
340  else
341  t = g*( sqrt( 1.0 + h ) - 1.0 );
342 
343  /* Compute and sort the factors in the arctangent. */
344  {
345  double tanPFac[4]; /* factors of tanP */
346  tanPFac[0] = pi - t;
347  tanPFac[1] = pi + t;
348  tanPFac[2] = 1.0/pi;
349  tanPFac[3] = 1.0/t;
350  double length = 4;
351  HeapSort( tanPFac, length );
352  tanP = tanPFac[0]*tanPFac[3];
353  tanP *= tanPFac[1]*tanPFac[2];
354  tanP /= 2.0*f1;
355  }
356 
357  /* Compute latitude, longitude, and elevation. */
358  phi = atan( tanP );
359  latitude = phi;
360  if ( z < 0.0 ) latitude *= -1.0;
361  longitude = atan2( y, x );
362  elevation = ( pi - t/pi )*cos( phi );
363  elevation += ( fabs( z ) - f1 )*sin( phi );
364  elevation *= LAL_REARTH_SI;
365  }
366 }
367 
368 inline void
369 GetCartesianComponents( double u[3], double Alt, double Az, double Lat, double Lon) {
370 
371  double cosAlt=cos(Alt); double sinAlt=sin(Alt);
372  double cosAz=cos(Az); double sinAz=sin(Az);
373  double cosLat=cos(Lat); double sinLat=sin(Lat);
374  double cosLon=cos(Lon); double sinLon=sin(Lon);
375 
376  double uNorth = cosAlt * cosAz;
377  double uEast = cosAlt * sinAz;
378  /* uUp == sinAlt */
379  double uRho = - sinLat * uNorth + cosLat * sinAlt;
380  /* uLambda == uEast */
381 
382  u[0] = cosLon * uRho - sinLon * uEast;
383  u[1] = sinLon * uRho + cosLon * uEast;
384  u[2] = cosLat * uNorth + sinLat * sinAlt;
385 
386  return;
387 }
388 
389 // ************************************
390 // cWB Coordinate System
391 // theta=0 : North Pole
392 // phi=0 : Greenwich meridian
393 // ************************************
394 
395 inline void
396 CwbToGeographic(double ilongitude, double ilatitude, double& olongitude, double& olatitude)
397 {
398  olongitude = ilongitude>180 ? ilongitude-360 : ilongitude;
399  olatitude=-(ilatitude-90);
400 }
401 
402 inline void
403 GeographicToCwb(double ilongitude, double ilatitude, double& olongitude, double& olatitude)
404 {
405  olongitude = ilongitude<0 ? ilongitude+360 : ilongitude;
406  olatitude=-(ilatitude-90);
407 }
408 
409 inline void
410 CwbToCelestial(double ilongitude, double ilatitude, double& olongitude, double& olatitude, double gps=0)
411 {
412  skymap sm;
413  olongitude = gps>0 ? sm.phi2RA(ilongitude, gps) : ilongitude;
414  olongitude = 360-olongitude;
415  olatitude=-(ilatitude-90);
416 }
417 
418 inline void
419 CelestialToCwb(double ilongitude, double ilatitude, double& olongitude, double& olatitude, double gps=0)
420 {
421  skymap sm;
422  olongitude = gps>0 ? sm.RA2phi(ilongitude, gps) : ilongitude;
423  olongitude = 360-olongitude;
424  olatitude=-(ilatitude-90);
425 }
426 
427 #endif
wavearray< double > t(hp.size())
void EquatorialToEcliptic(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:156
static double g(double e)
Definition: GNGen.cc:98
tuple f
Definition: cwb_online.py:91
void CwbToCelestial(double ilongitude, double ilatitude, double &olongitude, double &olatitude, double gps=0)
Definition: skycoord.hh:410
wavearray< double > a(hp.size())
WSeries< float > v[nIFO]
Definition: cwb_net.C:62
int n
Definition: cwb_net.C:10
#define LAL_EARTHFLAT
Definition: skycoord.hh:18
wavearray< double > z
Definition: Test10.C:32
double olatitude
#define LAL_LGAL
Definition: skycoord.hh:14
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
#define LAL_IEARTH
Definition: skycoord.hh:15
double ilatitude
STL namespace.
double olongitude
int j
Definition: cwb_net.C:10
i drho i
double pi
Definition: TestChirp.C:18
wavearray< double > w
Definition: Test1.C:27
#define LAL_HSERIES
Definition: skycoord.hh:19
float phi
wavearray< double > h
Definition: Regression_H1.C:25
double deg2rad
void GeocentricToGeodetic(double X, double Y, double Z, double &latitude, double &longitude, double &elevation)
Definition: skycoord.hh:289
double Pi
TF1 * f2
Definition: cbc_plots.C:1710
int k
double RA2phi(double ph, double gps)
Definition: skymap.hh:195
void EclipticToEquatorial(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:115
Definition: skymap.hh:45
double e
void EquatorialToGalactic(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:72
double phi2RA(double ph, double gps)
Definition: skymap.hh:194
regression r
Definition: Regression_H1.C:44
s s
Definition: cwb_net.C:137
#define LAL_REARTH_SI
Definition: skycoord.hh:17
double rad2deg
void CelestialToCwb(double ilongitude, double ilatitude, double &olongitude, double &olatitude, double gps=0)
Definition: skycoord.hh:419
double gps
double ilongitude
void GeodeticToGeocentric(double latitude, double longitude, double elevation, double &X, double &Y, double &Z)
Definition: skycoord.hh:197
double fabs(const Complex &x)
Definition: numpy.cc:37
#define LAL_ALPHAGAL
Definition: skycoord.hh:13
void CwbToGeographic(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:396
void HeapSort(double *data, double length)
Definition: skycoord.hh:240
int l
Definition: cbc_plots.C:434
void GalacticToEquatorial(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:29
void GeographicToCwb(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:403
void GetCartesianComponents(double u[3], double Alt, double Az, double Lat, double Lon)
Definition: skycoord.hh:369
double length
Definition: TestBandPass.C:18
wavearray< double > y
Definition: Test10.C:31
#define LAL_DELTAGAL
Definition: skycoord.hh:12