Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:53

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