Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 
0003 import os
0004 import sys
0005 import math
0006 
0007 
0008 ###############################################################################################
0009 #  Python script for generating LUT to return tower Et threshold for energy sums              #
0010 #  Input 1: 5 bits - compressed pileup estimate, as used for EG                               #
0011 #  Input 2: 6 bits - abs(ieta) = absolute value of ieta of the trigger tower                  #
0012 #  Tower Et threshold not applied for ieta <= 15                                              # 
0013 #  LUT address input = compressedPileupEstimate << 6 | abs(ieta)                              #
0014 #  Returns 9 bits for tower et threshold                                                      #
0015 #  Author: Aaron Bundock (aaron.*nospamthankyamaam*bundock@cern.ch)                           #
0016 #  Date: 26/04/17                                                                             #  
0017 #                                                                                             #
0018 ###############################################################################################
0019 
0020 # Run from src/ directory in your checked out CMSSW code!
0021 
0022 # open LUT file for writing
0023 if not os.path.isdir(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data"):
0024     print(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/ directory does not exist.\n"
0025           "Creating directory now.\n"
0026           "Remember to do 'git add " + os.environ['LOCALRT'] + "L1Trigger/L1TCalorimeter/data' when committing the new LUT!")
0027     os.makedirs(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data")
0028 
0029 print("Creating tower Et threshold LUT with filename " + os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v4_excl30.txt'")
0030 towEtThreshLUTFile = open(os.environ['LOCALRT']+"/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v4_excl30.txt", "w")
0031 
0032 
0033 # write header info
0034 towEtThreshLUTFile.write(
0035     "# address to et sum tower Et threshold LUT\n"
0036     "# maps 11 bits to 9 bits\n"
0037     "# 11 bits = (compressedPileupEstimate << 6) | abs(ieta)\n"
0038     "# compressedPileupEstimate is unsigned 5 bits, abs(ieta) is unsigned 6 bits\n"
0039     "# data: tower energy threshold returned has 9 bits \n"
0040     "# anything after # is ignored with the exception of the header\n"
0041     "# the header is first valid line starting with #<header> versionStr nrBitsAddress nrBitsData </header>\n"
0042     "#<header> v1 11 9 </header>\n" 
0043 
0044 )
0045 
0046 # vector of calo tower areas, relative to central barrel areas (0.087 in eta)
0047 # dummy for ieta=0 and excludes ieta=29, since they don't physically exist!
0048 
0049 towerAreas = [0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,
0050                   1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,
0051                   1.03,1.15,1.3,1.48,1.72,2.05,1.72,4.02,
0052                   3.29,2.01,2.02,2.01,2.02,2.0,2.03,1.99,2.02,2.04,2.00,3.47];
0053   
0054 etaRange = xrange(0,41) # dummy entry for ieta=0, do not count ieta=29, so count 40 towers
0055 compNTT4Range = xrange(0,32) #  use compressed pileup estimate from EG LUT
0056 addr = 0
0057 printBins = ""
0058 
0059 for compNTT4 in compNTT4Range:
0060     for ieta in etaRange:
0061         towEtThresh = int(round(float(towerAreas[ieta])*(1/(1+math.exp(-0.2*(ieta-5))))*(float(compNTT4)/10)))
0062         if ieta > 28:
0063             towEtThresh -= 4
0064         if towEtThresh > 16:
0065             towEtThresh = int(16)
0066         if ieta < 13 or towEtThresh < 0:
0067             towEtThresh = 0
0068         if ieta == 29:
0069             towEtThresh = 511
0070         if (addr % 64) == 0:
0071             printBins = "             # nTT4 = " + str(5*compNTT4) + "-" + str((5*compNTT4)+5) + " ieta = " + str(ieta)  
0072         else:
0073             printBins = ""
0074         towEtThreshLUTFile.write(
0075             str(addr) + " " + 
0076             str(towEtThresh) +
0077             printBins +
0078             "\n"
0079             )
0080         addr+=1
0081     if ieta == 40: # dummy to fill 6 bits for eta
0082         extraCount = 0
0083         while extraCount < 23:
0084             towEtThreshLUTFile.write(
0085                 str(addr) + " " + 
0086                 str(0) + 
0087                 " #dummy\n"
0088                 )
0089             addr+=1
0090             extraCount +=1
0091 
0092 if addr < 2047:
0093     for addr in xrange(addr,2047):
0094         towEtThreshLUTFile.write(str(addr) + " " + str(0) + " # dummy\n")
0095         addr+=1
0096 
0097 print("Done. Closing file...")
0098 
0099 towEtThreshLUTFile.close()