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

Constructor & Destructor Documentation

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

Definition at line 1043 of file trackingPlots.py.

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

Member Function Documentation

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

Definition at line 1061 of file trackingPlots.py.

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

1061  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1062  # [plot][histo]
1063  for plot in self._plots:
1064  plot.create(tdirectoryNEvents, requireAllHistograms)
1065 
def create(self, tdirectoryNEvents, requireAllHistograms=False)
def trackingPlots.TrackingSeedingLayerTable.draw (   self,
  legendLabels,
  prefix = None,
  directory = "",
  args,
  kwargs 
)

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

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

Definition at line 1057 of file trackingPlots.py.

References plotting.PlotFolder._onlyForPileup.

1057  def onlyForPileup(self):
1058  """Return True if the PlotGroup is intended only for pileup samples"""
1059  return self._onlyForPileup
1060 

Member Data Documentation

trackingPlots.TrackingSeedingLayerTable._fileName
private

Definition at line 1046 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

trackingPlots.TrackingSeedingLayerTable._format
private

Definition at line 1047 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

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

Definition at line 1045 of file trackingPlots.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().