CMS 3D CMS Logo

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