-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdetector_geometry.c
158 lines (140 loc) · 5.15 KB
/
detector_geometry.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* detector_geometry_ppc.c -- for "ppc" geometry
* Karin Lagergren
*
* This module keeps track of the detector geometry
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "detector_geometry.h"
#include "point.h"
#include "cyl_point.h"
#define SQ(x) ((x)*(x))
/* outside_detector
returns 1 if pt is outside the detector, 0 if inside detector
*/
int outside_detector(point pt, MJD_Siggen_Setup *setup){
float r, z, r1, z1, br, a, b;
z = pt.z;
if (z > setup->zmax || z < 0) return 1;
r = sqrt(SQ(pt.x)+SQ(pt.y));
if (r > setup->rmax) return 1;
r1 = setup->rmax - r; // distance from outer radius
z1 = setup->zmax - z; // distance from top of crystal
/* check point contact */
if (z < setup->pc_length && r < setup->pc_radius) {
if (!setup->bulletize_PC) return 1;
if (setup->pc_length > setup->pc_radius) {
a = setup->pc_length - setup->pc_radius;
if (z < a || SQ(z-a) + SQ(r) < SQ(setup->pc_radius)) return 1;
} else {
a = setup->pc_radius - setup->pc_length;
if (r < a || SQ(z) + SQ(r-a) < SQ(setup->pc_length)) return 1;
}
return 0;
}
/* check ditch */
if (z < setup->ditch_depth &&
setup->ditch_thickness > 0 && setup->wrap_around_radius > 0 &&
r < setup->wrap_around_radius &&
r > setup->wrap_around_radius - setup->ditch_thickness) return 1;
/* check hole */
if ( r < setup->hole_radius &&
z1 < setup->hole_length) {
b = setup->zmax - setup->hole_length + setup->hole_bullet_radius;
if (z > b) return 1;
a = setup->hole_radius - setup->hole_bullet_radius;
if (r < a || SQ(b-z) + SQ(r-a) < SQ(setup->hole_bullet_radius)) return 1;
}
/* check inner taper of hole */
if (z1 < setup->inner_taper_length &&
r < setup->hole_radius +
((setup->inner_taper_length - z1) *
setup->inner_taper_width / setup->inner_taper_length)) return 1;
/* check outer taper of crystal */
if (z1 < setup->outer_taper_length &&
r1 < ((setup->outer_taper_length - z1) *
setup->outer_taper_width / setup->outer_taper_length)) return 1;
/* check 45-degree bottom outer taper of crystal */
if ( z < setup->bottom_taper_length &&
r1 < setup->bottom_taper_length - z) return 1;
/* check bulletizations */
br = setup->top_bullet_radius;
// adjust top bulletization position for top outer taper
a = 0;
if (setup->outer_taper_length > br)
a = ((setup->outer_taper_length - br) *
setup->outer_taper_width / setup->outer_taper_length);
if (z1 < br &&
r1 < br + a &&
SQ(br - r1 + a) + SQ(br - z1) > br*br) return 1;
br = setup->bottom_bullet_radius;
if ( z < br &&
r1 < br &&
SQ(br - r1) + SQ(br - z ) > br*br) return 1;
return 0;
}
int outside_detector_cyl(cyl_pt pt, MJD_Siggen_Setup *setup){
float r, z, r1, z1, br, a, b;
z = pt.z;
if (z > setup->zmax || z < 0) return 1;
r = pt.r;
if (r < 0) r = -r;
if (r > setup->rmax) return 1;
r1 = setup->rmax - r; // distance from outer radius
z1 = setup->zmax - z; // distance from top of crystal
/* check point contact */
if (z < setup->pc_length && r < setup->pc_radius) {
if (!setup->bulletize_PC) return 1;
if (setup->pc_length > setup->pc_radius) {
a = setup->pc_length - setup->pc_radius;
if (z < a || SQ(z-a) + SQ(r) < SQ(setup->pc_radius)) return 1;
} else {
a = setup->pc_radius - setup->pc_length;
if (r < a || SQ(z) + SQ(r-a) < SQ(setup->pc_length)) return 1;
}
return 0;
}
/* check ditch */
if (z <= setup->ditch_depth &&
setup->ditch_thickness > 0 && setup->wrap_around_radius > 0 &&
r < setup->wrap_around_radius &&
r > setup->wrap_around_radius - setup->ditch_thickness) return 1;
/* check hole */
if ( r < setup->hole_radius &&
z1 < setup->hole_length) {
b = setup->zmax - setup->hole_length + setup->hole_bullet_radius;
if (z > b) return 1;
a = setup->hole_radius - setup->hole_bullet_radius;
if (r < a || SQ(b-z) + SQ(r-a) < SQ(setup->hole_bullet_radius)) return 1;
}
/* check inner taper of hole */
if (z1 < setup->inner_taper_length &&
r < setup->hole_radius +
((setup->inner_taper_length - z1) *
setup->inner_taper_width / setup->inner_taper_length)) return 1;
/* check outer taper of crystal */
if (z1 < setup->outer_taper_length &&
r1 < ((setup->outer_taper_length - z1) *
setup->outer_taper_width / setup->outer_taper_length)) return 1;
/* check 45-degree bottom outer taper of crystal */
if ( z < setup->bottom_taper_length &&
r1 < setup->bottom_taper_length - z) return 1;
/* check bulletizations */
br = setup->top_bullet_radius;
// adjust top bulletization position for top outer taper
a = 0;
if (setup->outer_taper_length > br)
a = ((setup->outer_taper_length - br) *
setup->outer_taper_width / setup->outer_taper_length);
if (z1 < br &&
r1 < br + a &&
SQ(br - r1 + a) + SQ(br - z1) > br*br) return 1;
br = setup->bottom_bullet_radius;
a = setup->Li_thickness; // FIXME ? added for fieldgen
if ( z < br + a &&
r1 < br &&
SQ(br - r1) + SQ(br - z + a) > br*br) return 1;
return 0;
}
#undef SQ