CMS 3D CMS Logo

generateTowerEtThresholdLUT.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import sys
5 import math
6 
7 
8 ###############################################################################################
9 # Python script for generating LUT to return tower Et threshold for energy sums #
10 # Input 1: 5 bits - compressed pileup estimate, as used for EG #
11 # Input 2: 6 bits - abs(ieta) = absolute value of ieta of the trigger tower #
12 # Tower Et threshold not applied for ieta <= 15 #
13 # LUT address input = compressedPileupEstimate << 6 | abs(ieta) #
14 # Returns 9 bits for tower et threshold #
15 # Author: Aaron Bundock (aaron.*nospamthankyamaam*bundock@cern.ch) #
16 # Date: 26/04/17 #
17 # #
18 ###############################################################################################
19 
20 # Run from src/ directory in your checked out CMSSW code!
21 
22 # open LUT file for writing
23 if not os.path.isdir(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data"):
24  print(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/ directory does not exist.\n"
25  "Creating directory now.\n"
26  "Remember to do 'git add " + os.environ['LOCALRT'] + "L1Trigger/L1TCalorimeter/data' when committing the new LUT!")
27  os.makedirs(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data")
28 
29 print "Creating tower Et threshold LUT with filename " + os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v3.txt'"
30 towEtThreshLUTFile = open(os.environ['LOCALRT']+"/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v3.txt", "w")
31 
32 
33 # write header info
34 towEtThreshLUTFile.write(
35  "# address to et sum tower Et threshold LUT\n"
36  "# maps 11 bits to 9 bits\n"
37  "# 11 bits = (compressedPileupEstimate << 6) | abs(ieta)\n"
38  "# compressedPileupEstimate is unsigned 5 bits, abs(ieta) is unsigned 6 bits\n"
39  "# data: tower energy threshold returned has 9 bits \n"
40  "# anything after # is ignored with the exception of the header\n"
41  "# the header is first valid line starting with #<header> versionStr nrBitsAddress nrBitsData </header>\n"
42  "#<header> v1 11 9 </header>\n"
43 
44 )
45 
46 # vector of calo tower areas, relative to central barrel areas (0.087 in eta)
47 # excludes ieta=0 and ieta=29, since they don't physically exist!
48 
49 towerAreas = [1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,
50  1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,
51  1.03,1.15,1.3,1.48,1.72,2.05,1.72,4.02,
52  3.29,2.01,2.02,2.01,2.02,2.0,2.03,1.99,2.02,2.04,2.00,3.47];
53 
54 etaRange = xrange(1,41) # 30 towers: skip 1-10. Do not count ieta=29, so count up to ieta = 40
55 compNTT4Range = xrange(0,32) # use compressed pileup estimate from EG LUT
56 addr = 0
57 printBins = ""
58 
59 for compNTT4 in compNTT4Range:
60  for ieta in etaRange:
61  towEtThresh = int(round((float(towerAreas[ieta-1])**1.2)*(1/(1+math.exp(-0.2*(ieta-5))))*(float(compNTT4)/10)))
62  if ieta > 28:
63  towEtThresh -= 4
64  if towEtThresh > 16:
65  towEtThresh = int(16)
66  if ieta < 13 or towEtThresh < 0:
67  towEtThresh = 0
68  if (addr % 64) == 0:
69  printBins = " # nTT4 = " + str(5*compNTT4) + "-" + str((5*compNTT4)+5) + " ieta = " + str(ieta)
70  else:
71  printBins = ""
72  towEtThreshLUTFile.write(
73  str(addr) + " " +
74  str(towEtThresh) +
75  printBins +
76  "\n"
77  )
78  addr+=1
79  if ieta == 40: # dummy to fill 6 bits for eta
80  extraCount = 0
81  while extraCount < 24:
82  towEtThreshLUTFile.write(
83  str(addr) + " " +
84  str(0) +
85  " #dummy\n"
86  )
87  addr+=1
88  extraCount +=1
89 
90 if addr < 2047:
91  for addr in xrange(addr,2047):
92  towEtThreshLUTFile.write(str(addr) + " " + str(0) + " # dummy\n")
93  addr+=1
94 
95 print "Done. Closing file..."
96 
97 towEtThreshLUTFile.close()
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10