CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
l1tGTSingleInOutLUT.SingleInOutLUT Class Reference

Public Member Functions

def __init__ (self, width_in, unused_lsbs, lsb, output_scale_factor, operation, start_value=0, label="", width_out_force=0)
 
def config (self)
 
def debug_info (self, msg)
 
def export
 
def optimal_scale_factor (width_in, max_width_out, unused_lsbs, lsb, operation, start_value=0)
 
def print_error (self)
 

Public Attributes

 debug_txt
 
 input_scale_factor
 
 lsb
 
 lut
 
 max_error
 
 operation
 
 output_scale_factor
 
 start_value
 
 unused_lsbs
 
 width_in
 
 width_out
 

Detailed Description

Definition at line 13 of file l1tGTSingleInOutLUT.py.

Constructor & Destructor Documentation

◆ __init__()

def l1tGTSingleInOutLUT.SingleInOutLUT.__init__ (   self,
  width_in,
  unused_lsbs,
  lsb,
  output_scale_factor,
  operation,
  start_value = 0,
  label = "",
  width_out_force = 0 
)

Definition at line 15 of file l1tGTSingleInOutLUT.py.

15  def __init__(self, width_in, unused_lsbs, lsb, output_scale_factor, operation, start_value=0, label="", width_out_force=0):
16  self.debug_txt = ""
17  input_scale_factor = 2**unused_lsbs * lsb
18  self.unused_lsbs = unused_lsbs
19  self.lsb = lsb
20  signed_output = min([operation(input_scale_factor * (i + 0.5) + start_value)
21  for i in range(2**width_in)]) < 0
22 
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))])))
27  if signed_output:
28  self.width_out += 1
29  else:
30  self.width_out = width_out_force
31 
32  self.debug_info(
33  "***************************** {} LUT {} *****************************".format(operation.__name__, label))
34  self.debug_info("Depth: {} x {} (addr x data)".format(width_in, self.width_out))
35  self.debug_info("Scale: {}".format(output_scale_factor))
36 
37  self.width_in = width_in
38  self.output_scale_factor = output_scale_factor
39  self.input_scale_factor = input_scale_factor
40  self.operation = operation
41  self.start_value = start_value
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)]))
45 
46  self.print_error()
47 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

Member Function Documentation

◆ config()

def l1tGTSingleInOutLUT.SingleInOutLUT.config (   self)

Definition at line 51 of file l1tGTSingleInOutLUT.py.

References CSCTFDTReceiverLUT.lut, EcalTPGFineGrainStripEE::Item.lut, HcalLutSet.lut, LutXml::_Config.lut, l1tGTSingleInOutLUT.SingleInOutLUT.lut, l1tGTSingleInOutLUT.SingleInOutLUT.max_error, l1tGTSingleInOutLUT.SingleInOutLUT.output_scale_factor, and l1tGTSingleInOutLUT.SingleInOutLUT.unused_lsbs.

51  def config(self):
52  return cms.PSet(
53  output_scale_factor=cms.double(self.output_scale_factor),
54  unused_lsbs=cms.uint32(self.unused_lsbs),
55  lut=self.lut,
56  max_error=cms.double(self.max_error)
57  )
58 
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30

◆ debug_info()

def l1tGTSingleInOutLUT.SingleInOutLUT.debug_info (   self,
  msg 
)

Definition at line 48 of file l1tGTSingleInOutLUT.py.

References l1tGTSingleInOutLUT.SingleInOutLUT.debug_txt.

48  def debug_info(self, msg):
49  self.debug_txt += msg + "\n"
50 

◆ export()

def l1tGTSingleInOutLUT.SingleInOutLUT.export (   self,
  filename 
)

Definition at line 59 of file l1tGTSingleInOutLUT.py.

References l1tGTSingleInOutLUT.SingleInOutLUT.debug_txt, createfilelist.int, CSCTFDTReceiverLUT.lut, EcalTPGFineGrainStripEE::Item.lut, HcalLutSet.lut, LutXml::_Config.lut, l1tGTSingleInOutLUT.SingleInOutLUT.lut, print(), and l1tGTSingleInOutLUT.SingleInOutLUT.width_out.

59  def export(self, filename: str):
60  print(self.debug_txt)
61  with open(filename, "w") as file:
62  for value in self.lut:
63  file.write("{:X}".format(int(value) & ((1 << self.width_out) - 1)
64  ).rjust(math.ceil(self.width_out/4), '0') + "\n")
65 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ optimal_scale_factor()

def l1tGTSingleInOutLUT.SingleInOutLUT.optimal_scale_factor (   width_in,
  max_width_out,
  unused_lsbs,
  lsb,
  operation,
  start_value = 0 
)

Definition at line 67 of file l1tGTSingleInOutLUT.py.

References funct.abs(), WZElectronSkims53X_cff.max, l1tGTSingleInOutLUT.SingleInOutLUT.operation, and isotrackApplyRegressor.range.

67  def optimal_scale_factor(width_in, max_width_out, unused_lsbs, lsb, operation, start_value=0):
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)])
71  return scale_factor
72 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ print_error()

def l1tGTSingleInOutLUT.SingleInOutLUT.print_error (   self)

Definition at line 73 of file l1tGTSingleInOutLUT.py.

References funct.abs(), createfilelist.int, l1tGTSingleInOutLUT.SingleInOutLUT.lsb, CSCTFDTReceiverLUT.lut, EcalTPGFineGrainStripEE::Item.lut, HcalLutSet.lut, LutXml::_Config.lut, l1tGTSingleInOutLUT.SingleInOutLUT.lut, GlobalLogicParser::TokenRPN.operation, l1tGTSingleInOutLUT.SingleInOutLUT.operation, L1GtLogicParser::TokenRPN.operation, l1tGTSingleInOutLUT.SingleInOutLUT.output_scale_factor, isotrackApplyRegressor.range, l1tGTSingleInOutLUT.SingleInOutLUT.start_value, l1tGTSingleInOutLUT.SingleInOutLUT.unused_lsbs, and l1tGTSingleInOutLUT.SingleInOutLUT.width_in.

73  def print_error(self):
74  errors = [abs(self.lut[int(i/(2**self.unused_lsbs))]/self.output_scale_factor -
75  self.operation(i * self.lsb + self.start_value)) for i in range(2**(self.width_in + self.unused_lsbs))]
76 
77  self.max_error = max(errors)
78 
79  self.debug_info("Error: {:.5f} +/- {:.5f}, max: {:.5f}, total: {:.5f}, median: {:.5f}".format(
80  mean(errors), stdev(errors), self.max_error, sum(errors), median(errors)))
81 
82  # mass_errors = [errors[i]/(2*self.operation(i * self.lsb + self.start_value)) for i in range(2**(self.width_in + self.unused_lsbs)) ]
83  # self.debug_info("inv mass error: {:.5f} +/- {:.5f}, max: {:.5f}, total: {:.5f}, median: {:.5f}".format(
84  # mean(mass_errors), stdev(mass_errors), max(mass_errors), sum(mass_errors), median(mass_errors)))
85 
86 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static void print_error(const std::exception &e)
T median(std::vector< T > values)
Definition: median.h:16
def stdev(xlist)
Definition: plotscripts.py:69

Member Data Documentation

◆ debug_txt

l1tGTSingleInOutLUT.SingleInOutLUT.debug_txt

◆ input_scale_factor

l1tGTSingleInOutLUT.SingleInOutLUT.input_scale_factor

Definition at line 39 of file l1tGTSingleInOutLUT.py.

◆ lsb

l1tGTSingleInOutLUT.SingleInOutLUT.lsb

◆ lut

l1tGTSingleInOutLUT.SingleInOutLUT.lut

◆ max_error

l1tGTSingleInOutLUT.SingleInOutLUT.max_error

Definition at line 77 of file l1tGTSingleInOutLUT.py.

Referenced by l1tGTSingleInOutLUT.SingleInOutLUT.config().

◆ operation

l1tGTSingleInOutLUT.SingleInOutLUT.operation

◆ output_scale_factor

l1tGTSingleInOutLUT.SingleInOutLUT.output_scale_factor

◆ start_value

l1tGTSingleInOutLUT.SingleInOutLUT.start_value

◆ unused_lsbs

l1tGTSingleInOutLUT.SingleInOutLUT.unused_lsbs

◆ width_in

l1tGTSingleInOutLUT.SingleInOutLUT.width_in

◆ width_out

l1tGTSingleInOutLUT.SingleInOutLUT.width_out

Definition at line 24 of file l1tGTSingleInOutLUT.py.

Referenced by l1tGTSingleInOutLUT.SingleInOutLUT.export().