source: trunk/WuerzburgSoft/Thomas/mphys/MParticle.cc@ 1365

Last change on this file since 1365 was 1365, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.6 KB
Line 
1///////////////////////////////////////////////////////////////////////
2//
3// MParticle
4//
5///////////////////////////////////////////////////////////////////////
6
7#include "MParticle.h"
8
9#include <TRandom.h>
10#include <TMatrixD.h>
11
12ClassImp(MParticle);
13
14/**************************************************
15 *
16 * H0 = 50./3.0857e19; // [km / Mpc s] --> [s^-1]
17 *
18 **************************************************/
19
20Double_t MParticle::ZofR(Double_t *x, Double_t *k)
21{
22 /*
23 const Double_t c = 299792458; // [m/s]
24 const Double_t H0 = 50./3.0857e19; // [km / Mpc s] --> [s^-1]
25
26 const Double_t ly = 3600.*24.*365.*c; // [m/ly]
27 const Double_t pc = 1./3.258; // [pc/ly]
28 const Double_t r = x[0] /pc*ly*1e3; // [m]
29
30 const Double_t R = r*H0/c; // [1]
31
32 return (R+1+sqrt(R*2+1))/2 - 1;
33 */
34 const Double_t c = 299792458; // [m/s]
35 const Double_t H0 = 50./3.0857e19; // [km / Mpc s] --> [s^-1]
36
37 const Double_t ly = 3600.*24.*365.*c; // [m/ly]
38 const Double_t pc = 1./3.258; // [pc/ly]
39 const Double_t r = x[0] /pc*ly*1e3; // [m]
40
41 const Double_t R = 1./(1-r*H0/c/2); // [1]
42
43 return R*R - 1;
44}
45
46Double_t MParticle::RofZ(Double_t *x, Double_t *k)
47{
48 /*
49 Double_t z1 = x[0] + 1;
50
51 const Double_t c = 299792458; // [m/s]
52 const Double_t H0 = 50./3.0857e19; // [km / Mpc s] --> [s^-1]
53
54 const Double_t ly = 3600.*24.*365.*c; // [m/ly]
55 const Double_t pc = 1./3.258; // [pc/ly]
56
57 const Double_t R = c/H0 * 2 * (z1 - sqrt(z1)); // [m]
58
59 return R * pc/ly/1e3; // [kpc]
60 */
61 Double_t z1 = x[0] + 1;
62
63 const Double_t c = 299792458; // [m/s]
64 const Double_t H0 = 50./3.0857e19; // [km / Mpc s] --> [s^-1]
65
66 const Double_t ly = 3600.*24.*365.*c; // [m/ly]
67 const Double_t pc = 1./3.258; // [pc/ly]
68
69 const Double_t R = c/H0 * 2 * (1 - 1./sqrt(z1)); // [m]
70
71 return R * pc/ly/1e3; // [kpc]
72}
73
74Double_t MParticle::Planck(Double_t *x, Double_t *k)
75{
76 //
77 // Planck, per unit volume, per unit energy
78 //
79 // constants (see below) moved out of function
80 //
81 const Double_t E = x[0]; // [GeV]
82 const Double_t z = k ? k[0] : 0;
83
84 const Double_t T = 2.96*(z+1); // [K]
85 const Double_t e = 1.602176462e-19; // [C]
86 const Double_t kB = 1e-9/e*1.3806503e-23; // [GeV/K]
87
88 const Double_t EkT = E/kB/T;
89
90 /*
91 //Double_t c = 299792458; // [m/s]
92 //Double_t h = 1e-9/e*6.62606876e-34; // [GeVs]
93 //Double_t hc = h*c; // [GeVm]
94 Double_t konst = 4.*TMath::Pi() * 2. / (hc*hc*hc);
95 return konst * E*E / (exp(EkT)-1.); // [1 / GeV / m^3 ]
96 */
97
98 return E*E / (exp(EkT)-1.); // [GeV^2]
99}
100
101MParticle::MParticle(ParticleType_t t, const char *name, const char *title)
102 : fPType(t), fZ(0), fR(0), fPhi(0), fTheta(0), fPsi(0)
103{
104 //
105 // default constructor
106 //
107}
108
109void MParticle::SetNewDirection(Double_t theta, Double_t phi)
110{
111 TMatrixD B(3, 3);
112
113 B(0, 0) = cos(fTheta)*cos(fPsi);
114 B(1, 0) = cos(fTheta)*sin(fPsi);
115 B(2, 0) = -sin(fTheta);
116
117 B(0, 1) = -sin(fPsi);
118 B(1, 1) = cos(fPsi);
119 B(2, 1) = 0;
120
121 B(0, 2) = sin(fTheta)*cos(fPsi);
122 B(1, 2) = sin(fTheta)*sin(fPsi);
123 B(2, 2) = cos(fTheta);
124
125 // ------------------------------
126
127 TVectorD r(3);
128
129 r(0) = sin(theta)*cos(phi);
130 r(1) = sin(theta)*sin(phi);
131 r(2) = cos(theta);
132
133 // ------------------------------
134
135 r *= B;
136
137 fTheta = sqrt(r(0)*r(0)+r(1)*r(1)); // Numerically bad: acos(r(2));
138 fPsi = atan2(r(1), r(0));
139
140 /*
141 if (fTheta*2 > TMath::Pi())
142 fTheta = fabs(fTheta-TMath::Pi());
143 */
144}
145
146Bool_t MParticle::SetNewPosition(Double_t dr)
147{
148 Bool_t rc=kTRUE;
149
150 TVectorD x(3);
151
152 x(0) = sin(fTheta)*cos(fPsi);
153 x(1) = sin(fTheta)*sin(fPsi);
154 x(2) = cos(fTheta);
155
156 x *= dr;
157
158 // ------------------------------
159
160 const Double_t R = RofZ(&fZ);
161
162 if (x(2) > R*cos(fTheta))
163 {
164 x *= R/dr;
165 rc = kFALSE;
166 }
167
168 // ------------------------------
169
170 TVectorD r(3);
171
172 r(0) = fR*cos(fPhi);
173 r(1) = fR*sin(fPhi);
174 r(2) = R;
175
176 // ------------------------------
177
178 r -= x;
179
180 fR = sqrt(r(0)*r(0)+r(1)*r(1));
181 fPhi = atan2(r(1), r(0));
182 fZ = ZofR(&r(2));
183
184 return rc;
185}
186
187Bool_t MParticle::SetNewPosition()
188{
189 static TRandom rand(0);
190 Double_t r = rand.Exp(GetInteractionLength());
191 return SetNewPosition(r);
192}
Note: See TracBrowser for help on using the repository browser.