1 |
mocchiut |
1.1 |
#include <iostream> |
2 |
|
|
#include <stdio.h> |
3 |
|
|
#include <TObject.h> |
4 |
|
|
#include <TString.h> |
5 |
|
|
#include <TMatrixD.h> |
6 |
|
|
|
7 |
|
|
#include <OrientationInfo.h> |
8 |
|
|
|
9 |
|
|
ClassImp(OrientationInfo) |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
using namespace std; |
13 |
|
|
|
14 |
|
|
OrientationInfo::OrientationInfo() : TObject(){ |
15 |
|
|
a = 360/(2*TMath::Pi()); |
16 |
|
|
Re = 6000000; |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
OrientationInfo::~OrientationInfo(){ |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
TMatrixD OrientationInfo::QuatoECI(Float_t q0, Float_t q1, Float_t q2, Float_t q3){ |
23 |
|
|
TMatrixD Pij(3,3); |
24 |
|
|
Pij(0,0) = pow(q0,2)+pow(q1,2)-pow(q2,2)-pow(q3,2); |
25 |
|
|
Pij(0,1) = /*2*(q1*q2+q0*q3);/*/ 2*(q1*q2-q0*q3); |
26 |
|
|
Pij(0,2) = /*2*(q1*q3-q0*q2);/*/ 2*(q1*q3+q0*q2); |
27 |
|
|
Pij(1,0) = /*2*(q1*q2-q0*q3);/*/ 2*(q1*q2+q0*q3); |
28 |
|
|
Pij(1,1) = pow(q0,2)-pow(q1,2)+pow(q2,2)-pow(q3,2); |
29 |
|
|
Pij(1,2) = /*2*(q2*q3+q0*q1);/*/ 2*(q2*q3-q0*q1); |
30 |
|
|
Pij(2,0) = /*2*(q1*q3+q0*q2);/*/ 2*(q1*q3-q0*q2); |
31 |
|
|
Pij(2,1) = /*2*(q2*q3-q0*q1);/*/ 2*(q2*q3+q0*q1); |
32 |
|
|
Pij(2,2) = pow(q0,2)-pow(q1,2)-pow(q2,2)+pow(q3,2); |
33 |
|
|
return Pij; |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
TMatrixD OrientationInfo::ECItoGreenwich(TMatrixD Aij, UInt_t t){ |
37 |
|
|
TMatrixD Gij(3,3); |
38 |
pam-mep |
1.2 |
Double_t omg = (7.292115e-5)*a; // Earth rotation velosity (Around polar axis); |
39 |
mocchiut |
1.1 |
Double_t d = (t-10957*86400-43200); //Number of day, passing from 01/01/2000 12:00:00 to t; |
40 |
|
|
d = d/86400; |
41 |
|
|
Double_t T = d/36525; //Number of Julian centuries; |
42 |
|
|
|
43 |
|
|
Double_t Se = 6*3600+41*60+236.555367908*d+0.093104*pow(T,2)-(6.2e-6)*pow(T,3); |
44 |
pam-mep |
1.2 |
|
45 |
mocchiut |
1.1 |
Int_t tr = (t-10957*86400)%86400; |
46 |
pam-mep |
1.2 |
|
47 |
mocchiut |
1.1 |
Double_t Somg = (Se+49.077+omg*86400*tr/360)*360/86400; |
48 |
pam-mep |
1.2 |
|
49 |
|
|
//Somg = 25; //for test transition |
50 |
|
|
|
51 |
mocchiut |
1.1 |
Gij(0,0) = cos(Somg/a); |
52 |
|
|
Gij(0,1) = -sin(Somg/a); |
53 |
|
|
Gij(0,2) = 0; |
54 |
|
|
Gij(1,0) = sin(Somg/a); |
55 |
|
|
Gij(1,1) = cos(Somg/a); |
56 |
|
|
Gij(1,2) = 0; |
57 |
|
|
Gij(2,0) = 0; |
58 |
|
|
Gij(2,1) = 0; |
59 |
|
|
Gij(2,2) = 1; |
60 |
|
|
Gij.Invert(); |
61 |
|
|
return Gij*Aij; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
TMatrixD OrientationInfo::GreenwichtoGEO(Double_t lat, Double_t lon, TMatrixD Aij){ |
65 |
pam-mep |
1.2 |
|
66 |
mocchiut |
1.1 |
TMatrixD Gij(3,3); |
67 |
|
|
TMatrixD Fij(3,3); |
68 |
|
|
|
69 |
pam-mep |
1.2 |
lon=(-lon)/a; lat=(-lat)/a; // here has the same result as Gij.Invert() in ECItoGreenwich function |
70 |
|
|
|
71 |
|
|
Gij(0,0) = cos(lon); // rotation around z-axis: |
72 |
mocchiut |
1.1 |
Gij(0,1) = -sin(lon); |
73 |
pam-mep |
1.2 |
Gij(0,2) = 0; // | cos(lon) -sin(lon) 0| |
74 |
|
|
Gij(1,0) = sin(lon); // | sin(lon) cos(lon) 0| |
75 |
|
|
Gij(1,1) = cos(lon); // | 0 0 1| |
76 |
mocchiut |
1.1 |
Gij(1,2) = 0; |
77 |
|
|
Gij(2,0) = 0; |
78 |
|
|
Gij(2,1) = 0; |
79 |
|
|
Gij(2,2) = 1; |
80 |
|
|
|
81 |
pam-mep |
1.2 |
Fij(0,0) = cos(lat); // rotation around y-axis at angle -lat, cause rotation around y from x to z axis is negative |
82 |
|
|
Fij(0,1) = 0; // |
83 |
|
|
Fij(0,2) = -sin(lat); // |cos(-lat) 0 sin(-lat)| |cos(lat) 0 -sin(lat)| |
84 |
|
|
Fij(1,0) = 0; // | 0 1 0 | ==> | 0 1 0 | |
85 |
|
|
Fij(1,1) = 1; // |-sin(-lat) 0 cos(-lat)| |sin(lat) 0 cos(lat) | |
86 |
mocchiut |
1.1 |
Fij(1,2) = 0; |
87 |
|
|
Fij(2,0) = sin(lat); |
88 |
|
|
Fij(2,1) = 0; |
89 |
|
|
Fij(2,2) = cos(lat); |
90 |
pam-mep |
1.2 |
|
91 |
mocchiut |
1.1 |
return Fij*(Gij*Aij); |
92 |
|
|
} |
93 |
|
|
|
94 |
pam-mep |
1.2 |
TMatrixD OrientationInfo::GEOtoGeomag(TMatrixD Aij,Double_t Bnorth, Double_t Beast, Double_t Bup){ //Geomagnetic geodetic reference frame |
95 |
|
|
Double_t alpha = 0; |
96 |
|
|
if(Beast==0. && Bnorth>0) alpha = 0; else |
97 |
|
|
if(Beast==0. && Bnorth<0) alpha = 180.; else{ |
98 |
|
|
if(Beast > 0) alpha = TMath::ATan(Bnorth/Beast)*TMath::RadToDeg() - 90.; |
99 |
|
|
if(Beast < 0) alpha = TMath::ATan(Bnorth/Beast)*TMath::RadToDeg() + 90.; |
100 |
|
|
} |
101 |
|
|
alpha = alpha*TMath::DegToRad(); |
102 |
|
|
Double_t beta = TMath::ATan(Bup/sqrt(pow(Bnorth,2)+pow(Beast,2))); |
103 |
|
|
//if(Bup<0.0) beta = TMath::ATan(TMath::Abs(Bup/sqrt(pow(Bnorth,2)+pow(Beast,2)))); |
104 |
|
|
//if(Bup>0.0) beta = TMath::ATan(TMath::Abs(sqrt(pow(Bnorth,2)+pow(Beast,2))/Bup)); |
105 |
|
|
//cout<<"GEOtomag:alpha = "<<alpha*TMath::RadToDeg()<<"\tbeta = "<<beta*TMath::RadToDeg()<<endl; |
106 |
|
|
TMatrixD Gij(3,3); |
107 |
|
|
TMatrixD Fij(3,3); |
108 |
|
|
Gij(0,0) = 1; //rotation around x-axis at angle alpha |
109 |
|
|
Gij(0,1) = 0; |
110 |
|
|
Gij(0,2) = 0; // |1 0 0 | |
111 |
|
|
Gij(1,0) = 0; // |0 cos(alpha) -sin(alpha) | |
112 |
|
|
Gij(1,1) = cos(alpha); // |0 sin(alpha) cos(alpha) | |
113 |
|
|
Gij(1,2) = -sin(alpha); |
114 |
|
|
Gij(2,0) = 0; |
115 |
|
|
Gij(2,1) = sin(alpha); |
116 |
|
|
Gij(2,2) = cos(alpha); |
117 |
|
|
Gij.Invert(); |
118 |
|
|
Fij(0,0) = cos(beta); //rotation around y-axis at angle beta |
119 |
|
|
Fij(0,1) = 0; |
120 |
|
|
Fij(0,2) = sin(beta); // |cos(beta) 0 sin(beta)| |
121 |
|
|
Fij(1,0) = 0; // | 0 1 0 | |
122 |
|
|
Fij(1,1) = 1; // |-sin(beta) 0 cos(beta)| |
123 |
|
|
Fij(1,2) = 0; |
124 |
|
|
Fij(2,0) = -sin(beta); |
125 |
|
|
Fij(2,1) = 0; |
126 |
|
|
Fij(2,2) = cos(beta); |
127 |
|
|
Fij.Invert(); |
128 |
|
|
//Int_t tri; |
129 |
|
|
//cin >> tri; |
130 |
|
|
return Fij*(Gij*Aij); |
131 |
|
|
} |
132 |
|
|
|
133 |
mocchiut |
1.1 |
TMatrixD OrientationInfo::PamelatoGEO(TMatrixD Aij, Double_t B1, Double_t B2, Double_t B3){ |
134 |
|
|
//TMatrixD Gij(3,3); |
135 |
|
|
TMatrixD Hij(3,1); |
136 |
|
|
TMatrixD Bij(3,1); |
137 |
|
|
Bij(0,0) = B1; |
138 |
|
|
Bij(1,0) = B2; |
139 |
|
|
Bij(2,0) = B3; |
140 |
|
|
Hij=Aij*Bij; |
141 |
|
|
return Hij; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
TMatrixD OrientationInfo::ColPermutation(TMatrixD Aij){ |
145 |
|
|
TMatrixD Gij(3,3); |
146 |
|
|
Gij(0,0) = 1; Gij(0,1) = 0; Gij(0,2) = 0; |
147 |
|
|
Gij(1,0) = 0; Gij(1,1) = 0; Gij(1,2) = 1; |
148 |
|
|
Gij(2,0) = 0; Gij(2,1) = -1; Gij(2,2) = 0; |
149 |
|
|
return Aij*Gij; |
150 |
|
|
} |
151 |
|
|
|
152 |
pam-mep |
1.2 |
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 |
153 |
|
|
Float_t mp = 938.272029; Float_t amu = 931.494043e0; |
154 |
|
|
Float_t cc = 299792458.; |
155 |
|
|
Float_t ee = 1.60217653e-19; |
156 |
|
|
Float_t kg = 1.7826619e-30; |
157 |
|
|
Float_t gam = (Ek+mp)/mp; |
158 |
|
|
Float_t mm = mp*kg; |
159 |
|
|
Float_t omega = iZ*ee*Bm*1e-9/(gam*mm); |
160 |
|
|
Float_t larmor = 1e-3*sqrt(1e0-1e0/pow(gam,2))*cc/omega; |
161 |
|
|
larmor = 1e-3*Ek*cc/omega; //Ek here is p or for onecharged particle R; |
162 |
|
|
return larmor; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
TMatrixD OrientationInfo::GetDirectiontoGirocenter(Float_t R, Float_t Px, Float_t Py){ |
166 |
|
|
TMatrixD GirDir(3,1); |
167 |
|
|
if(R>0){ |
168 |
|
|
GirDir(0,0) = Py; |
169 |
|
|
GirDir(1,0) = -Px; |
170 |
|
|
}else{ |
171 |
|
|
GirDir(0,0) = -Py; |
172 |
|
|
GirDir(1,0) = Px; |
173 |
|
|
} |
174 |
|
|
GirDir(2,0) = 0.; |
175 |
|
|
return GirDir; |
176 |
|
|
} |
177 |
|
|
|
178 |
mocchiut |
1.1 |
Double_t OrientationInfo::GetPitchAngle(Double_t x1, Double_t y1, Double_t z1, Double_t x2, Double_t y2, Double_t z2){ |
179 |
|
|
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(); |
180 |
|
|
} |