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

Constructor & Destructor Documentation

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

Definition at line 1031 of file trackingPlots.py.

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

Member Function Documentation

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

Definition at line 1049 of file trackingPlots.py.

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

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

Definition at line 1054 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().

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

Definition at line 1045 of file trackingPlots.py.

References plotting.PlotFolder._onlyForPileup.

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

Member Data Documentation

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1034 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1035 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

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

Definition at line 1033 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().