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="", width_out_force=0):
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 if width_out_force == 0:
24 self.
width_out = math.ceil(math.log2(output_scale_factor *
25 max([
abs(
operation(input_scale_factor * (i + 0.5) + start_value))
for i
in range(2**width_in - 1)] +
26 [
abs(
operation(input_scale_factor * (2**width_in - 1) + start_value))])))
33 "***************************** {} LUT {} *****************************".
format(operation.__name__, label))
42 self.
lut = cms.vint32(
43 * ([
min(round(output_scale_factor *
operation(input_scale_factor * (i + 0.5) + start_value)), 2**self.
width_out - 1)
for i
in range(2**width_in - 1)]
44 + [
min(round(output_scale_factor *
operation(input_scale_factor * (2 ** width_in - 1) + start_value)), 2**self.
width_out - 1)]))
61 with open(filename,
"w")
as file:
62 for value
in self.
lut:
64 ).rjust(math.ceil(self.
width_out/4),
'0') +
"\n")
68 input_scale_factor = 2**unused_lsbs * lsb
69 scale_factor = (2**max_width_out - 1) /
max([
abs(
operation(input_scale_factor * (i + 0.5) + start_value))
70 for i
in range(2**width_in)])
79 self.
debug_info(
"Error: {:.5f} +/- {:.5f}, max: {:.5f}, total: {:.5f}, median: {:.5f}".
format(
88 COSH_ETA_IN_WIDTH = 11
92 optimal_scale_factor_lower = math.floor(
93 (2**17 - 1) / (math.cosh((2**(COSH_ETA_IN_WIDTH + 2) - 1)*scale_parameter.eta_lsb.value()) + 1))
96 COS_PHI_IN_WIDTH, 2, scale_parameter.phi_lsb.value(), optimal_scale_factor_lower, math.cos)
100 COSH_ETA_IN_WIDTH, 2, scale_parameter.eta_lsb.value(), optimal_scale_factor_lower, math.cosh, 0,
"[0, 2pi)")
102 optimal_scale_factor_upper = SingleInOutLUT.optimal_scale_factor(
103 COSH_ETA_IN_WIDTH, 17, 2, scale_parameter.eta_lsb.value(), math.cosh, 2**13 * scale_parameter.eta_lsb.value())
108 optimal_scale_factor_upper = optimal_scale_factor_lower / \
109 math.pow(2, math.floor(math.log2(optimal_scale_factor_lower / optimal_scale_factor_upper)))
113 COSH_ETA_IN_WIDTH, 2, scale_parameter.eta_lsb.value(), optimal_scale_factor_upper, math.cosh, 2**13 * scale_parameter.eta_lsb.value(),
"[2pi, 4pi)", 17)
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="", width_out_force=0)