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="")
 
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 = "" 
)

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=""):
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  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))])))
26 
27  if signed_output:
28  self.width_out += 1
29 
30  self.debug_info(
31  "***************************** {} LUT {} *****************************".format(operation.__name__, label))
32  self.debug_info("Depth: {} x {} (addr x data)".format(width_in, self.width_out))
33  self.debug_info("Scale: {}".format(output_scale_factor))
34 
35  self.width_in = width_in
36  self.output_scale_factor = output_scale_factor
37  self.input_scale_factor = input_scale_factor
38  self.operation = operation
39  self.start_value = start_value
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))]))
43 
44  self.print_error()
45 
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 49 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.

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

◆ debug_info()

def l1tGTSingleInOutLUT.SingleInOutLUT.debug_info (   self,
  msg 
)

Definition at line 46 of file l1tGTSingleInOutLUT.py.

References l1tGTSingleInOutLUT.SingleInOutLUT.debug_txt.

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

◆ export()

def l1tGTSingleInOutLUT.SingleInOutLUT.export (   self,
  filename 
)

Definition at line 57 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.

57  def export(self, filename: str):
58  print(self.debug_txt)
59  with open(filename, "w") as file:
60  for value in self.lut:
61  file.write("{:X}".format(int(value) & ((1 << self.width_out) - 1)
62  ).rjust(math.ceil(self.width_out/4), '0') + "\n")
63 
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 65 of file l1tGTSingleInOutLUT.py.

References funct.abs(), SiStripPI.max, l1tGTSingleInOutLUT.SingleInOutLUT.operation, and FastTimerService_cff.range.

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

◆ print_error()

def l1tGTSingleInOutLUT.SingleInOutLUT.print_error (   self)

Definition at line 71 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, FastTimerService_cff.range, l1tGTSingleInOutLUT.SingleInOutLUT.start_value, l1tGTSingleInOutLUT.SingleInOutLUT.unused_lsbs, and l1tGTSingleInOutLUT.SingleInOutLUT.width_in.

71  def print_error(self):
72  errors = [abs(self.lut[int(i/(2**self.unused_lsbs))]/self.output_scale_factor -
73  self.operation(i * self.lsb + self.start_value)) for i in range(2**(self.width_in + self.unused_lsbs))]
74 
75  self.max_error = max(errors)
76 
77  self.debug_info("Error: {:.5f} +/- {:.5f}, max: {:.5f}, total: {:.5f}, median: {:.5f}".format(
78  mean(errors), stdev(errors), self.max_error, sum(errors), median(errors)))
79 
80  # mass_errors = [errors[i]/(2*self.operation(i * self.lsb + self.start_value)) for i in range(2**(self.width_in + self.unused_lsbs)) ]
81  # self.debug_info("inv mass error: {:.5f} +/- {:.5f}, max: {:.5f}, total: {:.5f}, median: {:.5f}".format(
82  # mean(mass_errors), stdev(mass_errors), max(mass_errors), sum(mass_errors), median(mass_errors)))
83 
84 
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 37 of file l1tGTSingleInOutLUT.py.

◆ lsb

l1tGTSingleInOutLUT.SingleInOutLUT.lsb

◆ lut

l1tGTSingleInOutLUT.SingleInOutLUT.lut

◆ max_error

l1tGTSingleInOutLUT.SingleInOutLUT.max_error

Definition at line 75 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 23 of file l1tGTSingleInOutLUT.py.

Referenced by l1tGTSingleInOutLUT.SingleInOutLUT.export().