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

Constructor & Destructor Documentation

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

Definition at line 1028 of file trackingPlots.py.

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

Member Function Documentation

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

Definition at line 1046 of file trackingPlots.py.

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

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

Definition at line 1051 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, harvestTrackValidationPlots.str, and ComparisonHelper.zip().

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

References plotting.PlotFolder._onlyForPileup.

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

Member Data Documentation

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1031 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1032 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

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

Definition at line 1030 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().