-
Notifications
You must be signed in to change notification settings - Fork 0
/
scattering.c
93 lines (80 loc) · 1.58 KB
/
scattering.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define pi 3.141592653
struct position
{
double x;
double y;
};
int Z=0;
double E=0;
int A=0;
double R=10;
double irand()
{
return (double)rand()/RAND_MAX;
}
double energy(double Ec)
{
E=Ec*(1+0.01*pow(-2*log(irand()),1/2)*cos(2*pi*irand()));
return 0;
}
double alpha()
{
return (3.4*pow(10,-3)*pow(Z,0.67)/E);
}
double step()
{
//double alpha=3.4*pow(10,-3)*pow(Z,0.67)/E;
double sigmaE=5.21*pow(10,-21)*Z*Z/E/E*4*pi/(alpha()*(alpha()+1))*pow((E+511)/(E+1024),2);
double lambda=A/(6.022*pow(10,23)*196.9665*sigmaE);
return (-lambda*log(irand())*pow(10,8));
//in unit of 10*e-10
}
double phi()
{
//double alpha=3.4*pow(10,-3)*pow(Z,0.67)/E;
//return 1-(2*alpha()*irand())/(1+alpha()-irand());
return 2*pi*irand();
}
double cospsi()
{
return 1-(2*alpha()*irand())/(1+alpha()+irand());
}
double sinpsi()
{
return pow(1-cospsi(),1/2);
}
double perenergyloss()
{
double J=(9.76*79+58.5/pow(Z,0.19))*pow(10,-3);
return -78500*196.9665*Z/A/E*log(1.166*E/J+1);
}
double totalenergyloss()
{
double totald=step()+R/sinpsi();
return totald*perenergyloss();
}
int main()
{
double totald=0;
//position *p=(position*) malloc(10 * sizeof(position));
Z=79;
double Ec=10000;
A=117;
srand(time(NULL));
for (int i=0;i<10;i++)
{
energy(Ec);
//printf("%f\n",E);
//now for the interaction point
//printf("%f\n",step());
//printf("%f",phi());
printf("step here is %f\n",step());
printf("scattering angle here is %f\n",acos(cospsi()));
printf("energy loss is %f\n",totalenergyloss());
}
return 0;
}