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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1037 of file trackingPlots.py.

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

Member Function Documentation

◆ create()

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

Definition at line 1055 of file trackingPlots.py.

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

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

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

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

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

References plotting.PlotFolder._onlyForPileup.

Member Data Documentation

◆ _fileName

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1040 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _format

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1041 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

◆ _plots

trackingPlots.TrackingSeedingLayerTable._plots
private

◆ _titles

trackingPlots.TrackingSeedingLayerTable._titles
private

Definition at line 1039 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:708
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:294
plotting._th1IncludeOnlyBins
def _th1IncludeOnlyBins(histos, xbinlabels)
Definition: plotting.py:745
str
#define str(s)
Definition: TestProcessor.cc:52
plotting._th1RemoveEmptyBins
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:608
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
trackingPlots.onlyForPileup
onlyForPileup
Definition: trackingPlots.py:300
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