-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.py
More file actions
161 lines (125 loc) · 4.34 KB
/
utilities.py
File metadata and controls
161 lines (125 loc) · 4.34 KB
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
159
160
161
#External Dependencies
import math
#internal Dependencies
from dataTypes import *
def generatePlaneInfo(wirePitches, volume, angles):
"""Generates information about planes based on wire pitches and volume assuming equal angle between each plane and the next
Parameters
----------
wirePitches : list or tuple of int or float
A list of wire pitches, each number corresponding to the pitch of each plane
volume : DetectorVolume
The width and height of the detector
angles : list or tuple of float
List of the angles of the wire plane in radians
Returns
-------
list of PlaneInfo
List of information regarding the planes.
"""
#TODO Add functionality for translating wires by a certain amount
planes = []
for planeNo, pitch in enumerate(wirePitches):
# basic angle calculations
angle = angles[planeNo]
cos = math.cos(angle)
sin = math.sin(angle)
# Origin and number of wire calculations
if (volume.width * math.cos(angle) < 0):
originTranslation = volume.width
noOfWires = math.floor(
(sin * volume.height - cos * originTranslation) / pitch)
else:
originTranslation = 0
noOfWires = math.floor(
(cos * volume.width + sin * volume.height) / pitch)
# gradient calculations
if(math.isclose(angle, math.pi, rel_tol=1e-5)):
gradient = "INF"
elif originTranslation == 0:
gradient = math.tan(angle + math.pi / 2)
else:
gradient = math.tan(angle - math.pi / 2)
planes.append(PlaneInfo(angle, pitch, noOfWires,
originTranslation, sin, cos, gradient))
return planes
def wireNumberFromPoint(plane, point):
"""Generates the wire number for a point given a certain plane
Parameters
----------
plane : PlaneInfo
Plane information for the plane the wire number is for
point : Point
The point being queried
Returns
-------
int
Primitive Wire number
"""
return math.floor((plane.cos * point.x + plane.sin * point.y - plane.cos * plane.originTranslation) / plane.pitch)
def pointInWire(plane,point,wire):
"""Check if a point is inside a certain merged wire
Parameters
----------
plane : PlaneInfo
Plane information for the plane the wire number is for
point : Point
The point being queried
wire : tuple[2] of int
A merged wire
Returns
-------
Boolean
True if point is in wire, False if not
"""
wireFloat = (plane.cos * point.x + plane.sin * point.y - plane.cos * plane.originTranslation) / plane.pitch
wireInt = math.floor(wireFloat)
insideWire = wireInt>=wire[0] and wireInt<=wire[1]
onEdge = math.isclose(wireFloat,(wire[0]),rel_tol=1e-5) or math.isclose(wireFloat,(wire[1]+1),rel_tol=1e-5)
return insideWire or onEdge
def fireWires(planes, points):
"""Show which wires have been hit for a given blob
Parameters
----------
planes : list of PlaneInfo
A list containing information for all the planes in the detector
points : list of points
points defining ConvexHull of blob
Returns
-------
2d list of int
A list that has lists of merged wire numbers. one list for every plane
"""
firedWires = []
for planeNo, plane in enumerate(planes):
for pointNo, point in enumerate(points):
wireNo = wireNumberFromPoint(plane, point)
if pointNo == 0:
min = wireNo
max = wireNo
elif wireNo > max:
max = wireNo
elif wireNo < min:
min = wireNo
firedWires.append(list(range(min, max + 1)))
return firedWires
def getChannelNo(planes, wireNo, planeNo):
"""Get Channel Number for a primitve wire
Parameters
----------
planes : list of PlaneInfo
A list containing information for all the planes in the detector
wireNo : int
Primitive Wire
planeNo : int
Index of plane the wires are in
Returns
-------
int
Channel number for a primitive wire
"""
trueWireNo = 0
for plane in range(0,planeNo):
trueWireNo += planes[plane].noOfWires
trueWireNo += wireNo
return trueWireNo