-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComputeSignal.m
79 lines (64 loc) · 2.35 KB
/
ComputeSignal.m
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the signal given the "Work-Transport" matrix %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% WorkTransportTotal = Total "Work-Transport" matrix
% x, y = Axes
% Depth = Penetration depth along y (positive = from back side,
% negative = from strip side) [um]
% XEnterParticle = X cordinate of the enter of the particle [um] (back-plane side)
% XExitParticle = X cordinate of the exit of the particle [um] (strip side)
% Bulk = Bulk thickness [um]
% Radius = Unit step of the movements and field interpolation [um]
% ChargeDensity = Charge density [electrons/um]
% IsGamma = [true/false]
function [Charge] = ComputeSignal(WorkTransportTotal,x,y,Depth,...
XEnterParticle,XExitParticle,Bulk,Radius,ChargeDensity,IsGamma)
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Variable initialization %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Charge = 0; % Starting value of the signal [electrons]
eps = Radius/10; % Minimum step to avoid infinities [um]
%%%%%%%%%%%%%%%%%%%
% Start algorithm %
%%%%%%%%%%%%%%%%%%%
mx = min(abs(x - XEnterParticle));
if Depth >= 0
my = y(1);
else
my = min(abs(y - (Bulk + Depth)));
end
while my >= 0 && ((Depth >= 0 && my <= Depth) || (Depth < 0 && my <= Bulk))
x_near = find(abs(x - mx) <= Radius);
y_near = find(abs(y - my) <= Radius);
% Calculate the average Work within a radius = Radius
W = 0;
weight = 0;
for ii = 1:length(x_near)
for jj = 1:length(y_near)
dist = sqrt((mx-x(x_near(ii)))^2 + (my-y(y_near(jj)))^2);
if dist <= Radius && ~isnan(WorkTransportTotal(y_near(jj),x_near(ii)))
if dist < eps
dist = eps;
end
W = W + WorkTransportTotal(y_near(jj),x_near(ii)) / dist;
weight = weight + 1 / dist;
end
end
end
if weight ~= 0
W = W / weight;
end
Charge = Charge + W;
% Calculate the next movement
if IsGamma == false
dx = XExitParticle - XEnterParticle;
sinv = dx / sqrt(dx^2 + Bulk^2);
cosv = Bulk / sqrt(dx^2 + Bulk^2);
mx = mx + Radius*sinv;
my = my + Radius*cosv;
else
break
end
end
Charge = ChargeDensity * Charge;
end