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

Constructor & Destructor Documentation

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

Definition at line 1012 of file trackingPlots.py.

1012  def __init__(self, fileName, plots, titles, isRate, **kwargs):
1013  self._plots = plots
1014  self._titles = titles
1015  self._fileName = fileName
1016  self._format = "%.4g" if isRate else "%d"
1017 
1018  if len(plots) != len(titles):
1019  raise Exception("Number of plots (%d) has to be the same as number of titles (%d)" % (len(plots), len(titles)))
1020 
1021  def _set(attr, default):
1022  setattr(self, "_"+attr, kwargs.get(attr, default))
1023 
1024  _set("onlyForPileup", False)
1025 
def __init__(self, fileName, plots, titles, isRate, kwargs)

Member Function Documentation

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

Definition at line 1030 of file trackingPlots.py.

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

1030  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1031  # [plot][histo]
1032  for plot in self._plots:
1033  plot.create(tdirectoryNEvents, requireAllHistograms)
1034 
def create(self, tdirectoryNEvents, requireAllHistograms=False)
def trackingPlots.TrackingSeedingLayerTable.draw (   self,
  legendLabels,
  prefix = None,
  directory = "",
  args,
  kwargs 
)

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

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

References plotting.PlotFolder._onlyForPileup.

1026  def onlyForPileup(self):
1027  """Return True if the PlotGroup is intended only for pileup samples"""
1028  return self._onlyForPileup
1029 

Member Data Documentation

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1015 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1016 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

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

Definition at line 1014 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().