-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotVelo.py
196 lines (123 loc) · 4.3 KB
/
plotVelo.py
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import matplotlib.pyplot as plt
from matplotlib import rcParams
import matplotlib as mpl
mpl.use("Agg")
import seaborn
import time
from pprint import pprint
import json
import numpy as np
np.random.seed(42)
import uproot
from scipy.stats import rv_histogram, expon, poisson
from veloGeom import buildTileXY, boundingVolumes, testIntersection
from genPhSp import genPhaseSpace
from genVeloHits import genTracks, addDecays
from genVeloHits import formDecayproducts, sampleBKinematics, genHits
plt.style.use(["seaborn-whitegrid", "seaborn-ticks"])
rcParams["figure.figsize"] = 12, 12
rcParams["axes.facecolor"] = "FFFFFF"
rcParams["savefig.facecolor"] = "FFFFFF"
rcParams["figure.facecolor"] = "FFFFFF"
rcParams["xtick.direction"] = "in"
rcParams["ytick.direction"] = "in"
rcParams["mathtext.fontset"] = "cm"
rcParams["mathtext.rm"] = "serif"
rcParams.update({"figure.autolayout": True})
def drawXY(tile, colour="k"):
# bottom
plt.plot([tile[0][0], tile[0][1]], [tile[1][0], tile[1][0]], color=colour)
# right
plt.plot([tile[0][1], tile[0][1]], [tile[1][0], tile[1][1]], color=colour)
# top
plt.plot([tile[0][0], tile[0][1]], [tile[1][1], tile[1][1]], color=colour)
# left
plt.plot([tile[0][0], tile[0][0]], [tile[1][0], tile[1][1]], color=colour)
def drawZ(geom, xRangeA, xRangeC):
for z in geom["z"]["a"]:
plt.plot([z, z], [xRangeA[0], xRangeA[1]], color="red")
for z in geom["z"]["c"]:
plt.plot([z, z], [xRangeC[0], xRangeC[1]], color="black")
def drawXYTrack(geom, ray):
rayO, rayD = ray
xMax = 500
ts = np.linspace(0, 1000, 100)
# z-x projection
pointsX = [rayO[0] + rayD[0] * t for t in ts]
pointsY = [rayO[1] + rayD[1] * t for t in ts]
plt.plot(pointsX, pointsY, linestyle=":", alpha=0.5)
def drawTrack(geom, ray):
rayO, rayD = ray
zMax = geom["z"]["a"][-1] + 10.0
maxT = (zMax - rayO[2]) / rayD[2]
ts = np.linspace(0, 1000, 100)
# z-x projection
pointsX = [rayO[0] + rayD[0] * t for t in ts]
pointsZ = [rayO[2] + rayD[2] * t for t in ts]
plt.plot(pointsZ, pointsX, linestyle=":", alpha=0.5)
if __name__ == "__main__":
geom = json.load(open("veloGeom.json", "r"))
decayParams = json.load(open("decayProbs.json", "r"))
bottom, right, top, left = buildTileXY(geom) # , offset = (10, 10))
drawXY(bottom, "black")
drawXY(right, "blue")
drawXY(top, "red")
drawXY(left, "green")
plt.savefig("test.pdf")
plt.clf()
volsA, volsC = boundingVolumes(geom, (bottom, right, top, left))
xRangeA = (top[0][0], top[0][1])
xRangeC = (bottom[0][0], bottom[0][1])
drawZ(geom, xRangeA, xRangeC)
plt.xlim(-400, 800)
plt.ylim(-10, 100)
plt.savefig("testZ.pdf")
plt.clf()
tracks = genTracks(geom, 1000, allFONLL=True)
# Select only those going forwards for now, *in principle* a cut on eta
tracks = list(
filter(
lambda x: np.arcsinh(x[1][2] / np.sqrt(x[1][0] ** 2 + x[1][1] ** 2)) > 3,
tracks,
)
)
print("N tracks:", len(tracks))
tracks = addDecays(decayParams, tracks)
drawXY(bottom, "black")
drawXY(right, "blue")
drawXY(top, "red")
drawXY(left, "green")
tracks, hits, hitsPix = genHits(nGen=1000, tracks=tracks)
for t in hits:
plt.plot([h[0] for h in t], [h[1] for h in t], "+")
plt.xlim(-10, 80)
plt.ylim(-10, 80)
plt.savefig("hitXY.pdf")
plt.clf()
drawXY(bottom, "black")
drawXY(right, "blue")
drawXY(top, "red")
drawXY(left, "green")
for r in np.array(tracks): # [list(toDraw)]:
drawXYTrack(geom, r)
plt.xlim(-10, 80)
plt.ylim(-10, 80)
plt.savefig("trackXY.pdf")
plt.clf()
drawZ(geom, xRangeA, xRangeC)
for track in np.array(tracks): # [list(toDraw)]:
drawTrack(geom, track)
plt.xlim(-400, 800)
plt.ylim(-10, 90)
plt.savefig("trackZ.pdf")
plt.xlim(-50, 50)
plt.ylim(35, 40)
plt.savefig("trackZZoom.pdf")
# emptyTile = np.zeros((geom["pixelsPerTile"]["short"], geom["pixelsPerTile"]["long"]))
# for i in range(10000):
# rx = np.random.randint(0, geom["pixelsPerTile"]["short"])
# ry = np.random.randint(0, geom["pixelsPerTile"]["long"])
# emptyTile[rx][ry] = 1
#
# plt.imshow(emptyTile)
# plt.savefig('tileTest.pdf')