CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trackingPlots.TrackingSeedingLayerTable Class Reference

Public Member Functions

def __init__ (self, fileName, plots, titles, isRate, **kwargs)
 
def create (self, tdirectoryNEvents, requireAllHistograms=False)
 
def draw (self, legendLabels, prefix=None, directory="", *args, **kwargs)
 
def onlyForPileup (self)
 

Private Attributes

 _fileName
 
 _format
 
 _plots
 
 _titles
 

Detailed Description

Definition at line 1053 of file trackingPlots.py.

Constructor & Destructor Documentation

◆ __init__()

def trackingPlots.TrackingSeedingLayerTable.__init__ (   self,
  fileName,
  plots,
  titles,
  isRate,
**  kwargs 
)

Definition at line 1054 of file trackingPlots.py.

1054  def __init__(self, fileName, plots, titles, isRate, **kwargs):
1055  self._plots = plots
1056  self._titles = titles
1057  self._fileName = fileName
1058  self._format = "%.4g" if isRate else "%d"
1059 
1060  if len(plots) != len(titles):
1061  raise Exception("Number of plots (%d) has to be the same as number of titles (%d)" % (len(plots), len(titles)))
1062 
1063  def _set(attr, default):
1064  setattr(self, "_"+attr, kwargs.get(attr, default))
1065 
1066  _set("onlyForPileup", False)
1067 

Member Function Documentation

◆ create()

def trackingPlots.TrackingSeedingLayerTable.create (   self,
  tdirectoryNEvents,
  requireAllHistograms = False 
)

Definition at line 1072 of file trackingPlots.py.

1072  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1073  # [plot][histo]
1074  for plot in self._plots:
1075  plot.create(tdirectoryNEvents, requireAllHistograms)
1076 

References trackingPlots.TrackingSeedingLayerTable._plots, plotting.PlotGroup._plots, plotting.PlotOnSideGroup._plots, and plotting.Plotter._plots.

◆ draw()

def trackingPlots.TrackingSeedingLayerTable.draw (   self,
  legendLabels,
  prefix = None,
  directory = "",
args,
**  kwargs 
)

Definition at line 1077 of file trackingPlots.py.

1077  def draw(self, legendLabels, prefix=None, directory="", *args, **kwargs):
1078  # Do not make the table if it would be empty
1079  onlyEmptyPlots = True
1080  for plot in self._plots:
1081  if not plot.isEmpty():
1082  onlyEmptyPlots = False
1083  break
1084  if onlyEmptyPlots:
1085  return []
1086 
1087  haveShortLabels = False
1088  legendLabels = legendLabels[:]
1089  if max(map(len, legendLabels)) > 20:
1090  haveShortLabels = True
1091  labels_short = [str(chr(ord('A')+i)) for i in range(len(legendLabels))]
1092  for i, ls in enumerate(labels_short):
1093  legendLabels[i] = "%s: %s" % (ls, legendLabels[i])
1094  else:
1095  labels_short = legendLabels
1096 
1097  content = [
1098  '<html>',
1099  ' <body>',
1100  ' <table border="1">',
1101  ' <tr>',
1102  ]
1103 
1104 
1105  histos_linear = []
1106  histos_index = []
1107  labels = []
1108  for plot, title in zip(self._plots, self._titles):
1109  h_tmp = []
1110  l_tmp = []
1111  for h, l in zip(plot._histograms, labels_short):
1112  if h is not None:
1113  h_tmp.append(len(histos_linear))
1114  histos_linear.append(h)
1115  l_tmp.append(l)
1116 
1117  if len(h_tmp) > 0:
1118  histos_index.append(h_tmp)
1119  labels.append(l_tmp)
1120  content.extend([
1121  ' <td></td>',
1122  ' <td colspan="%d">%s</td>' % (len(h_tmp), title),
1123  ])
1124 
1125  if len(histos_linear) == 0:
1126  return []
1127 
1128  content.extend([
1129  ' </tr>',
1130  ' <tr>',
1131  ])
1132 
1133  xbinlabels = plotting._mergeBinLabelsX(histos_linear)
1134  histos_linear = plotting._th1IncludeOnlyBins(histos_linear, xbinlabels)
1135  if len(histos_linear) == 0:
1136  return []
1137  (histos_linear_new, xbinlabels) = plotting._th1RemoveEmptyBins(histos_linear, xbinlabels)
1138  # in practice either all histograms are returned, or none, but let's add a check anyway
1139  if len(histos_linear_new) > 0 and len(histos_linear_new) != len(histos_linear):
1140  raise Exception("This should never happen. len(histos_linear_new) %d != len(histos_linear) %d" % (len(histos_linear_new), len(histos_linear)))
1141  histos_linear = histos_linear_new
1142  if len(histos_linear) == 0:
1143  return []
1144 
1145  data = [ [h.GetBinContent(i) for i in range(1, h.GetNbinsX()+1)] for h in histos_linear]
1146  table = html.Table(["dummy"]*len(histos_linear), xbinlabels, data, None, None, None)
1147  data = table.tableAsRowColumn()
1148 
1149  for labs in labels:
1150  content.append(' <td></td>')
1151  content.extend([' <td>%s</td>' % lab for lab in labs])
1152  content.extend([
1153  ' </tr>',
1154  ])
1155 
1156  for irow, row in enumerate(data):
1157  content.extend([
1158  ' <tr>',
1159  ' <td>%s</td>' % table.rowHeaders()[irow]
1160  ])
1161 
1162  for hindices in histos_index:
1163  for hindex in hindices:
1164  item = row[hindex]
1165  formatted = self._format%item if item is not None else ""
1166  content.append(' <td align="right">%s</td>' % formatted)
1167  content.append(' <td></td>')
1168  del content[-1]
1169  content.append(' </tr>')
1170 
1171  content.append(' </table>')
1172  if haveShortLabels:
1173  for lab in legendLabels:
1174  content.append(' %s<br/>' % lab)
1175 
1176  content.extend([
1177  ' </body>',
1178  '<html>'
1179  ])
1180 
1181  name = self._fileName
1182  if prefix is not None:
1183  name = prefix+name
1184  name += ".html"
1185  name = os.path.join(directory, name)
1186 
1187  with open(name, "w") as f:
1188  for line in content:
1189  f.write(line)
1190  f.write("\n")
1191  return [name]
1192 

References L1Validator._fileName, trackingPlots.TrackingSeedingLayerTable._fileName, trackingPlots.TrackingSeedingLayerTable._format, plotting._mergeBinLabelsX(), trackingPlots.TrackingSeedingLayerTable._plots, plotting.PlotGroup._plots, plotting.PlotOnSideGroup._plots, plotting.Plotter._plots, plotting._th1IncludeOnlyBins(), plotting._th1RemoveEmptyBins(), trackingPlots.TrackingSeedingLayerTable._titles, genParticles_cff.map, SiStripPI.max, FastTimerService_cff.range, str, and ComparisonHelper.zip().

◆ onlyForPileup()

def trackingPlots.TrackingSeedingLayerTable.onlyForPileup (   self)
Return True if the PlotGroup is intended only for pileup samples

Definition at line 1068 of file trackingPlots.py.

1068  def onlyForPileup(self):
1069  """Return True if the PlotGroup is intended only for pileup samples"""
1070  return self._onlyForPileup
1071 

References plotting.PlotFolder._onlyForPileup.

Member Data Documentation

◆ _fileName

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1057 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _format

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1058 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _plots

trackingPlots.TrackingSeedingLayerTable._plots
private

◆ _titles

trackingPlots.TrackingSeedingLayerTable._titles
private

Definition at line 1056 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
plotting._mergeBinLabelsX
def _mergeBinLabelsX(histos)
Definition: plotting.py:706
ntuplePlotting.draw
def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs)
Definition: ntuplePlotting.py:25
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
html.Table
Definition: html.py:253
plotting._th1IncludeOnlyBins
def _th1IncludeOnlyBins(histos, xbinlabels)
Definition: plotting.py:743
str
#define str(s)
Definition: TestProcessor.cc:51
plotting._th1RemoveEmptyBins
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:606
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
trackingPlots.onlyForPileup
onlyForPileup
Definition: trackingPlots.py:310
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:41
genParticles_cff.map
map
Definition: genParticles_cff.py:11