2 This computes the most optimal COS_PHI_LUT and COSH_ETA_LUT. Call 3 :func:`~l1tGTSingleInOutLUT.SingleInOutLUT.export` to export the 7 import FWCore.ParameterSet.Config
as cms
8 from L1Trigger.Phase2L1GT.l1tGTScales
import scale_parameter
9 from statistics
import mean, median, stdev
15 def __init__(self, width_in, unused_lsbs, lsb, output_scale_factor, operation, start_value=0, label=""):
17 input_scale_factor = 2**unused_lsbs * lsb
20 signed_output =
min([
operation(input_scale_factor * (i + 0.5) + start_value)
21 for i
in range(2**width_in)]) < 0
23 self.
width_out = math.ceil(math.log2(output_scale_factor *
24 max([
abs(
operation(input_scale_factor * (i + 0.5) + start_value))
for i
in range(2**width_in - 1)] +
25 [
abs(
operation(input_scale_factor * (2**width_in - 1) + start_value))])))
31 "***************************** {} LUT {} *****************************".
format(operation.__name__, label))
40 self.
lut = cms.vint32(
41 * ([round(output_scale_factor *
operation(input_scale_factor * (i + 0.5) + start_value))
for i
in range(2**width_in - 1)]
42 + [round(output_scale_factor *
operation(input_scale_factor * (2 ** width_in - 1) + start_value))]))
59 with open(filename,
"w")
as file:
60 for value
in self.
lut:
62 ).rjust(math.ceil(self.
width_out/4),
'0') +
"\n")
66 input_scale_factor = 2**unused_lsbs * lsb
67 scale_factor = (2**max_width_out - 1) /
max([
abs(
operation(input_scale_factor * (i + 0.5) + start_value))
68 for i
in range(2**width_in)])
77 self.
debug_info(
"Error: {:.5f} +/- {:.5f}, max: {:.5f}, total: {:.5f}, median: {:.5f}".
format(
86 COSH_ETA_IN_WIDTH = 11
90 optimal_scale_factor = math.floor(
91 (2**17 - 1) / (math.cosh((2**(COSH_ETA_IN_WIDTH + 2) - 1)*scale_parameter.eta_lsb.value()) + 1))
94 COS_PHI_IN_WIDTH, 2, scale_parameter.phi_lsb.value(), optimal_scale_factor, math.cos)
98 COSH_ETA_IN_WIDTH, 2, scale_parameter.eta_lsb.value(), optimal_scale_factor, math.cosh, 0,
"[0, 2pi)")
102 COSH_ETA_IN_WIDTH, 2, scale_parameter.eta_lsb.value(),
103 SingleInOutLUT.optimal_scale_factor(
104 COSH_ETA_IN_WIDTH, 17, 2, scale_parameter.eta_lsb.value(), math.cosh, 2**13 * scale_parameter.eta_lsb.value()),
105 math.cosh, 2**13 * scale_parameter.eta_lsb.value(),
"[2pi, 4pi)")
def debug_info(self, msg)
def optimal_scale_factor(width_in, max_width_out, unused_lsbs, lsb, operation, start_value=0)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)
def __init__(self, width_in, unused_lsbs, lsb, output_scale_factor, operation, start_value=0, label="")