Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:00

0001 #!/usr/bin/env python
0002 
0003 import os
0004 
0005 path = 'L1Trigger/L1TMuonEndCap/data/emtf_luts/vl_lut/'
0006 
0007 
0008 def main():
0009   full_path = os.environ['CMSSW_BASE'] + '/src/' + path + '%s'
0010 
0011   all_files = []
0012 
0013   ph_init_array = []
0014   ph_disp_array = []
0015   th_init_array = []
0016   th_disp_array = []
0017   th_lut_array = []
0018   th_corr_lut_array = []
0019 
0020   # ____________________________________________________________________________
0021   def read_file_into_array(fn, arr, resize=0):
0022     old_size = len(arr)
0023     with open(fn) as f:
0024       for line in f:
0025         for s in line.split():
0026           x = int(s, 16)
0027           arr.append(x)
0028 
0029     new_size = len(arr)
0030     if resize:
0031       for i in xrange(new_size-old_size, resize):
0032         arr.append(0)
0033     return
0034 
0035   def dump_array_into_file(arr, fn):
0036     with open(fn, 'w') as f:
0037       s = ""
0038       for i in xrange(len(arr)):
0039         x = arr[i]
0040         s += ("%i " % x)
0041         if (i+1)%30 == 0:
0042           s += "\n"
0043       f.write(s)
0044 
0045   # ____________________________________________________________________________
0046   for endcap in [1,2]:
0047     for sector in [1,2,3,4,5,6]:
0048 
0049       # ph_init
0050       for st in [0,1,2,3,4]:
0051         ph_init_filename = 'ph_init_full_endcap_%i_sect_%i_st_%i.lut' % (endcap, sector, st)
0052         read_file_into_array((full_path % ph_init_filename), ph_init_array)
0053         all_files.append(ph_init_filename)
0054 
0055       # ph_disp
0056       ph_disp_filename = 'ph_disp_endcap_%i_sect_%i.lut' % (endcap, sector)
0057       read_file_into_array((full_path % ph_disp_filename), ph_disp_array)
0058       all_files.append(ph_disp_filename)
0059 
0060       # th_init
0061       th_init_filename = 'th_init_endcap_%i_sect_%i.lut' % (endcap, sector)
0062       read_file_into_array((full_path % th_init_filename), th_init_array)
0063       all_files.append(th_init_filename)
0064 
0065       # th_disp
0066       th_disp_filename = 'th_disp_endcap_%i_sect_%i.lut' % (endcap, sector)
0067       read_file_into_array((full_path % th_disp_filename), th_disp_array)
0068       all_files.append(th_disp_filename)
0069 
0070       # th_lut
0071       for sub in [1]:
0072         for st in [1]:
0073           for ch in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]:
0074             th_lut_filename = 'vl_th_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0075             read_file_into_array((full_path % th_lut_filename), th_lut_array, resize=128)
0076             all_files.append(th_lut_filename)
0077 
0078       for sub in [2]:
0079         for st in [1]:
0080           for ch in [1,2,3,4,5,6,7,8,9,10,11,12]:
0081             th_lut_filename = 'vl_th_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0082             read_file_into_array((full_path % th_lut_filename), th_lut_array, resize=128)
0083             all_files.append(th_lut_filename)
0084 
0085       for st in [2,3,4]:
0086         for ch in [1,2,3,4,5,6,7,8,9,10,11]:
0087           th_lut_filename = 'vl_th_lut_endcap_%i_sec_%i_st_%i_ch_%i.lut' % (endcap, sector, st, ch)
0088           read_file_into_array((full_path % th_lut_filename), th_lut_array, resize=128)
0089           all_files.append(th_lut_filename)
0090 
0091       # th_corr_lut
0092       for sub in [1]:
0093         for st in [1]:
0094           for ch in [1,2,3,13]:
0095             th_corr_lut_filename = 'vl_th_corr_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0096             read_file_into_array((full_path % th_corr_lut_filename), th_corr_lut_array, resize=128)
0097             all_files.append(th_corr_lut_filename)
0098 
0099       for sub in [2]:
0100         for st in [1]:
0101           for ch in [1,2,3]:
0102             th_corr_lut_filename = 'vl_th_corr_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0103             read_file_into_array((full_path % th_corr_lut_filename), th_corr_lut_array, resize=128)
0104             all_files.append(th_corr_lut_filename)
0105 
0106       pass  # end loop over sector
0107     pass  # end loop over endcap
0108 
0109   # ____________________________________________________________________________
0110   assert(len(all_files) == 12*76)
0111   assert(len(ph_init_array) == 12*61)
0112   assert(len(ph_disp_array) == 12*61)
0113   assert(len(th_init_array) == 12*61)
0114   assert(len(th_disp_array) == 12*61)
0115   assert(len(th_lut_array) == 12*61*128)
0116   assert(len(th_corr_lut_array) == 12*7*128)
0117 
0118   dump_array_into_file(ph_init_array, "ph_init_neighbor.txt")
0119   dump_array_into_file(ph_disp_array, "ph_disp_neighbor.txt")
0120   dump_array_into_file(th_init_array, "th_init_neighbor.txt")
0121   dump_array_into_file(th_disp_array, "th_disp_neighbor.txt")
0122   dump_array_into_file(th_lut_array, "th_lut_neighbor.txt")
0123   dump_array_into_file(th_corr_lut_array, "th_corr_lut_neighbor.txt")
0124 
0125   return
0126 
0127 
0128 # ______________________________________________________________________________
0129 if __name__ == '__main__':
0130 
0131   main()