/[PAMELA software]/DarthVader/OrbitalInfo/src/OrientationInfo.cpp
ViewVC logotype

Contents of /DarthVader/OrbitalInfo/src/OrientationInfo.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Fri Mar 28 20:47:15 2014 UTC (10 years, 8 months ago) by pam-mep
Branch: MAIN
Changes since 1.3: +176 -1 lines
new OrbitalInfo code

1 #include <iostream>
2 #include <stdio.h>
3 #include <TObject.h>
4 #include <TString.h>
5 #include <TMatrixD.h>
6 #include <TVector3.h>
7
8 #include <OrientationInfo.h>
9
10 ClassImp(OrientationInfo)
11
12
13 using namespace std;
14
15 OrientationInfo::OrientationInfo() : TObject(){
16 a = 360/(2*TMath::Pi());
17 Re = 6000000;
18 }
19
20 OrientationInfo::~OrientationInfo(){
21 }
22
23 TMatrixD OrientationInfo::QuatoECI(Float_t q0, Float_t q1, Float_t q2, Float_t q3){
24 TMatrixD Pij(3,3);
25 Pij(0,0) = pow(q0,2)+pow(q1,2)-pow(q2,2)-pow(q3,2);
26 Pij(0,1) = /*2*(q1*q2+q0*q3);/*/ 2*(q1*q2-q0*q3);
27 Pij(0,2) = /*2*(q1*q3-q0*q2);/*/ 2*(q1*q3+q0*q2);
28 Pij(1,0) = /*2*(q1*q2-q0*q3);/*/ 2*(q1*q2+q0*q3);
29 Pij(1,1) = pow(q0,2)-pow(q1,2)+pow(q2,2)-pow(q3,2);
30 Pij(1,2) = /*2*(q2*q3+q0*q1);/*/ 2*(q2*q3-q0*q1);
31 Pij(2,0) = /*2*(q1*q3+q0*q2);/*/ 2*(q1*q3-q0*q2);
32 Pij(2,1) = /*2*(q2*q3-q0*q1);/*/ 2*(q2*q3+q0*q1);
33 Pij(2,2) = pow(q0,2)-pow(q1,2)-pow(q2,2)+pow(q3,2);
34 return Pij;
35 }
36
37 TMatrixD OrientationInfo::ECItoGreenwich(TMatrixD Aij, UInt_t t){
38 TMatrixD Gij(3,3);
39 Double_t omg = (7.292115e-5)*a; // Earth rotation velosity (Around polar axis);
40 Double_t d = (t-10957*86400-43200); //Number of day, passing from 01/01/2000 12:00:00 to t;
41 d = d/86400;
42 Double_t T = d/36525; //Number of Julian centuries;
43
44 Double_t Se = 6*3600+41*60+236.555367908*d+0.093104*pow(T,2)-(6.2e-6)*pow(T,3);
45
46 Int_t tr = (t-10957*86400)%86400;
47
48 Double_t Somg = (Se+49.077+omg*86400*tr/360)*360/86400;
49
50 //Somg = 25; //for test transition
51
52 Gij(0,0) = cos(Somg/a);
53 Gij(0,1) = -sin(Somg/a);
54 Gij(0,2) = 0;
55 Gij(1,0) = sin(Somg/a);
56 Gij(1,1) = cos(Somg/a);
57 Gij(1,2) = 0;
58 Gij(2,0) = 0;
59 Gij(2,1) = 0;
60 Gij(2,2) = 1;
61 Gij.Invert();
62 return Gij*Aij;
63 }
64
65 TMatrixD OrientationInfo::GreenwichtoGEO(Double_t lat, Double_t lon, TMatrixD Aij){
66
67 TMatrixD Gij(3,3);
68 TMatrixD Fij(3,3);
69
70 lon=(-lon)/a; lat=(-lat)/a; // here has the same result as Gij.Invert() in ECItoGreenwich function
71
72 Gij(0,0) = cos(lon); // rotation around z-axis:
73 Gij(0,1) = -sin(lon);
74 Gij(0,2) = 0; // | cos(lon) -sin(lon) 0|
75 Gij(1,0) = sin(lon); // | sin(lon) cos(lon) 0|
76 Gij(1,1) = cos(lon); // | 0 0 1|
77 Gij(1,2) = 0;
78 Gij(2,0) = 0;
79 Gij(2,1) = 0;
80 Gij(2,2) = 1;
81
82 Fij(0,0) = cos(lat); // rotation around y-axis at angle -lat, cause rotation around y from x to z axis is negative
83 Fij(0,1) = 0; //
84 Fij(0,2) = -sin(lat); // |cos(-lat) 0 sin(-lat)| |cos(lat) 0 -sin(lat)|
85 Fij(1,0) = 0; // | 0 1 0 | ==> | 0 1 0 |
86 Fij(1,1) = 1; // |-sin(-lat) 0 cos(-lat)| |sin(lat) 0 cos(lat) |
87 Fij(1,2) = 0;
88 Fij(2,0) = sin(lat);
89 Fij(2,1) = 0;
90 Fij(2,2) = cos(lat);
91
92 return Fij*(Gij*Aij);
93 }
94
95 TMatrixD OrientationInfo::EulertoEci(Double_t x0, Double_t y0, Double_t z0, Double_t Vx0, Double_t Vy0, Double_t Vz0, Double_t Bank, Double_t Yaw, Double_t SPitch){
96 //cerr.precision(12);
97 //cerr<<"Position:\t"<<x0<<"\t"<<y0<<"\t"<<z0<<"\tVelocity:\t"<<Vx0<<"\t"<<Vy0<<"\t"<<Vz0<<endl;
98 //Sangur to Resurs transition
99 TMatrixD Zij(3,3);
100 Zij(0,0) = 0.0; Zij(0,1) = 0.0; Zij(0,2) = -1.0;
101 Zij(1,0) = -1.0; Zij(1,1) = 0.0; Zij(1,2) = 0.0;
102 Zij(2,0) = 0.0; Zij(2,1) = 1.0; Zij(2,2) = 0.0;
103
104 //Spacecraft velosity referenca frame in Eci
105 TMatrixD Aij(3,3);
106 Double_t C1 = y0*Vz0 - z0*Vy0;
107 Double_t C2 = z0*Vx0 - x0*Vz0;
108 Double_t C3 = x0*Vy0 - y0*Vx0;
109 Double_t C = sqrt(C1*C1 + C2*C2 + C3*C3);
110 Double_t V0 = sqrt(Vx0*Vx0+Vy0*Vy0 + Vz0*Vz0);
111 Aij(0,0) = Vx0/V0; Aij(0,1) = C1/C; Aij(0,2) = (Vy0*C3-Vz0*C2)/(V0*C);
112 Aij(1,0) = Vy0/V0; Aij(1,1) = C2/C; Aij(1,2) = (Vz0*C1-Vx0*C3)/(V0*C);
113 Aij(2,0) = Vz0/V0; Aij(2,1) = C3/C; Aij(2,2) = (Vx0*C2-Vy0*C1)/(V0*C);
114
115 //Elements of matrix elements described orientation of spacecraft on velocity reference frame
116 Double_t u10 = tan(Bank*TMath::DegToRad())/sqrt(tan(Bank*TMath::DegToRad())*tan(Bank*TMath::DegToRad())+1);
117 Double_t u11 = -sqrt((1-u10*u10))/(1+tan(Yaw*TMath::DegToRad())*tan(Yaw*TMath::DegToRad()));
118 Double_t u12 = u11*tan(Yaw*TMath::DegToRad());
119 Double_t u20 = -sqrt((1-u10*u10)/(1+tan(SPitch*TMath::DegToRad())*tan(SPitch*TMath::DegToRad())));
120 Double_t u00 = -u20*tan(SPitch*TMath::DegToRad());
121
122 Double_t ab = 1+(u20*u20/(u00*u00));
123 Double_t by = 2*u10*u11*u20/(u00*u00);
124 Double_t cy = (1+u10*u10/(u00*u00))*u11*u11-1;
125 Double_t bz = 2*u10*u12*u20/(u00*u00);
126 Double_t cz = (1+u10*u10/(u00*u00))*u12*u12-1;
127
128 Int_t uj = TMath::Sign(1.,Yaw)*TMath::Sign(1.,SPitch);
129 //long double by_l = by;
130 Double_t Ds = by*by-4*ab*cy;
131 if(Ds<0) Ds = 0.;
132 Double_t u21 = (-by+uj*sqrt(Ds))/(2*ab);
133 Double_t u21s = -TMath::Sign(1.,Bank)*TMath::Abs(u21);
134 Double_t u01 = TMath::Sign(1.,Yaw)*TMath::Abs((u10*u11+u20*u21)/u00);
135 // cerr<<"by = " << by<<"\tuj"<<uj<<"\tab: "<<ab<<"\t"<<by*by-4*ab*cy<<endl;
136 // cerr<<"u21: "<<u21<<"\tu01: "<<u01<<"\t"<<TMath::Abs((u10*u11+u20*u21)/u00)<<"\t"<<TMath::Sign(1.,Yaw)<<"\t"<<(u10*u11+u20*u21)<<endl;
137 Int_t fj=1;
138 if(TMath::Sign(1.,SPitch)>0 && TMath::Sign(1.,Yaw)>0) fj=-1;
139 // cout<<"bla-bla-bla"<<endl;
140
141 Double_t u22 = (-bz+fj*sqrt(bz*bz-4*ab*cz))/(2*ab);
142 Double_t u22s = -TMath::Sign(1.,SPitch)*TMath::Abs(u22);
143 Double_t u02 = -TMath::Abs((u10*u12+u20*u22)/u00);
144
145 // cout<<fj<<"\t"<<ab<<"\t"<<by<<"\t"<<cy<<"\t"<<bz<<"\t"<<cz<<endl;
146 // cout<<"INSIDE EULERTOECI"<<endl;
147 // cout<<u00<<"\t"<<u01<<"\t"<<u02<<endl;
148 // cout<<u10<<"\t"<<u11<<"\t"<<u12<<endl;
149 // cout<<u20<<"\t"<<u21s<<"\t"<<u22s<<endl;
150
151 TMatrixD Dij(3,3);
152 Dij(0,0) = u00; Dij(0,1) = u01; Dij(0,2) = u02;
153 Dij(1,0) = u10; Dij(1,1) = u11; Dij(1,2) = u12;
154 Dij(2,0) = u20; Dij(2,1) = u21s; Dij(2,2) = u22s;
155
156 TMatrixD Shij(3,3);
157 TMatrixD Usij(3,3);
158 Usij = (Aij*Dij);
159 Usij.Invert();
160 Shij = Zij*Usij;
161 Shij.Invert();
162
163 return Shij;
164 }
165
166 TMatrixD OrientationInfo::ECItoGEO(TMatrixD Aij, UInt_t t, Double_t lat, Double_t lon){
167 TMatrixD Gij(3,3);
168 Double_t omg = (7.292115e-5)*a; // Earth rotation velosity (Around polar axis);
169 Double_t d = (t-10957*86400-43200); //Number of day, passing from 01/01/2000 12:00:00 to t;
170 d = d/86400;
171 Double_t T = d/36525; //Number of Julian centuries;
172
173 Double_t Se = 6*3600+41*60+236.555367908*d+0.093104*pow(T,2)-(6.2e-6)*pow(T,3);
174
175 Int_t tr = (t-10957*86400)%86400;
176
177 Double_t Somg = (Se+49.077+omg*86400*tr/360)*360/86400;
178
179 lon=(-lon)/a; lat=(-lat)/a;
180
181 Gij(0,0)=cos(lat)*cos(lon)*cos(Somg/a)+cos(lat)*sin(lon)*sin(Somg/a);
182 Gij(0,1)=cos(lat)*cos(lon)*sin(Somg/a)-cos(lat)*sin(lon)*cos(Somg/a);
183 Gij(0,2)=-sin(lat);
184 Gij(1,0)=sin(lon)*cos(Somg/a)-cos(lon)*sin(Somg/a);
185 Gij(1,1)=sin(lon)*sin(Somg/a)+cos(lon)*cos(Somg/a);
186 Gij(1,2)=0;
187 Gij(2,0)=sin(lat)*cos(lon)*cos(Somg/a)+sin(lat)*sin(lon)*sin(Somg/a);
188 Gij(2,1)=sin(lat)*cos(lon)*sin(Somg/a)-sin(lat)*sin(lon)*cos(Somg/a);
189 Gij(2,2)=cos(lat);
190
191 TMatrixD Tij=Gij*Aij;
192
193 return Tij;
194 }
195
196 TMatrixD OrientationInfo::GEOtoECI(TMatrixD Aij, UInt_t t, Double_t lat, Double_t lon){
197 TMatrixD Gij(3,3);
198 Double_t omg = (7.292115e-5)*a; // Earth rotation velosity (Around polar axis);
199 Double_t d = (t-10957*86400-43200); //Number of day, passing from 01/01/2000 12:00:00 to t;
200 d = d/86400;
201 Double_t T = d/36525; //Number of Julian centuries;
202
203 Double_t Se = 6*3600+41*60+236.555367908*d+0.093104*pow(T,2)-(6.2e-6)*pow(T,3);
204
205 Int_t tr = (t-10957*86400)%86400;
206
207 Double_t Somg = (Se+49.077+omg*86400*tr/360)*360/86400;
208
209 lon=(-lon)/a; lat=(-lat)/a;
210
211 Gij(0,0)=cos(lat)*cos(lon)*cos(Somg/a)+cos(lat)*sin(lon)*sin(Somg/a);
212 Gij(1,0)=cos(lat)*cos(lon)*sin(Somg/a)-cos(lat)*sin(lon)*cos(Somg/a);
213 Gij(2,0)=-sin(lat);
214 Gij(0,1)=sin(lon)*cos(Somg/a)-cos(lon)*sin(Somg/a);
215 Gij(1,1)=sin(lon)*sin(Somg/a)+cos(lon)*cos(Somg/a);
216 Gij(2,1)=0;
217 Gij(0,2)=sin(lat)*cos(lon)*cos(Somg/a)+sin(lat)*sin(lon)*sin(Somg/a);
218 Gij(1,2)=sin(lat)*cos(lon)*sin(Somg/a)-sin(lat)*sin(lon)*cos(Somg/a);
219 Gij(2,2)=cos(lat);
220
221 return Gij*Aij;
222 }
223
224
225 TMatrixD OrientationInfo::GEOtoGeomag(TMatrixD Aij,Double_t Bnorth, Double_t Beast, Double_t Bup){ //Geomagnetic geodetic reference frame
226 Double_t alpha = 0;
227 if(Beast==0. && Bnorth>0) alpha = 0; else
228 if(Beast==0. && Bnorth<0) alpha = 180.; else{
229 if(Beast > 0) alpha = TMath::ATan(Bnorth/Beast)*TMath::RadToDeg() - 90.;
230 if(Beast < 0) alpha = TMath::ATan(Bnorth/Beast)*TMath::RadToDeg() + 90.;
231 }
232 alpha = alpha*TMath::DegToRad();
233 Double_t beta = TMath::ATan(Bup/sqrt(pow(Bnorth,2)+pow(Beast,2)));
234 //if(Bup<0.0) beta = TMath::ATan(TMath::Abs(Bup/sqrt(pow(Bnorth,2)+pow(Beast,2))));
235 //if(Bup>0.0) beta = TMath::ATan(TMath::Abs(sqrt(pow(Bnorth,2)+pow(Beast,2))/Bup));
236 //cout<<"GEOtomag:alpha = "<<alpha*TMath::RadToDeg()<<"\tbeta = "<<beta*TMath::RadToDeg()<<endl;
237 TMatrixD Gij(3,3);
238 TMatrixD Fij(3,3);
239 Gij(0,0) = 1; //rotation around x-axis at angle alpha
240 Gij(0,1) = 0;
241 Gij(0,2) = 0; // |1 0 0 |
242 Gij(1,0) = 0; // |0 cos(alpha) -sin(alpha) |
243 Gij(1,1) = cos(alpha); // |0 sin(alpha) cos(alpha) |
244 Gij(1,2) = -sin(alpha);
245 Gij(2,0) = 0;
246 Gij(2,1) = sin(alpha);
247 Gij(2,2) = cos(alpha);
248 Gij.Invert();
249 Fij(0,0) = cos(beta); //rotation around y-axis at angle beta
250 Fij(0,1) = 0;
251 Fij(0,2) = sin(beta); // |cos(beta) 0 sin(beta)|
252 Fij(1,0) = 0; // | 0 1 0 |
253 Fij(1,1) = 1; // |-sin(beta) 0 cos(beta)|
254 Fij(1,2) = 0;
255 Fij(2,0) = -sin(beta);
256 Fij(2,1) = 0;
257 Fij(2,2) = cos(beta);
258 Fij.Invert();
259 //Int_t tri;
260 //cin >> tri;
261 return Fij*(Gij*Aij);
262 }
263
264 TMatrixD OrientationInfo::PamelatoGEO(TMatrixD Aij, Double_t B1, Double_t B2, Double_t B3){
265 //TMatrixD Gij(3,3);
266 TMatrixD Hij(3,1);
267 TMatrixD Bij(3,1);
268 Bij(0,0) = B1;
269 Bij(1,0) = B2;
270 Bij(2,0) = B3;
271 Hij=Aij*Bij;
272 return Hij;
273 }
274
275 TMatrixD OrientationInfo::ColPermutation(TMatrixD Aij){
276 TMatrixD Gij(3,3);
277 Gij(0,0) = 1; Gij(0,1) = 0; Gij(0,2) = 0;
278 Gij(1,0) = 0; Gij(1,1) = 0; Gij(1,2) = 1;
279 Gij(2,0) = 0; Gij(2,1) = -1; Gij(2,2) = 0;
280 return Aij*Gij;
281 }
282
283 TVector3 OrientationInfo::GetSunPosition(UInt_t atime){
284 TVector3 sunout;
285 Float_t JD=atime/86400.+2440587.5;
286 //SAV
287 // cout << "JD = " << JD <<endl;
288 //SAV
289 //test June 1997 JD=2451545.0-877.047;
290 Float_t Tm = (JD - 2451545.0)/36525.;
291 Float_t Mo = (357.52910+35999.05030*Tm-0.0001559*Tm*Tm-0.00000048*Tm*Tm*Tm);
292 //SAV
293 // cout<<"Tm = " << Tm << "Mo = " << Mo <<endl;
294 //SAV
295 Mo=Mo*TMath::DegToRad();
296
297 Float_t Co = ((1.914600 - 0.004817*Tm - 0.00014*Tm*Tm)*sin(Mo) + (0.019993 - 0.000101*Tm)* sin(2.*Mo) + 0.000290* sin(3.*Mo));
298 Co=Co* TMath::DegToRad();
299
300 Float_t Lo = (280.46645 + 36000.76983*Tm +0.0003032*Tm*Tm);
301 Lo=Lo*TMath::DegToRad();
302
303 Float_t theta = (Lo + Co); // * TMath::DegToRad();
304
305 Float_t eps = (23.+26./60.+21.448/3600. - 46.8150/3600.*Tm - 0.00059/3600.*Tm*Tm + 0.001813*Tm*Tm*Tm)*TMath::DegToRad();
306
307 //SAV
308 // cout << "Co = " << Co*TMath::RadToDeg() << "\tLo = " << Lo*TMath::RadToDeg() << "\ttheta = " << theta << "\teps = " << eps << endl;
309 //SAV
310
311 Float_t YY=cos(eps)*sin(theta);
312 Float_t XX=cos(theta);
313 //SAV
314 // cout << "XX = " << XX << "\tYY" << YY << endl;
315 //SAV
316 Float_t RASun=atan(YY/XX);
317 if(XX<0. ) RASun=RASun+TMath::Pi();
318 if(XX >0. && YY <0.) RASun=RASun+2*TMath::Pi();
319 Float_t DESun = asin(sin(eps)*sin(theta));
320 //SAV
321 // cout << "DE = " << DESun << "\t" << RASun << endl;
322 //SAV
323 sunout.SetMagThetaPhi(1.0,TMath::Pi()/2.-DESun,RASun);
324 return sunout;
325 }
326
327 Float_t OrientationInfo::Larmor(Float_t Ek,Float_t Bm,Int_t iZ,Float_t xA){ //Ek in MeV, Bm in nT, Pitch-angle, rad
328 Float_t mp = 938.272029;// Float_t amu = 931.494043e0;
329 Float_t cc = 299792458.;
330 Float_t ee = 1.60217653e-19;
331 Float_t kg = 1.7826619e-30;
332 Float_t gam = (Ek+mp)/mp;
333 Float_t mm = mp*kg;
334 Float_t omega = iZ*ee*Bm*1e-9/(gam*mm);
335 Float_t larmor = 1e-3*sqrt(1e0-1e0/pow(gam,2))*cc/omega;
336 larmor = 1e-3*Ek*cc/omega; //Ek here is p or for onecharged particle R; larmor in m
337 return larmor;
338 }
339
340 TMatrixD OrientationInfo::GetDirectiontoGirocenter(Float_t R, Float_t Px, Float_t Py){
341 TMatrixD GirDir(3,1);
342 if(R>0){
343 GirDir(0,0) = Py;
344 GirDir(1,0) = -Px;
345 }else{
346 GirDir(0,0) = -Py;
347 GirDir(1,0) = Px;
348 }
349 GirDir(2,0) = 0.;
350 return GirDir;
351 }
352
353 Double_t OrientationInfo::GetPitchAngle(Double_t x1, Double_t y1, Double_t z1, Double_t x2, Double_t y2, Double_t z2){
354 return TMath::ACos((x1*x2 + y1*y2 + z1*z2)/(sqrt(pow(x1,2)+pow(y1,2)+pow(z1,2))*sqrt(pow(x2,2)+pow(y2,2)+pow(z2,2)))) * TMath::RadToDeg();
355 }

  ViewVC Help
Powered by ViewVC 1.1.23