1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
|
---|
19 | ! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | // //
|
---|
28 | // //
|
---|
29 | //////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MElectron.h"
|
---|
31 |
|
---|
32 | #include <iostream.h>
|
---|
33 |
|
---|
34 | #include <TF1.h>
|
---|
35 | #include <TH1.h>
|
---|
36 | #include <TMatrixD.h>
|
---|
37 | #include <TVectorD.h>
|
---|
38 |
|
---|
39 | #include <TRandom.h>
|
---|
40 |
|
---|
41 | #include <TPad.h>
|
---|
42 | #include <TCanvas.h>
|
---|
43 |
|
---|
44 | #include "MPhoton.h"
|
---|
45 |
|
---|
46 | ClassImp(MElectron);
|
---|
47 |
|
---|
48 | Double_t MElectron::Li(Double_t *x, Double_t *k)
|
---|
49 | {
|
---|
50 | const Double_t t = x[0];
|
---|
51 | return log(1.-t)/t;
|
---|
52 | }
|
---|
53 |
|
---|
54 | Double_t DiSum(Double_t *x, Double_t *k=NULL)
|
---|
55 | {
|
---|
56 | Double_t t = x[0];
|
---|
57 |
|
---|
58 | const Double_t eps = fabs(t*1e-2);
|
---|
59 |
|
---|
60 | Double_t disum = t;
|
---|
61 | Double_t add = 0;
|
---|
62 |
|
---|
63 | Int_t n = 2;
|
---|
64 | Double_t pow = t*t; // t^2
|
---|
65 |
|
---|
66 | do
|
---|
67 | {
|
---|
68 | add = pow/n/n;
|
---|
69 |
|
---|
70 | pow *= t; // pow = t^n
|
---|
71 | n++;
|
---|
72 |
|
---|
73 | disum += add;
|
---|
74 |
|
---|
75 | } while (fabs(add)>eps);
|
---|
76 |
|
---|
77 | return disum;
|
---|
78 | }
|
---|
79 |
|
---|
80 | Double_t MElectron::Li2(Double_t *x, Double_t *k=NULL)
|
---|
81 | {
|
---|
82 | //
|
---|
83 | // Dilog, Li2
|
---|
84 | // ----------
|
---|
85 | //
|
---|
86 | // Integral(0, 1) = konst;
|
---|
87 | // Double_t konst = 1./6*TMath::Pi()*TMath::Pi();
|
---|
88 | //
|
---|
89 | // x[0]: z
|
---|
90 | //
|
---|
91 | const Double_t z = x[0];
|
---|
92 |
|
---|
93 | if (fabs(z)<1)
|
---|
94 | return DiSum(x);
|
---|
95 |
|
---|
96 | // TF1 IntLi("Li", Li, 0, z, 0);
|
---|
97 | static TF1 IntLi("Li", Li, 0, 0, 0);
|
---|
98 | const Double_t integ = IntLi.Integral(0, z, (Double_t*)NULL, 1e-2);
|
---|
99 | return -integ;
|
---|
100 | }
|
---|
101 |
|
---|
102 | Double_t MElectron::Flim(Double_t *x, Double_t *k=NULL) // F(omegap)-F(omegam) mit b-->1 (Maple)
|
---|
103 | {
|
---|
104 | const Double_t w = x[0];
|
---|
105 |
|
---|
106 | const Double_t w4 = w*4;
|
---|
107 | const Double_t wsqr = w*w;
|
---|
108 |
|
---|
109 | const Double_t u1 = (w*wsqr*16 + wsqr*40 + w*17 + 2)*log(w4 + 1);
|
---|
110 | const Double_t u2 = -w4*(wsqr*2 + w*9 + 2);
|
---|
111 | const Double_t d = w4*(w4 + 1);
|
---|
112 |
|
---|
113 | Double_t s = -w*2*(1+1); // -2*omega*(1+beta)
|
---|
114 | const Double_t li2 = Li2(&s);
|
---|
115 |
|
---|
116 | const Double_t res = (u1+u2)/d + li2;
|
---|
117 |
|
---|
118 | return res; //<1e-10? 0 : res;
|
---|
119 | }
|
---|
120 |
|
---|
121 | Double_t MElectron::Compton(Double_t *x, Double_t *k)
|
---|
122 | {
|
---|
123 | const Double_t E0 = 511e-6; //[GeV]
|
---|
124 |
|
---|
125 | Double_t epsilon = x[0];
|
---|
126 | Double_t z = k[1];
|
---|
127 |
|
---|
128 | const Double_t E = k[0];
|
---|
129 |
|
---|
130 | Double_t omega = epsilon*E/(E0*E0);
|
---|
131 |
|
---|
132 | const Double_t n = MParticle::Planck(&epsilon, &z)/epsilon/epsilon; // [1]
|
---|
133 | return Flim(&omega)*n;
|
---|
134 | }
|
---|
135 |
|
---|
136 | Double_t MElectron::InteractionLength(Double_t *E, Double_t *k=NULL)
|
---|
137 | {
|
---|
138 | // E = electron energy, ~ TeV(?) 1e12
|
---|
139 | // e = photon energy, ~ meV(?) 1e-3
|
---|
140 | // mc^2 = electron rest mass energy ~.5keV(?) .5e3
|
---|
141 | //
|
---|
142 | // x^-1 = int( n(epsilon)/2beta * ((mc^2)^2/eE)^2 * int ( omega*sigma(omega), omega=o-..o+), epsilon=0..inf)
|
---|
143 | //
|
---|
144 | // o+/- = omage_0 (1 +- beta)
|
---|
145 | //
|
---|
146 | // omega_0 = eE/(mc^2)^2 ~1e12*1e-3/.25e6=4e3
|
---|
147 | //
|
---|
148 | // --> x^-1 = (alpha*hc)^2/4pibetaE^2 * int(n(epsilon)/epsilon^2 *( F(o+)-F(o-)), epsilon=0..inf)
|
---|
149 | //
|
---|
150 | // F(o) = -o/4 + (9/4 + 1/o + o/2) * ln(1+2o) + 1/8(1+2o) - 3/8 + Li2(-2o)
|
---|
151 | //
|
---|
152 | // Li2(x) = int(ln(1-t)/t, t=0..x)
|
---|
153 | //
|
---|
154 | // F(o+)~F(2o) = -o/2 + (9/4 + 1/2o + o) * ln(1+4o) + 1/8(1+4o) - 3/8 + Li2(-4o)
|
---|
155 | // F(o-)~F(0) = 14/8 = 1.75
|
---|
156 |
|
---|
157 | const Double_t E0 = 511e-6; // [GeV]
|
---|
158 | const Double_t E02 = E0*E0; // [GeV^2]
|
---|
159 | const Double_t c = 299792458; // [m/s]
|
---|
160 | const Double_t e = 1.602176462e-19; // [C]
|
---|
161 | const Double_t h = 1e-9/e*6.62606876e-34; // [GeVs]
|
---|
162 | const Double_t hc = h*c; // [GeVm]
|
---|
163 | const Double_t alpha = 1./137.; // [1]
|
---|
164 |
|
---|
165 | const Double_t z = k ? k[0] : 0;
|
---|
166 |
|
---|
167 | /* -------------- old ----------------
|
---|
168 | Double_t from = 1e-15;
|
---|
169 | Double_t to = 1e-11;
|
---|
170 | eps = [default];
|
---|
171 | -----------------------------------
|
---|
172 | */
|
---|
173 | static TF1 func("Compton", Compton, 0, 0, 2); // [0, inf]
|
---|
174 |
|
---|
175 | const Double_t from = 1e-17;
|
---|
176 | const Double_t to = 1e-11;
|
---|
177 |
|
---|
178 | Double_t val[3] = { E[0], z }; // E[GeV]
|
---|
179 |
|
---|
180 | Double_t integ = func.Integral(from, to, val, 1e-2); // [Gev] [0, inf]
|
---|
181 |
|
---|
182 | const Double_t aE = alpha/E[0]; // [1/GeV]
|
---|
183 |
|
---|
184 | const Double_t beta = 1;
|
---|
185 |
|
---|
186 | const Double_t konst = 2.*E02/hc/beta; // [1 / GeV m]
|
---|
187 | const Double_t ret = konst * (aE*aE) * integ; // [1 / m]
|
---|
188 |
|
---|
189 | const Double_t ly = 3600.*24.*365.*c; // [m/ly]
|
---|
190 | const Double_t pc = 1./3.258; // [pc/ly]
|
---|
191 |
|
---|
192 | return (1./ret)/ly*pc/1000; // [kpc]
|
---|
193 | }
|
---|
194 |
|
---|
195 | Double_t MElectron::GetInteractionLength(Double_t energy, Double_t z)
|
---|
196 | {
|
---|
197 | return InteractionLength(&energy, &z);
|
---|
198 | }
|
---|
199 |
|
---|
200 | Double_t MElectron::GetInteractionLength() const
|
---|
201 | {
|
---|
202 | return InteractionLength((Double_t*)&fEnergy, (Double_t*)&fZ);
|
---|
203 | }
|
---|
204 |
|
---|
205 | // --------------------------------------------------------------------------
|
---|
206 |
|
---|
207 | inline Double_t MElectron::p_e(Double_t *x, Double_t *k)
|
---|
208 | {
|
---|
209 | Double_t e = pow(10, x[0]);
|
---|
210 | return Compton(&e, k);
|
---|
211 | /*
|
---|
212 | Double_t z = k[1];
|
---|
213 |
|
---|
214 | const Double_t E = k[0];
|
---|
215 |
|
---|
216 | const Double_t E0 = 511e-6; //[GeV]
|
---|
217 | const Double_t E02 = E0*E0;
|
---|
218 |
|
---|
219 | Double_t omega = e*E/E02;
|
---|
220 |
|
---|
221 | const Double_t n = Planck(&e, &z);
|
---|
222 |
|
---|
223 | const Double_t F = Flim(&omega)/omega/omega;
|
---|
224 |
|
---|
225 | return n*F*1e26;
|
---|
226 | */
|
---|
227 | }
|
---|
228 |
|
---|
229 | Double_t MElectron::G_q(Double_t *x, Double_t *k)
|
---|
230 | {
|
---|
231 | const Double_t q = x[0];
|
---|
232 | const Double_t Gamma = k[0];
|
---|
233 |
|
---|
234 | const Double_t Gq = Gamma*q;
|
---|
235 |
|
---|
236 | const Double_t s1 = 2.*q*log(q);
|
---|
237 | const Double_t s2 = (1.+2.*q);
|
---|
238 | const Double_t s3 = (Gq*Gq)/(1.+Gq)/2.;
|
---|
239 |
|
---|
240 | return s1+(s2+s3)*(1.-q);
|
---|
241 | }
|
---|
242 |
|
---|
243 |
|
---|
244 | Double_t MElectron::EnergyLoss(Double_t *x, Double_t *k, Double_t *ep)
|
---|
245 | {
|
---|
246 | const Double_t E = x[0];
|
---|
247 | const Double_t z = k ? k[0] : 0;
|
---|
248 |
|
---|
249 | const Double_t E0 = 511e-6; //[GeV]
|
---|
250 |
|
---|
251 | const Double_t lolim = -log10(E)/7*4-13;
|
---|
252 |
|
---|
253 | TF1 fP("p_e", p_e, lolim, -10.8, 2);
|
---|
254 | TF1 fQ("G", G_q, 0, 1., 1);
|
---|
255 |
|
---|
256 | fP.SetParameter(0, E);
|
---|
257 | fP.SetParameter(1, z);
|
---|
258 |
|
---|
259 | const Double_t e = pow(10, fP.GetRandom());
|
---|
260 |
|
---|
261 | if (ep)
|
---|
262 | *ep = e;
|
---|
263 |
|
---|
264 | const Double_t omega = (e/E0)*(E/E0);
|
---|
265 | const Double_t Gamma = 4.*omega;
|
---|
266 |
|
---|
267 | fQ.SetParameter(0, Gamma);
|
---|
268 |
|
---|
269 | const Double_t q = fQ.GetRandom();
|
---|
270 | const Double_t Gq = Gamma*q;
|
---|
271 |
|
---|
272 | const Double_t e1 = Gq*E/(1.+Gq);
|
---|
273 |
|
---|
274 | return e1;
|
---|
275 | }
|
---|
276 |
|
---|
277 | Double_t MElectron::GetEnergyLoss(Double_t E, Double_t z, Double_t *ep)
|
---|
278 | {
|
---|
279 | return EnergyLoss(&E, &z);
|
---|
280 | }
|
---|
281 |
|
---|
282 | Double_t MElectron::GetEnergyLoss(Double_t *ep) const
|
---|
283 | {
|
---|
284 | return EnergyLoss((Double_t*)&fEnergy, (Double_t*)&fZ, ep);
|
---|
285 | }
|
---|
286 |
|
---|
287 | MPhoton *MElectron::DoInvCompton(Double_t theta)
|
---|
288 | {
|
---|
289 | static TRandom rand(0);
|
---|
290 |
|
---|
291 | const Double_t E0 = 511e-6; //[GeV]
|
---|
292 |
|
---|
293 | Double_t epsilon;
|
---|
294 | const Double_t e = GetEnergyLoss(&epsilon);
|
---|
295 |
|
---|
296 | // er: photon energy before interaction, rest frame
|
---|
297 | // e: photon energy after interaction, lab
|
---|
298 |
|
---|
299 | const Double_t gamma = fEnergy/E0;
|
---|
300 | // const Double_t beta = sqrt(1.-1./(gamma*gamma));
|
---|
301 | const Double_t gammabeta = sqrt(gamma*gamma-1);
|
---|
302 |
|
---|
303 | const Double_t f = fEnergy/e;
|
---|
304 |
|
---|
305 | Double_t t=-1;
|
---|
306 | Double_t arg;
|
---|
307 | do
|
---|
308 | {
|
---|
309 | if (t>0)
|
---|
310 | cout << "~" << flush;
|
---|
311 | t = rand.Uniform(TMath::Pi())+TMath::Pi()/2;
|
---|
312 | Double_t er = epsilon*(gamma-gammabeta*cos(t)); // photon energy rest frame
|
---|
313 | arg = (f - E0/er - 1)/(sqrt(fEnergy*fEnergy-E0*E0)/e+1);
|
---|
314 |
|
---|
315 | } while (arg<-1 || arg>1);
|
---|
316 |
|
---|
317 | const Double_t theta1s = acos(arg);
|
---|
318 | const Double_t thetas = atan(sin(t)/(gamma*cos(t)-gammabeta));
|
---|
319 |
|
---|
320 | const Double_t thetastar = thetas-theta1s;
|
---|
321 |
|
---|
322 | const Double_t theta1 = atan(sin(thetastar)/(gamma*cos(thetastar)+gammabeta));
|
---|
323 |
|
---|
324 | fEnergy -= e;
|
---|
325 |
|
---|
326 | const Double_t phi = rand.Uniform(TMath::Pi()*2);
|
---|
327 |
|
---|
328 | MPhoton &p = *new MPhoton(e, fZ);
|
---|
329 | p = *this;
|
---|
330 | p.SetNewDirection(theta1, phi);
|
---|
331 |
|
---|
332 | const Double_t beta2 = sqrt(1.-E0/fEnergy*E0/fEnergy);
|
---|
333 | const Double_t theta2 = asin((epsilon*sin(t)-e*sin(theta1))/fEnergy/beta2);
|
---|
334 |
|
---|
335 | SetNewDirection(theta2, phi);
|
---|
336 |
|
---|
337 | return &p;
|
---|
338 | }
|
---|
339 |
|
---|
340 | void MElectron::DrawInteractionLength(Double_t z)
|
---|
341 | {
|
---|
342 | if (!gPad)
|
---|
343 | new TCanvas("IL_Electron", "Mean Interaction Length Electron");
|
---|
344 | else
|
---|
345 | gPad->GetVirtCanvas()->cd(3);
|
---|
346 |
|
---|
347 | TF1 f2("length", MElectron::InteractionLength, 1e3, 1e10, 0);
|
---|
348 | f2.SetParameter(0, z);
|
---|
349 |
|
---|
350 | gPad->SetLogx();
|
---|
351 | gPad->SetLogy();
|
---|
352 | gPad->SetGrid();
|
---|
353 | f2.SetLineWidth(1);
|
---|
354 |
|
---|
355 | TH1 &h=*f2.DrawCopy()->GetHistogram();
|
---|
356 |
|
---|
357 | h.SetTitle("Mean Interaction Length (Electron)");
|
---|
358 | h.SetXTitle("E [GeV]");
|
---|
359 | h.SetYTitle("x [kpc]");
|
---|
360 |
|
---|
361 | gPad->Modified();
|
---|
362 | gPad->Update();
|
---|
363 | }
|
---|
364 |
|
---|
365 | void MElectron::DrawInteractionLength() const
|
---|
366 | {
|
---|
367 | DrawInteractionLength(fZ);
|
---|
368 | }
|
---|
369 |
|
---|
370 | Bool_t MElectron::SetNewPositionB(Double_t B)
|
---|
371 | {
|
---|
372 | static TRandom rand(0);
|
---|
373 | Double_t x = rand.Exp(GetInteractionLength());
|
---|
374 |
|
---|
375 | // -----------------------------
|
---|
376 |
|
---|
377 | const Double_t E0 = 511e-6; //[GeV]
|
---|
378 |
|
---|
379 | Double_t B_theta = rand.Uniform(TMath::Pi());
|
---|
380 | Double_t B_phi = rand.Uniform(TMath::Pi()*2);
|
---|
381 |
|
---|
382 | TMatrixD M(3,3);
|
---|
383 |
|
---|
384 | M(0, 0) = sin(B_theta)*cos(B_phi);
|
---|
385 | M(1, 0) = cos(B_theta)*cos(B_phi);
|
---|
386 | M(2, 0) = -sin(B_phi);
|
---|
387 |
|
---|
388 | M(0, 1) = sin(B_theta)*sin(B_phi);
|
---|
389 | M(1, 1) = cos(B_theta)*sin(B_phi);
|
---|
390 | M(2, 1) = cos(B_phi);
|
---|
391 |
|
---|
392 | M(0, 2) = cos(B_theta);
|
---|
393 | M(1, 2) = -sin(B_theta);
|
---|
394 | M(2, 2) = 0;
|
---|
395 |
|
---|
396 | const Double_t beta = sqrt(1-E0/fEnergy*E0/fEnergy);
|
---|
397 |
|
---|
398 | //
|
---|
399 | // rotate vector of velocity into a system in
|
---|
400 | // which the x-axis is identical with the B-Field
|
---|
401 | //
|
---|
402 | TVectorD v(3);
|
---|
403 | v(0) = beta*sin(fTheta)*cos(fPsi);
|
---|
404 | v(1) = beta*sin(fTheta)*sin(fPsi);
|
---|
405 | v(2) = beta*cos(fTheta);
|
---|
406 | v *= M;
|
---|
407 |
|
---|
408 | //
|
---|
409 | // Now rotate the system so, that the velocity vector
|
---|
410 | // lays in the y-z-plain
|
---|
411 | //
|
---|
412 | Double_t chi = atan(-v(2)/v(1));
|
---|
413 |
|
---|
414 | // -----------------------------
|
---|
415 |
|
---|
416 | TMatrixD N(3,3);
|
---|
417 | N(0, 0) = 1;
|
---|
418 | N(1, 0) = 0;
|
---|
419 | N(2, 0) = 0;
|
---|
420 |
|
---|
421 | N(0, 1) = 0;
|
---|
422 | N(1, 1) = -cos(chi);
|
---|
423 | N(2, 1) = -sin(chi);
|
---|
424 |
|
---|
425 | N(0, 2) = 0;
|
---|
426 | N(1, 2) = sin(chi);
|
---|
427 | N(2, 2) = -cos(chi);
|
---|
428 | v *= N;
|
---|
429 |
|
---|
430 | Double_t beta_p = v(0); // beta parallel
|
---|
431 | Double_t beta_o = v(1); // beta orthogonal
|
---|
432 | // v(2) = 0
|
---|
433 | // -----------------------------
|
---|
434 | TVectorD p(3);
|
---|
435 |
|
---|
436 | Double_t rho = 0;
|
---|
437 | if (B>0)
|
---|
438 | {
|
---|
439 | const Double_t c = 299792458; // [m/s]
|
---|
440 | const Double_t ly = 3600.*24.*365.*c; // [m/ly]
|
---|
441 | const Double_t pc = 1./3.258; // [pc/ly]
|
---|
442 |
|
---|
443 | Double_t r = (fEnergy*1e9)*beta_o/(c*B)*(pc/ly/1e3); // [kpc]
|
---|
444 |
|
---|
445 | rho = beta_o/beta*x/r; // [2pi]
|
---|
446 |
|
---|
447 | // -----------------------------
|
---|
448 |
|
---|
449 | if (fabs(rho*3437)>5*60) // > 5*60min
|
---|
450 | {
|
---|
451 | cout << "r" << flush;
|
---|
452 | return kFALSE;
|
---|
453 | }
|
---|
454 |
|
---|
455 | p(0) = beta_p/beta*x;
|
---|
456 | p(1) = GetPType()==kEElectron?r*sin(rho):-r*sin(rho);
|
---|
457 | p(2) = r*(1-cos(rho));
|
---|
458 | }
|
---|
459 | else
|
---|
460 | {
|
---|
461 | p(0) = beta_p/beta*x;
|
---|
462 | p(1) = beta_o/beta*x;
|
---|
463 | p(2) = 0;
|
---|
464 | }
|
---|
465 |
|
---|
466 | TVectorD s(3);
|
---|
467 | s(0) = fR*cos(fPhi);
|
---|
468 | s(1) = fR*sin(fPhi);
|
---|
469 | s(2) = RofZ(&fZ);
|
---|
470 |
|
---|
471 | TMatrixD N2(TMatrixD::kTransposed, N);
|
---|
472 | TMatrixD M2(TMatrixD::kTransposed, M);
|
---|
473 | p *= N2;
|
---|
474 | p *= M2;
|
---|
475 | s -= p;
|
---|
476 |
|
---|
477 | fR = sqrt(s(0)*s(0)+s(1)*s(1));
|
---|
478 | fPhi = atan2(s(1), s(0));
|
---|
479 | fZ = ZofR(&s(2));
|
---|
480 |
|
---|
481 | // -----------------------------
|
---|
482 |
|
---|
483 | TVectorD w(3);
|
---|
484 | w(0) = beta_p/beta;
|
---|
485 | w(1) = beta_o/beta*cos(rho);
|
---|
486 | w(2) = beta_o/beta*sin(rho);
|
---|
487 |
|
---|
488 | w *= N2;
|
---|
489 | w *= M2;
|
---|
490 |
|
---|
491 | fPsi = atan2(w(1), w(0));
|
---|
492 | fTheta = asin(sqrt(w(0)*w(0)+w(1)*w(1)));
|
---|
493 |
|
---|
494 | // -----------------------------
|
---|
495 |
|
---|
496 | return fZ<0 ? kFALSE : kTRUE;
|
---|
497 | }
|
---|