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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1052 of file trackingPlots.py.

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

Member Function Documentation

◆ create()

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

Definition at line 1070 of file trackingPlots.py.

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

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

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

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

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

References plotting.PlotFolder._onlyForPileup.

Member Data Documentation

◆ _fileName

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1055 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _format

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1056 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _plots

trackingPlots.TrackingSeedingLayerTable._plots
private

◆ _titles

trackingPlots.TrackingSeedingLayerTable._titles
private

Definition at line 1054 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:48
plotting._th1RemoveEmptyBins
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:606
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
trackingPlots.onlyForPileup
onlyForPileup
Definition: trackingPlots.py:309
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:38
genParticles_cff.map
map
Definition: genParticles_cff.py:11