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 1037 of file trackingPlots.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1038 of file trackingPlots.py.

1038  def __init__(self, fileName, plots, titles, isRate, **kwargs):
1039  self._plots = plots
1040  self._titles = titles
1041  self._fileName = fileName
1042  self._format = "%.4g" if isRate else "%d"
1043 
1044  if len(plots) != len(titles):
1045  raise Exception("Number of plots (%d) has to be the same as number of titles (%d)" % (len(plots), len(titles)))
1046 
1047  def _set(attr, default):
1048  setattr(self, "_"+attr, kwargs.get(attr, default))
1049 
1050  _set("onlyForPileup", False)
1051 

Member Function Documentation

◆ create()

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

Definition at line 1056 of file trackingPlots.py.

1056  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1057  # [plot][histo]
1058  for plot in self._plots:
1059  plot.create(tdirectoryNEvents, requireAllHistograms)
1060 

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 1061 of file trackingPlots.py.

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

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 1052 of file trackingPlots.py.

1052  def onlyForPileup(self):
1053  """Return True if the PlotGroup is intended only for pileup samples"""
1054  return self._onlyForPileup
1055 

References plotting.PlotFolder._onlyForPileup.

Member Data Documentation

◆ _fileName

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1041 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _format

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1042 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _plots

trackingPlots.TrackingSeedingLayerTable._plots
private

◆ _titles

trackingPlots.TrackingSeedingLayerTable._titles
private

Definition at line 1040 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:707
ntuplePlotting.draw
def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs)
Definition: ntuplePlotting.py:24
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
html.Table
Definition: html.py:293
plotting._th1IncludeOnlyBins
def _th1IncludeOnlyBins(histos, xbinlabels)
Definition: plotting.py:744
str
#define str(s)
Definition: TestProcessor.cc:53
plotting._th1RemoveEmptyBins
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:607
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
trackingPlots.onlyForPileup
onlyForPileup
Definition: trackingPlots.py:299
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