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

Constructor & Destructor Documentation

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

Definition at line 1029 of file trackingPlots.py.

1029  def __init__(self, fileName, plots, titles, isRate, **kwargs):
1030  self._plots = plots
1031  self._titles = titles
1032  self._fileName = fileName
1033  self._format = "%.4g" if isRate else "%d"
1034 
1035  if len(plots) != len(titles):
1036  raise Exception("Number of plots (%d) has to be the same as number of titles (%d)" % (len(plots), len(titles)))
1037 
1038  def _set(attr, default):
1039  setattr(self, "_"+attr, kwargs.get(attr, default))
1040 
1041  _set("onlyForPileup", False)
1042 
def __init__(self, fileName, plots, titles, isRate, kwargs)

Member Function Documentation

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

Definition at line 1047 of file trackingPlots.py.

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

1047  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1048  # [plot][histo]
1049  for plot in self._plots:
1050  plot.create(tdirectoryNEvents, requireAllHistograms)
1051 
def create(self, tdirectoryNEvents, requireAllHistograms=False)
def trackingPlots.TrackingSeedingLayerTable.draw (   self,
  legendLabels,
  prefix = None,
  directory = "",
  args,
  kwargs 
)

Definition at line 1052 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, genParticles_cff.map, SiStripPI.max, str, and ComparisonHelper.zip().

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

Definition at line 1043 of file trackingPlots.py.

References plotting.PlotFolder._onlyForPileup.

1043  def onlyForPileup(self):
1044  """Return True if the PlotGroup is intended only for pileup samples"""
1045  return self._onlyForPileup
1046 

Member Data Documentation

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1032 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1033 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._plots
private
trackingPlots.TrackingSeedingLayerTable._titles
private

Definition at line 1031 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().