Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-27 03:17:55

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 
0004 from L1Trigger.L1TMuonBarrel.simKBmtfDigis_cfi import bmtfKalmanTrackingSettings as settings
0005 
0006 initialK = settings.initialK
0007 initialK2 = settings.initialK2
0008 
0009 def bits(number, size_in_bits):
0010     """
0011     The bin() function is *REALLY* unhelpful when working with negative numbers.
0012     It outputs the binary representation of the positive version of that number
0013     with a '-' at the beginning. Woop-di-do. Here's how to derive the two's-
0014     complement binary of a negative number:
0015 
0016         complement(bin(+n - 1))
0017 
0018     `complement` is a function that flips each bit. `+n` is the negative number
0019     made positive.
0020 
0021     """
0022     if number < 0:
0023         return compliment(bin(abs(number) - 1)[2:]).rjust(size_in_bits, '1')
0024     else:
0025         return bin(number)[2:].rjust(size_in_bits, '0')
0026 
0027 def compliment(value):
0028     return ''.join(COMPLEMENT[x] for x in value)
0029 
0030 COMPLEMENT = {'1': '0', '0': '1'}
0031 
0032 
0033 
0034 for i in range(0,4):
0035     arr = []
0036     for k in range(0,1024):
0037         arr.append(0)
0038     for phiB in range(-512,512):
0039         address = int(bits(phiB,10),2)       
0040         factor=phiB    
0041         if i in [2,3]:
0042             if abs(phiB)>63:
0043                 factor = 63*phiB/abs(phiB)
0044         if i in [1,0]:
0045             if abs(phiB)>127:
0046                 factor = 127*phiB/abs(phiB)
0047         if factor!=0:         
0048             charge= phiB/abs(phiB)
0049         else:
0050             charge=0;
0051         
0052         K = int(initialK[i]*8*factor/(1+initialK2[i]*8*charge*factor))
0053         if K>8191:
0054             K=8191
0055         if K<-8191:
0056             K=-8191
0057         arr[address]=str(K)    
0058 #    import pdb;pdb.set_trace()    
0059     print('\n\n\n'    )
0060     if i in [0,1]:
0061         lut = 'ap_int<14> initialK_'+str(i+1)+'[1024] = {'+','.join(arr)+'};'
0062     if i in [2,3]:
0063         lut = 'ap_int<14> initialK_'+str(i+1)+'[1024] = {'+','.join(arr)+'};'
0064     print(lut)
0065 
0066         
0067 
0068 
0069