# Project CMSSW displayed by LXR

File indexing completed on 2023-10-25 09:54:55

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