CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Attributes
trackingPlots.TrackingSeedingLayerTable Class Reference

Public Member Functions

def __init__
 
def create
 
def draw
 
def onlyForPileup
 

Private Attributes

 _fileName
 
 _format
 
 _plots
 
 _titles
 

Detailed Description

Definition at line 1037 of file trackingPlots.py.

Constructor & Destructor Documentation

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

Definition at line 1038 of file trackingPlots.py.

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

Member Function Documentation

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

Definition at line 1056 of file trackingPlots.py.

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

1057  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1058  # [plot][histo]
1059  for plot in self._plots:
1060  plot.create(tdirectoryNEvents, requireAllHistograms)
def trackingPlots.TrackingSeedingLayerTable.draw (   self,
  legendLabels,
  prefix = None,
  directory = "",
  args,
  kwargs 
)

Definition at line 1061 of file trackingPlots.py.

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, SiStripPI.max, sistrip::SpyUtilities.range(), str, and ComparisonHelper.zip().

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

Definition at line 1052 of file trackingPlots.py.

References plotting.PlotFolder._onlyForPileup.

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

Member Data Documentation

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1041 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1042 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._plots
private

Definition at line 1039 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.create(), and trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._titles
private

Definition at line 1040 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().