forked from cms-sw/cmssw
/
makeEtaLuts.py
92 lines (74 loc) · 2.97 KB
/
makeEtaLuts.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
from __future__ import print_function
etaLUT0=[8.946,7.508,6.279,6.399]
etaLUT1=[-0.159,-0.116,-0.088,-0.128]
#fine eta
for wheel in [-2,-1,0,1,2]:
for station in [1,2,3]:
lut=[]
for i in range(0,7):
p=0
if wheel==0:
if i==3:
p=0
else:
p=i-3
p=int(round(etaLUT0[station-1]*p+etaLUT1[station-1]*p*p*p/abs(p)))
elif (wheel>0):
p=4+(abs(wheel)-1)*7+6-i
p=int(round(etaLUT0[station-1]*p+etaLUT1[station-1]*p*p*p/abs(p)))
else:
p=-(4+(abs(wheel)-1)*7+6-i)
p=int(round(etaLUT0[station-1]*p+etaLUT1[station-1]*p*p*p/abs(p)))
lut.append(str(p))
if wheel>0:
print('etaLUT_plus_{wheel}_{station} = cms.vint32('.format(wheel=wheel,station=station)+','.join(lut)+')\n')
if wheel<0:
print('etaLUT_minus_{wheel}_{station} = cms.vint32('.format(wheel=abs(wheel),station=station)+','.join(lut)+')\n')
if wheel==0:
print('etaLUT_0_{station} = cms.vint32('.format(station=station)+','.join(lut)+')\n')
#wite HLS LUT
HLSINFO={}
#first the singles
for k in range(0,6):
tag=pow(2,k)
HLSINFO[tag]={'e1':lut[k],'e2':0,'q':1}
for l in range(k+1,7):
tag=pow(2,k)+pow(2,l)
HLSINFO[tag]={'e1':lut[k],'e2':lut[l],'q':3}
keys=sorted(HLSINFO.keys())
d1=[]
d2=[]
d3=[]
for N in range(0,pow(2,7)):
if not (N in keys):
d1.append('0')
d2.append('0')
d3.append('0')
else:
d1.append(str(HLSINFO[N]['e1']))
d2.append(str(HLSINFO[N]['e2']))
d3.append(str(HLSINFO[N]['q']))
if wheel>0:
etaTag='plus_'+str(abs(wheel))
elif wheel<0:
etaTag='minus_'+str(abs(wheel))
else:
etaTag='0'
print('const ap_int<8> etaLUT0_'+etaTag+"_"+str(station)+'[128]={'+','.join(d1)+'};\n')
print('const ap_int<8> etaLUT1_'+etaTag+"_"+str(station)+'[128]={'+','.join(d2)+'};\n')
print('const ap_int<8> etaLUTQ_'+etaTag+"_"+str(station)+'[128]={'+','.join(d3)+'};\n')
#coarse eta
for wheel,p in zip([-2,-1,0,1,2],[-13,-6,0,6,13]):
lut=[]
for station in [1,2,3,4]:
if p==0:
lut.append('0')
else:
u=int(round(etaLUT0[station-1]*p+etaLUT1[station-1]*p*p*p/abs(p)))
lut.append(str(u))
if wheel>0:
print('etaCoarseLUT_plus_{wheel}= cms.vint32('.format(wheel=wheel)+','.join(lut)+')\n')
if wheel<0:
print('etaCoarseLUT_minus_{wheel} = cms.vint32('.format(wheel=abs(wheel))+','.join(lut)+')\n')
if wheel==0:
print('etaCoarseLUT_0 = cms.vint32('+','.join(lut)+')\n')