-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcellTable.py
More file actions
129 lines (82 loc) · 3.19 KB
/
cellTable.py
File metadata and controls
129 lines (82 loc) · 3.19 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
from pprint import pprint
from sklearn import linear_model
import sys
import numpy as np
import itertools
import math
from scipy.spatial import ConvexHull
from dataTypes import *
def generateAngles(noOfPlanes):
individualAngle = math.pi/noOfPlanes
angles = []
for planeNo in range(noOfPlanes):
angles.append(individualAngle * (planeNo + 1))
return angles
def generateMatrix(planes, cells):
cellBindings = []
wires = []
matrix = []
for cellNo, cell in enumerate(cells):
for planeNo, wire in enumerate(cell.wires):
# print("\033[91m",wire, "\033[0m")
trueWire = (getTrueWireNo(planes,wire[0],planeNo),getTrueWireNo(planes,wire[1],planeNo))
# print("\033[93m",trueWire, "\033[0m")
if trueWire not in wires:
wires.append(trueWire)
matrix.append(list(np.zeros(len(cells),dtype=int)))
matrix[wires.index(trueWire)][cellNo] = 1
return wires, np.matrix(matrix)
def generateCharge(planes,blobs):
chargeMatrix = []
for plane in planes:
chargeMatrix.append(list(np.zeros(plane.noOfWires,dtype=int)))
for blob in blobs:
wires = fireWires(planes,blob.points)
for planeNo, plane in enumerate(wires):
charge = blob.charge/(len(plane))
for wireNo in plane:
chargeMatrix[planeNo][wireNo] += charge
return chargeMatrix
def measureCharge(wireList,chargeMatrix):
charges = []
chargeMatrix = list(itertools.chain(*chargeMatrix))
for wire in wireList:
charge = 0
test = []
for i in range(wire[0],wire[1]+1):
charge += chargeMatrix[i]
charges.append(charge)
return np.matrix(charges)
################################################################################
def main(argv):
volume = DetectorVolume(1000.0, 1000.0)
wirePitches = [5.0, 5.0, 5.0]
wireTranslations = [0.0,0.0,0.0]
angles = generateAngles(len(wirePitches))
planes = generatePlaneInfo(wirePitches, volume, angles, wireTranslations)
blobs = generateBlobs(planes,volume)
event = generateEvent(planes,blobs)
event = mergeEvent(event)
cells = generateCells(planes,event)
wireList, geomMatrix = generateMatrix(planes,cells)
# pprint(wireList)
chargeMatrix = generateCharge(planes,blobs)
charge = measureCharge(wireList,chargeMatrix)
trueCellCharge = generateTrueCellMatrix(blobs,cells)
trueWireCharge = geomMatrix * trueCellCharge
print("\033[93m","Number of true Blobs:",len(blobs),"\033[0m")
print("\033[93m","Number of Merged Wires:", np.shape(geomMatrix)[0],"\033[0m")
print("\033[93m","Number of Cells:", np.shape(geomMatrix)[1],"\033[0m")
pprint(trueCellCharge)
pprint(trueCellCharge.shape)
# pprint(geomMatrix)
# pprint(geomMatrix.shape)
# pprint(trueWireCharge)
# pprint(trueWireCharge.shape)
chargeSolving = linear_model.Lasso(positive = True, alpha=0.14)
chargeSolving.fit(geomMatrix,trueWireCharge)
solved = np.matrix(chargeSolving.coef_.reshape(trueCellCharge.shape))
print("\033[92m",solved,"\033[0m")
# pprint(planes)
if __name__ == "__main__":
main(sys.argv)