CMS 3D CMS Logo

html.py
Go to the documentation of this file.
1 import os
2 import collections
3 import six
4 
5 def _lowerFirst(s):
6  return s[0].lower()+s[1:]
7 
8 _sampleName = {
9  "RelValMinBias": "Min Bias",
10  "RelValTTbar": "TTbar",
11  "RelValQCD_Pt_600_800": "QCD Pt 600 to 800",
12  "RelValQCD_Pt_3000_3500": "QCD Pt 3000 to 3500",
13  "RelValQCD_FlatPt_15_3000": "QCD Flat Pt 15 to 3000",
14  "RelValZMM": "ZMuMu",
15  "RelValWjet_Pt_3000_3500": "Wjet Pt 3000 to 3500",
16  "RelValH125GGgluonfusion": "Higgs to gamma gamma",
17  "RelValSingleElectronPt35": "Single Electron Pt 35",
18  "RelValSingleElectronPt35Extended": "Single Electron Pt 35 (extended eta)",
19  "RelValSingleElectronPt10": "Single Electron Pt 10",
20  "RelValSingleMuPt1": "Single Muon Pt 1",
21  "RelValSingleMuPt10": "Single Muon Pt 10",
22  "RelValSingleMuPt10Extended": "Single Muon Pt 10 (extended eta)",
23  "RelValSingleMuPt100": "Single Muon Pt 100",
24  "RelValTenMuE_0_200": "Ten muon Pt 0-200",
25 }
26 
27 _sampleFileName = {
28  "RelValMinBias": "minbias",
29  "RelValTTbar": "ttbar",
30  "RelValQCD_Pt_600_800": "qcd600",
31  "RelValQCD_Pt_3000_3500": "qcd3000",
32  "RelValQCD_FlatPt_15_3000": "qcdflat",
33  "RelValZMM": "zmm",
34  "RelValWjet_Pt_3000_3500": "wjet3000",
35  "RelValH125GGgluonfusion": "hgg",
36  "RelValSingleElectronPt35": "ele35",
37  "RelValSingleElectronPt35Extended": "ele35ext",
38  "RelValSingleElectronPt10": "ele10",
39  "RelValSingleMuPt1": "mu1",
40  "RelValSingleMuPt10": "mu10",
41  "RelValSingleMuPt10Extended": "mu10ext",
42  "RelValSingleMuPt100": "mu100",
43  "RelValTenMuE_0_200": "tenmu200",
44 }
45 
46 _allName = "All tracks"
47 _allTPEfficName = _allName+" (all TPs)"
48 _fromPVName = "Tracks from PV"
49 _fromPVAllTPName = "Tracks from PV (all TPs)"
50 _tpPtLess09Name = "All tracks (TP pT < 0.9 GeV)"
51 _tpEtaGreater2p7Name = "All tracks (TP |eta| > 2.7)"
52 _conversionName = "Tracks for conversions"
53 _gsfName = "Electron GSF tracks"
54 _bhadronName = "All tracks (B-hadron TPs)"
55 def _toHP(s):
56  return "High purity "+_lowerFirst(s)
57 def _toOriAlgo(s):
58  return s.replace("tracks", "tracks by originalAlgo")
59 def _toAlgoMask(s):
60  return s.replace("tracks", "tracks by algoMask")
61 def _allToHP(s):
62  return s.replace("All", "High purity")
63 def _allToBTV(s):
64  return s.replace("All", "BTV-like")
65 def _ptCut(s):
66  return s.replace("Tracks", "Tracks pT > 0.9 GeV").replace("tracks", "tracks pT > 0.9 GeV")
67 _trackQualityNameOrder = collections.OrderedDict([
68  ("seeding_seeds", "Seeds"),
69  ("seeding_seedsa", "Seeds A"),
70  ("seeding_seedsb", "Seeds B"),
71  ("seeding_seedsc", "Seeds C"),
72  ("seeding_seedstripl", "Seeds triplets"),
73  ("seeding_seedspair", "Seeds pairs"),
74  ("building_", "Built tracks"),
75  ("", _allName),
76  ("highPurity", _allToHP(_allName)),
77  ("Pt09", "Tracks pT > 0.9 GeV"),
78  ("highPurityPt09", "High purity tracks pT > 0.9 GeV"),
79  ("ByOriginalAlgo", _toOriAlgo(_allName)),
80  ("highPurityByOriginalAlgo", _toOriAlgo(_toHP(_allName))),
81  ("ByAlgoMask", _toAlgoMask(_allName)),
82  ("highPurityByAlgoMask", _toAlgoMask(_toHP(_allName))),
83  ("tpPtLess09_", _tpPtLess09Name),
84  ("tpPtLess09_highPurity", _allToHP(_tpPtLess09Name)),
85  ("tpPtLess09_ByOriginalAlgo", _toOriAlgo(_tpPtLess09Name)),
86  ("tpPtLess09_highPurityByOriginalAlgo", _toOriAlgo(_allToHP(_tpPtLess09Name))),
87  ("tpPtLess09_ByAlgoMask", _toAlgoMask(_tpPtLess09Name)),
88  ("tpPtLess09_highPurityByAlgoMask", _toAlgoMask(_allToHP(_tpPtLess09Name))),
89  ("tpEtaGreater2p7_", _tpEtaGreater2p7Name),
90  ("tpEtaGreater2p7_highPurity", _allToHP(_tpEtaGreater2p7Name)),
91  ("btvLike", _allToBTV(_allName)),
92  ("ak4PFJets", "AK4 PF jets"),
93  ("allTPEffic_", _allTPEfficName),
94  ("allTPEffic_highPurity", _allToHP(_allTPEfficName)),
95  ("fromPV_", _fromPVName),
96  ("fromPV_highPurity", _toHP(_fromPVName)),
97  ("fromPV_Pt09", _ptCut(_fromPVName)),
98  ("fromPV_highPurityPt09", _toHP(_ptCut(_fromPVName))),
99  ("fromPVAllTP_", _fromPVAllTPName),
100  ("fromPVAllTP_highPurity", _toHP(_fromPVAllTPName)),
101  ("fromPVAllTP_Pt09", _ptCut(_fromPVAllTPName)),
102  ("fromPVAllTP_highPurityPt09", _toHP(_ptCut(_fromPVAllTPName))),
103  ("fromPVAllTP2_", _fromPVAllTPName.replace("PV", "PV v2")),
104  ("fromPVAllTP2_highPurity", "High purity "+_lowerFirst(_fromPVAllTPName).replace("PV", "PV v2")),
105  ("fromPVAllTP2_Pt09", _fromPVAllTPName.replace("Tracks", "Tracks pT > 0.9 GeV").replace("PV", "PV v2")),
106  ("fromPVAllTP2_highPurityPt09", _toHP(_ptCut(_fromPVAllTPName)).replace("PV", "PV v2")),
107  ("conversion_", _conversionName),
108  ("gsf_", _gsfName),
109  ("bhadron_", _bhadronName),
110  ("bhadron_highPurity", _allToHP(_bhadronName)),
111  ("bhadron_ByOriginalAlgo", _toOriAlgo(_bhadronName)),
112  ("bhadron_highPurityByOriginalAlgo", _toOriAlgo(_toHP(_bhadronName))),
113  ("bhadron_ByAlgoMask", _toAlgoMask(_bhadronName)),
114  ("bhadron_highPurityByAlgoMask", _toAlgoMask(_allToHP(_bhadronName))),
115  ("bhadron_btvLike", _allToBTV(_bhadronName)),
116 ])
117 
118 _trackAlgoName = {
119  "ootb": "Out of the box",
120  "iter0" : "Iterative Step 0",
121  "iter1" : "Iterative Step 1",
122  "iter2" : "Iterative Step 2",
123  "iter3" : "Iterative Step 3",
124  "iter4" : "Iterative Step 4",
125  "iter5" : "Iterative Step 5",
126  "iter6" : "Iterative Step 6",
127  "iter7" : "Iterative Step 7",
128  "iter9" : "Iterative Step 9",
129  "iter10": "Iterative Step 10",
130 }
131 
132 _trackAlgoOrder = [
133  'ootb',
134  'initialStepPreSplitting',
135  'initialStep',
136  'highPtTripletStep',
137  'detachedQuadStep',
138  'detachedTripletStep',
139  'lowPtQuadStep',
140  'lowPtTripletStep',
141  'pixelPairStep',
142  'mixedTripletStep',
143  'pixelLessStep',
144  'tobTecStep',
145  'jetCoreRegionalStep',
146  'muonSeededStepInOut',
147  'muonSeededStepOutIn',
148  'duplicateMerge',
149  'convStep',
150  'conversionStep',
151  'ckfInOutFromConversions',
152  'ckfOutInFromConversions',
153  'electronGsf',
154  'iter0',
155  'iter1',
156  'iter2',
157  'iter3',
158  'iter4',
159  'iter5',
160  'iter6',
161  'iter7',
162  'iter9',
163  'iter10',
164 ]
165 
166 _pageNameMap = {
167  "summary": "Summary",
168  "vertex": "Vertex",
169  "v0": "V0",
170  "miniaod": "MiniAOD",
171  "timing": "Timing",
172  "hlt": "HLT",
173  "pixel": "Pixel tracks",
174  "pf": "PF",
175 }
176 
177 _sectionNameMapOrder = collections.OrderedDict([
178  # These are for the summary page
179  ("seeding_seeds", "Seeds"),
180  ("building", "Built tracks"),
181  ("", "All tracks"),
182  ("Pt09", "All tracks (pT>0.9 GeV)"),
183  ("highPurity", "High purity tracks"),
184  ("highPurityPt09", "High purity tracks (pT>0.9 GeV)"),
185  ("tpPtLess09", _tpPtLess09Name),
186  ("tpPtLess09_highPurity", _allToHP(_tpPtLess09Name)),
187  ("tpEtaGreater2p7", _tpEtaGreater2p7Name),
188  ("tpEtaGreater2p7_highPurity", _allToHP(_tpEtaGreater2p7Name)),
189  ("btvLike", "BTV-like"),
190  ("ak4PFJets", "AK4 PF jets"),
191  ("allTPEffic", _allTPEfficName),
192  ("allTPEffic_highPurity", _allToHP(_allTPEfficName)),
193  ("fromPV", _fromPVName),
194  ("fromPV_highPurity", "High purity "+_lowerFirst(_fromPVName)),
195  ("fromPVAllTP", _fromPVAllTPName),
196  ("fromPVAllTP_highPurity", "High purity "+_lowerFirst(_fromPVAllTPName)),
197  ("conversion", _conversionName),
198  ("gsf", _gsfName),
199  ("bhadron", _bhadronName),
200  ("bhadron_highPurity", _allToHP(_bhadronName)),
201  # Pixel tracks
202  ("pixel", "Pixel tracks"),
203  # These are for vertices
204  ("genvertex", "Gen vertices"),
205  ("pixelVertices", "Pixel vertices"),
206  ("selectedPixelVertices", "Selected pixel vertices"),
207  ("firstStepPrimaryVerticesPreSplitting", "firstStepPrimaryVerticesPreSplitting"),
208  ("firstStepPrimaryVertices", "firstStepPrimaryVertices"),
209  ("offlinePrimaryVertices", "All vertices (offlinePrimaryVertices)"),
210  ("selectedOfflinePrimaryVertices", "Selected vertices (selectedOfflinePrimaryVertices)"),
211  ("offlinePrimaryVerticesWithBS", "All vertices with BS constraint"),
212  ("selectedOfflinePrimaryVerticesWithBS", "Selected vertices with BS constraint"),
213  # These are for V0
214  ("k0", "K0"),
215  ("lambda", "Lambda"),
216 ])
217 _btvLegend = "BTV-like selected tracks"
218 _allTPEfficLegend = "All tracks, efficiency denominator contains all TrackingParticles"
219 _fromPVLegend = "Tracks from reco PV vs. TrackingParticles from gen PV (fake rate includes pileup tracks)"
220 _fromPVPtLegend = "Tracks (pT > 0.9 GeV) from reco PV vs. TrackingParticles from gen PV (fake rate includes pileup tracks)"
221 _fromPVAllTPLegend = "Tracks from reco PV, fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
222 _fromPVAllTPPtLegend = "Tracks (pT > 0.9 GeV) from reco PV, fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
223 _fromPVAllTP2Legend = "Tracks from reco PV (another method), fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
224 _fromPVAllTPPt2Legend = "Tracks (pT > 0.9 GeV) from reco PV (another method), fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
225 _bhadronLegend = "All tracks, efficiency denominator contains only TrackingParticles from B-hadron decays"
226 
228  return {
229  "btvLike": _btvLegend,
230  "ak4PFJets": "Tracks from AK4 PF jets (jet corrected pT > 10 GeV)",
231  "allTPEffic": _allTPEfficLegend,
232  "allTPEffic_": _allTPEfficLegend,
233  "allTPEffic_highPurity": _allToHP(_allTPEfficLegend),
234  "fromPV": _fromPVLegend,
235  "fromPV_": _fromPVLegend,
236  "fromPV_highPurity": _toHP(_fromPVLegend),
237  "fromPV_Pt09": _fromPVPtLegend,
238  "fromPV_highPurity_Pt09": _toHP(_fromPVPtLegend),
239  "fromPVAllTP": _fromPVAllTPLegend,
240  "fromPVAllTP_": _fromPVAllTPLegend,
241  "fromPVAllTP_highPurity": _toHP(_fromPVAllTPLegend),
242  "fromPVAllTP_Pt09": _fromPVAllTPPtLegend,
243  "fromPVAllTP_highPurityPt09": _toHP(_fromPVAllTPPtLegend),
244  "fromPVAllTP2_": _fromPVAllTP2Legend,
245  "fromPVAllTP2_highPurity": _toHP(_fromPVAllTP2Legend),
246  "fromPVAllTP2_Pt09": _fromPVAllTPPt2Legend,
247  "fromPVAllTP2_highPurityPt09": _toHP(_fromPVAllTPPt2Legend),
248  "bhadron_": _bhadronLegend,
249  "bhadron_highPurity": _allToHP(_bhadronLegend),
250  "bhadron_btvLike": _bhadronLegend.replace("All tracks", _btvLegend),
251  }
252 
253 class Table:
254  # table [column][row]
255  def __init__(self, columnHeaders, rowHeaders, table, purpose, page, section):
256  if len(columnHeaders) != len(table):
257  raise Exception("Got %d columnHeaders for table with %d columns for page %s, section %s" % (len(columnHeaders), len(table), page, section))
258  lenRow = len(table[0])
259  for icol, column in enumerate(table):
260  if len(column) != lenRow:
261  raise Exception("Got non-square table, first column has %d rows, column %d has %d rows" % (lenRow, icol, len(column)))
262  if len(rowHeaders) != lenRow:
263  raise Exception("Got %d rowHeaders for table with %d rows" % (len(rowHeaders), lenRow))
264 
265  self._columnHeaders = columnHeaders
266  self._rowHeaders = rowHeaders
267  self._table = table
268 
269  self._purpose = purpose
270  self._page = page
271  self._section = section
272 
273  def getPurpose(self):
274  return self._purpose
275 
276  def getPage(self):
277  return self._page
278 
279  def getSection(self):
280  return self._section
281 
282  def ncolumns(self):
283  return len(self._table)
284 
285  def nrows(self):
286  return len(self._table[0])
287 
288  def columnHeaders(self):
289  return self._columnHeaders
290 
291  def rowHeaders(self):
292  return self._rowHeaders
293 
294  def tableAsColumnRow(self):
295  return self._table
296 
297  def tableAsRowColumn(self):
298  return map(list, zip(*self._table))
299 
301  class TrackingIteration: pass
302  class TrackingSummary: pass
303  class Vertexing: pass
304  class MiniAOD: pass
305  class Timing: pass
306  class HLT: pass
307  class Pixel: pass
308  class PF: pass
309 
310 class Page(object):
311  def __init__(self, title, sampleName):
312  self._content = [
313  '<html>',
314  ' <head>',
315  ' <title>%s</title>' % title,
316  ' </head>',
317  ' <body>',
318  ' '+sampleName,
319  ' <br/>',
320  ' <br/>',
321  ]
322 
323  self._plotSets = {}
324  self._tables = {}
325 
326  def addPlotSet(self, section, plotSet):
327  if section in self._plotSets:
328  self._plotSets[section].extend(plotSet)
329  else:
330  self._plotSets[section] = plotSet
331 
332  def addTable(self, section, table):
333  self._tables[section] = table
334 
335  def isEmpty(self):
336  for plotSet in six.itervalues(self._plotSets):
337  if len(plotSet) > 0:
338  return False
339 
340  if len(self._tables) > 0:
341  return False
342 
343  return True
344 
345  def write(self, fileName):
346  self._legends = []
348  self._columnHeaders = []
350  self._formatPlotSets()
351  self._formatTables()
352  self._formatLegend()
353 
354  self._content.extend([
355  ' </body>',
356  '</html>',
357  ])
358 
359  #print "Writing HTML report page", fileName
360  f = open(fileName, "w")
361  for line in self._content:
362  f.write(line)
363  f.write("\n")
364  f.close()
365 
366  def _appendLegend(self, section):
367  leg = ""
368  legends = _sectionNameLegend()
369  if section in legends:
370  if section in self._sectionLegendIndex:
371  leg = self._sectionLegendIndex[section]
372  else:
373  legnum = len(self._legends)+1
374  leg = "<sup>%d</sup>" % legnum
375  leg2 = "<sup>%d)</sup>" % legnum
376  self._legends.append("%s %s" % (leg2, legends[section]))
377  self._sectionLegendIndex[section] = leg
378  return leg
379 
380  def _formatPlotSets(self):
381  self._content.extend([
382  ' <table>'
383  ' <tr>',
384  ])
385 
386  fileTable = []
387 
388  sections = self._orderSets(self._plotSets.keys())
389  for isec, section in enumerate(sections):
390  leg = self._appendLegend(section)
391 
392  self._content.extend([
393  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
394  ])
395  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
396  for row in fileTable:
397  found = False
398  for i, (bsf, f) in enumerate(files):
399  if bsf == row[0]:
400  row.append(f)
401  found = True
402  del files[i]
403  break
404  if not found:
405  row.append(None)
406  for bsf, f in files:
407  fileTable.append( [bsf] + [None]*isec + [f] )
408 
409  self._content.extend([
410  ' </tr>',
411  ])
412 
413  for row in fileTable:
414  self._content.append(' <tr>')
415  bs = row[0]
416  for elem in row[1:]:
417  if elem is not None:
418  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
419  else:
420  self._content.append(' <td></td>')
421  self._content.append(' </tr>')
422 
423 
424  self._content.extend([
425  ' </table>',
426  ])
427 
428  if len(fileTable):
429  first_row = fileTable[0]
430  self._content.extend([
431  ' <a href="%s">Browse Folder</a>' % (first_row[1][0:first_row[1].rfind('/')])
432  ])
433 
434  def _appendColumnHeader(self, header):
435  leg = ""
436  if header in self._columnHeadersIndex:
437  leg = self._columnHeadersIndex[header]
438  else:
439  leg = str(chr(ord('A')+len(self._columnHeaders)))
440  self._columnHeaders.append("%s: %s" % (leg, header))
441  self._columnHeadersIndex[header] = leg
442  return leg
443 
444  def _formatTables(self):
445  def _allNone(row):
446  for item in row:
447  if item is not None:
448  return False
449  return True
450 
451  sections = self._orderSets(self._tables.keys())
452  for isec, section in enumerate(sections):
453  leg = self._appendLegend(section)
454 
455  table = self._tables[section]
456  self._content.extend([
457  ' <br/>',
458  ' %s%s' % (self._mapSectionName(section), leg),
459  ' <table border="1">'
460  ])
461 
462  # table is stored in column-row, need to transpose
463  data = table.tableAsRowColumn()
464 
465  self._content.extend([
466  ' <tr>'
467  ' <td></td>'
468  ])
469  heads = table.columnHeaders()
470  if max(map(lambda h: len(h), heads)) > 20:
471  heads = [self._appendColumnHeader(h) for h in heads]
472  for head in heads:
473  self._content.append(' <td>%s</td>' % head)
474  self._content.append(' </tr>')
475 
476  for irow, row in enumerate(data):
477  # Skip row if all values are non-existent
478  if _allNone(row):
479  continue
480 
481  self._content.extend([
482  ' <tr>'
483  ' <td>%s</td>' % table.rowHeaders()[irow]
484  ])
485  # align the number columns to right
486  for icol, item in enumerate(row):
487  formatted = str(item) if item is not None else ""
488  self._content.append(' <td align="right">%s</td>' % formatted)
489  self._content.append(' </tr>')
490 
491  self._content.append(' </table>')
492 
493  for shortenedColumnHeader in self._columnHeaders:
494  self._content.append(' %s<br/>' % shortenedColumnHeader)
495  self._columnHeaders = []
496  self._columnHeadersIndex = {}
497 
498  def _formatLegend(self):
499  if len(self._legends) > 0:
500  self._content.extend([
501  ' <br/>'
502  ' Details:</br>',
503  ])
504  for leg in self._legends:
505  self._content.append(' %s<br/>' % leg)
506 
507 
508  def _mapSectionName(self, section):
509  return _sectionNameMapOrder.get(section, section)
510 
511  def _orderSets(self, keys):
512  keys_sorted = sorted(keys)
513  ret = []
514  for section in _sectionNameMapOrder.keys():
515  if section in keys_sorted:
516  ret.append(section)
517  keys_sorted.remove(section)
518  ret.extend(keys_sorted)
519  return ret
520 
522  def __init__(self, title, sampleName, sample, fastVsFull, pileupComparison, dqmSubFolderTranslatedToSectionName=None):
523  self._title = title
524  self._sampleName = sampleName
525  self._pages = collections.OrderedDict()
526  self._dqmSubFolderTranslatedToSectionName = dqmSubFolderTranslatedToSectionName
527 
528  self._prefix = ""
529  if sample.fastsim():
530  self._prefix += "fast_"
531  if fastVsFull:
532  self._prefix += "full_"
533 
534  self._prefix += _sampleFileName.get(sample.label(), sample.label())+"_"
535  if hasattr(sample, "hasScenario") and sample.hasScenario():
536  self._prefix += sample.scenario()+"_"
537 
538  if hasattr(sample, "hasPileup"):
539  if sample.hasPileup():
540  self._prefix += "pu"+str(sample.pileupNumber())+"_"+sample.pileupType()+"_"
541  else:
542  self._prefix += "nopu_"
543  if pileupComparison:
544  self._prefix += "vspu_"
545 
546 
547  def _getPage(self, key, pageClass):
548  if key not in self._pages:
549  page = pageClass(self._title, self._sampleName)
550  self._pages[key] = page
551  else:
552  page = self._pages[key]
553  return page
554 
555  def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles):
556  pageKey = plotterFolder.getPage()
557  if pageKey is None:
558  if dqmSubFolder is not None:
559  pageKey = dqmSubFolder.translated
560  else:
561  pageKey = plotterFolder.getName()
562 
563  page = self._getPage(pageKey, Page)
564  sectionName = plotterFolder.getSection()
565  if sectionName is None:
566  if plotterFolder.getPage() is not None and dqmSubFolder is not None:
567  if self._dqmSubFolderTranslatedToSectionName is not None:
568  sectionName = self._dqmSubFolderTranslatedToSectionName(dqmSubFolder.translated)
569  else:
570  sectionName = dqmSubFolder.translated
571  else:
572  sectionName = ""
573 
574  page.addPlotSet(sectionName, plotFiles)
575 
576  def addTable(self, table):
577  if table is None:
578  return
579 
580  page = self._getPage(table.getPage(), Page)
581  page.addTable(table.getSection(), table)
582 
583  def write(self, baseDir):
584  #print "TrackingPageSet.write"
585  ret = []
586 
587  keys = self._orderPages(self._pages.keys())
588  for key in keys:
589  page = self._pages[key]
590  if page.isEmpty():
591  continue
592 
593  fileName = "%s%s.html" % (self._prefix, key)
594  page.write(os.path.join(baseDir, fileName))
595  ret.append( (self._mapPagesName(key), fileName) )
596  return ret
597 
598  def _mapPagesName(self, name):
599  return _pageNameMap.get(name, name)
600 
601  def _orderPages(self, keys):
602  return keys
603 
604 
605 
607  def __init__(self, *args, **kwargs):
608  super(TrackingIterPage, self).__init__(*args, **kwargs)
609 
610  def _mapSectionName(self, quality):
611  return _trackQualityNameOrder.get(quality, quality)
612 
613  def _orderSets(self, qualities):
614  ret = []
615  for qual in _trackQualityNameOrder.keys():
616  if qual in qualities:
617  ret.append(qual)
618  qualities.remove(qual)
619  ret.extend(qualities)
620  return ret
621 
623  def __init__(self, *args, **kwargs):
624  super(TrackingPageSet, self).__init__(*args, **kwargs)
625 
626  def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles):
627  (algo, quality) = dqmSubFolder.translated
628 
629  pageName = algo
630  sectionName = quality
631 
632  # put all non-iterative stuff under OOTB
633  #
634  # it is bit of a hack to access trackingPlots.TrackingPlotFolder this way,
635  # but it was simple and it works
636  if algo != "ootb" and not plotterFolder._plotFolder.isAlgoIterative(algo):
637  pageName = "ootb"
638  sectionName = algo
639 
640  folderName = plotterFolder.getName()
641  if folderName != "":
642  sectionName = folderName+"_"+sectionName
643 
644  page = self._getPage(pageName, TrackingIterPage)
645  page.addPlotSet(sectionName, plotFiles)
646 
647  def _mapPagesName(self, algo): # algo = pageName
648  return _trackAlgoName.get(algo, algo)
649 
650  def _orderPages(self, algos):
651  ret = []
652  for algo in _trackAlgoOrder:
653  if algo in algos:
654  ret.append(algo)
655  algos.remove(algo)
656  ret.extend(algos)
657  return ret
658 
659 
660 
662  def __init__(self, sample, title, fastVsFull, pileupComparison):
663  self._sample = sample
664 
665  self._sampleName = ""
666  if sample.fastsim():
667  self._sampleName += "FastSim "
668  if fastVsFull:
669  self._sampleName += "vs FullSim "
670 
671  pileup = ""
672  if hasattr(sample, "hasPileup"):
673  pileup = "with no pileup"
674  if sample.hasPileup():
675  pileup = "with %d pileup (%s)" % (sample.pileupNumber(), sample.pileupType())
676  if pileupComparison is not None:
677  pileup += " "+pileupComparison
678  if hasattr(sample, "customPileupLabel"):
679  pileup = sample.customPileupLabel()
680 
681  scenario = ""
682  if hasattr(sample, "hasScenario") and sample.hasScenario():
683  scenario = " (\"%s\")" % sample.scenario()
684  self._sampleName += "%s sample%s %s" % (_sampleName.get(sample.name(), sample.name()), scenario, pileup)
685 
686  params = [title, self._sampleName, sample, fastVsFull, pileupComparison is not None]
687  self._summaryPage = PageSet(*params)
689  self._vertexPage = PageSet(*params)
690  self._miniaodPage = PageSet(*params)
691  self._timingPage = PageSet(*params)
692  self._pfPages = PageSet(*params)
693  self._hltPages = PageSet(*params, dqmSubFolderTranslatedToSectionName=lambda algoQuality: algoQuality[0])
694  self._pixelPages = PageSet(*params, dqmSubFolderTranslatedToSectionName=lambda algoQuality: algoQuality[0])
695  self._otherPages = PageSet(*params)
696 
703  PlotPurpose.PF: self._pfPages,
706  }
707 
708  def addPlots(self, plotterFolder, dqmSubFolder, plotFiles):
709  page = self._purposePageMap.get(plotterFolder.getPurpose(), self._otherPages)
710  page.addPlotSet(plotterFolder, dqmSubFolder, plotFiles)
711 
712  def addTable(self, table):
713  if table is None:
714  return
715 
716  page = self._purposePageMap.get(table.getPurpose(), self._otherPages)
717  page.addTable(table)
718  params = []
719 
720  def write(self, baseDir):
721  ret = [
722  " "+self._sampleName,
723  " <br/>",
724  " <ul>",
725  ]
726 
727  for pages in [self._summaryPage, self._iterationPages, self._pixelPages, self._vertexPage, self._miniaodPage, self._timingPage, self._hltPages, self._pfPages, self._otherPages]:
728  labelFiles = pages.write(baseDir)
729  for label, fname in labelFiles:
730  ret.append(' <li><a href="%s">%s</a></li>' % (fname, label))
731 
732  ret.extend([
733  ' </ul>',
734  ' <br/>',
735  ])
736 
737  return ret
738 
740  def __init__(self, validationName, newBaseDir):
741  self._title = "Tracking validation "+validationName
742  self._newBaseDir = newBaseDir
743 
744  self._index = [
745  '<html>',
746  ' <head>',
747  ' <title>%s</title>' % self._title,
748  ' </head>',
749  ' <body>',
750  ]
751 
752  self._sections = collections.OrderedDict()
753 
754  def addNote(self, note):
755  self._index.append(' <p>%s</p>'%note)
756 
757  def beginSample(self, sample, fastVsFull=False, pileupComparison=None):
758  # Fast vs. Full becomes just after the corresponding Fast
759  # Same for PU
760  rightAfterRefSample = fastVsFull or (pileupComparison is not None)
761 
762  key = (sample.digest(), rightAfterRefSample)
763  if key in self._sections:
764  self._currentSection = self._sections[key]
765  else:
766  self._currentSection = IndexSection(sample, self._title, fastVsFull, pileupComparison)
767  self._sections[key] = self._currentSection
768 
769  def addPlots(self, *args, **kwargs):
770  self._currentSection.addPlots(*args, **kwargs)
771 
772  def addTable(self, *args, **kwargs):
773  self._currentSection.addTable(*args, **kwargs)
774 
775  def write(self):
776  # Reorder sections such that Fast vs. Full becomes just after the corresponding Fast
777  keys = self._sections.iterkeys()
778  newkeys = []
779  for key in keys:
780  if not key[1]:
781  newkeys.append(key)
782  continue
783  # is fast vs full
784  ind_fast = newkeys.index( (key[0], False) )
785  newkeys.insert(ind_fast+1, key)
786 
787  for key in newkeys:
788  section = self._sections[key]
789  self._index.extend(section.write(self._newBaseDir))
790 
791  self._index.extend([
792  " </body>",
793  "</html>",
794  ])
795 
796  f = open(os.path.join(self._newBaseDir, "index.html"), "w")
797  for line in self._index:
798  f.write(line)
799  f.write("\n")
800  f.close()
801 
803  def __init__(self):
804  pass
805 
806  def beginSample(self, *args, **kwargs):
807  pass
808 
809  def addPlots(self, *args, **kwargs):
810  pass
811 
812  def addTable(self, *args, **kwargs):
813  pass
html.IndexSection
Definition: html.py:661
html.Page.addTable
def addTable(self, section, table)
Definition: html.py:332
html.IndexSection._timingPage
_timingPage
Definition: html.py:691
html.HtmlReport.addTable
def addTable(self, *args, **kwargs)
Definition: html.py:772
html.TrackingPageSet.__init__
def __init__(self, *args, **kwargs)
Definition: html.py:623
html.PageSet._pages
_pages
Definition: html.py:525
html.Page.addPlotSet
def addPlotSet(self, section, plotSet)
Definition: html.py:326
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
html.PlotPurpose.TrackingIteration
Definition: html.py:301
html.HtmlReport.write
def write(self)
Definition: html.py:775
html._toOriAlgo
def _toOriAlgo(s)
Definition: html.py:57
html.Page._appendLegend
def _appendLegend(self, section)
Definition: html.py:366
html.IndexSection._iterationPages
_iterationPages
Definition: html.py:688
html.HtmlReportDummy.__init__
def __init__(self)
Definition: html.py:803
html._allToBTV
def _allToBTV(s)
Definition: html.py:63
html.Table.getSection
def getSection(self)
Definition: html.py:279
html.TrackingIterPage._orderSets
def _orderSets(self, qualities)
Definition: html.py:613
html.TrackingPageSet
Definition: html.py:622
html.Table._columnHeaders
_columnHeaders
Definition: html.py:265
html.PlotPurpose.MiniAOD
Definition: html.py:304
html.PlotPurpose.HLT
Definition: html.py:306
html._lowerFirst
def _lowerFirst(s)
Definition: html.py:5
html.Page._formatTables
def _formatTables(self)
Definition: html.py:444
html.HtmlReportDummy
Definition: html.py:802
html.Page._orderSets
def _orderSets(self, keys)
Definition: html.py:511
html.Table.tableAsColumnRow
def tableAsColumnRow(self)
Definition: html.py:294
html._sectionNameLegend
def _sectionNameLegend()
Definition: html.py:227
html.Page._content
_content
Definition: html.py:312
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
html.PageSet.addPlotSet
def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:555
html.PageSet._prefix
_prefix
Definition: html.py:528
html.HtmlReport.addNote
def addNote(self, note)
Definition: html.py:754
html.PageSet._title
_title
Definition: html.py:523
html.HtmlReport._title
_title
Definition: html.py:741
html.PlotPurpose.Timing
Definition: html.py:305
html.Page.__init__
def __init__(self, title, sampleName)
Definition: html.py:311
html.Table
Definition: html.py:253
html.PageSet._getPage
def _getPage(self, key, pageClass)
Definition: html.py:547
html.Page._legends
_legends
Definition: html.py:346
html.Table.tableAsRowColumn
def tableAsRowColumn(self)
Definition: html.py:297
html._toAlgoMask
def _toAlgoMask(s)
Definition: html.py:59
html.IndexSection.addPlots
def addPlots(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:708
html.IndexSection._purposePageMap
_purposePageMap
Definition: html.py:697
str
#define str(s)
Definition: TestProcessor.cc:48
html.PageSet._mapPagesName
def _mapPagesName(self, name)
Definition: html.py:598
html.IndexSection._sample
_sample
Definition: html.py:663
html.IndexSection._sampleName
_sampleName
Definition: html.py:665
html.Page
Definition: html.py:310
html._ptCut
def _ptCut(s)
Definition: html.py:65
html.Table.columnHeaders
def columnHeaders(self)
Definition: html.py:288
html.HtmlReport.addPlots
def addPlots(self, *args, **kwargs)
Definition: html.py:769
html.PageSet._sampleName
_sampleName
Definition: html.py:524
html.PlotPurpose.Pixel
Definition: html.py:307
html._toHP
def _toHP(s)
Definition: html.py:55
html.PlotPurpose.TrackingSummary
Definition: html.py:302
html.PageSet.write
def write(self, baseDir)
Definition: html.py:583
html.Page.write
def write(self, fileName)
Definition: html.py:345
html.HtmlReport._index
_index
Definition: html.py:744
html.PageSet.__init__
def __init__(self, title, sampleName, sample, fastVsFull, pileupComparison, dqmSubFolderTranslatedToSectionName=None)
Definition: html.py:522
html.Page._formatLegend
def _formatLegend(self)
Definition: html.py:498
html.HtmlReport._sections
_sections
Definition: html.py:752
html.IndexSection._summaryPage
_summaryPage
Definition: html.py:687
html.Page._sectionLegendIndex
_sectionLegendIndex
Definition: html.py:347
html.PlotPurpose.Vertexing
Definition: html.py:303
html.PlotPurpose
Definition: html.py:300
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
html.Page._formatPlotSets
def _formatPlotSets(self)
Definition: html.py:380
html.HtmlReport.__init__
def __init__(self, validationName, newBaseDir)
Definition: html.py:740
Exception
mps_setup.append
append
Definition: mps_setup.py:85
html.IndexSection._pfPages
_pfPages
Definition: html.py:692
html.Page._tables
_tables
Definition: html.py:324
html.TrackingIterPage
Definition: html.py:606
html.HtmlReport._newBaseDir
_newBaseDir
Definition: html.py:742
html.PageSet._orderPages
def _orderPages(self, keys)
Definition: html.py:601
html.Table._rowHeaders
_rowHeaders
Definition: html.py:266
html.HtmlReportDummy.beginSample
def beginSample(self, *args, **kwargs)
Definition: html.py:806
html.HtmlReportDummy.addPlots
def addPlots(self, *args, **kwargs)
Definition: html.py:809
html.Page._mapSectionName
def _mapSectionName(self, section)
Definition: html.py:508
html.Table.ncolumns
def ncolumns(self)
Definition: html.py:282
html.HtmlReport._currentSection
_currentSection
Definition: html.py:764
html.TrackingPageSet._mapPagesName
def _mapPagesName(self, algo)
Definition: html.py:647
html.Table.nrows
def nrows(self)
Definition: html.py:285
html.TrackingPageSet.addPlotSet
def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:626
html.Table._purpose
_purpose
Definition: html.py:269
html._allToHP
def _allToHP(s)
Definition: html.py:61
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:38
html.IndexSection._vertexPage
_vertexPage
Definition: html.py:689
html.Table.rowHeaders
def rowHeaders(self)
Definition: html.py:291
html.HtmlReportDummy.addTable
def addTable(self, *args, **kwargs)
Definition: html.py:812
html.TrackingIterPage._mapSectionName
def _mapSectionName(self, quality)
Definition: html.py:610
html.IndexSection.__init__
def __init__(self, sample, title, fastVsFull, pileupComparison)
Definition: html.py:662
html.Table.getPurpose
def getPurpose(self)
Definition: html.py:273
html.IndexSection._otherPages
_otherPages
Definition: html.py:695
html.PageSet
Definition: html.py:521
html.IndexSection.write
def write(self, baseDir)
Definition: html.py:720
html.IndexSection._pixelPages
_pixelPages
Definition: html.py:694
html.Page._columnHeadersIndex
_columnHeadersIndex
Definition: html.py:349
html.Page._columnHeaders
_columnHeaders
Definition: html.py:348
html.IndexSection._hltPages
_hltPages
Definition: html.py:693
html.Table._table
_table
Definition: html.py:267
html.TrackingIterPage.__init__
def __init__(self, *args, **kwargs)
Definition: html.py:607
html.IndexSection.addTable
def addTable(self, table)
Definition: html.py:712
html.PlotPurpose.PF
Definition: html.py:308
html.Page._appendColumnHeader
def _appendColumnHeader(self, header)
Definition: html.py:434
genParticles_cff.map
map
Definition: genParticles_cff.py:11
html.Table.getPage
def getPage(self)
Definition: html.py:276
html.IndexSection._miniaodPage
_miniaodPage
Definition: html.py:690
html.Page._plotSets
_plotSets
Definition: html.py:323
html.TrackingPageSet._orderPages
def _orderPages(self, algos)
Definition: html.py:650
html.Page.isEmpty
def isEmpty(self)
Definition: html.py:335
html.Table._page
_page
Definition: html.py:270
html.HtmlReport.beginSample
def beginSample(self, sample, fastVsFull=False, pileupComparison=None)
Definition: html.py:757
html.Table._section
_section
Definition: html.py:271
html.Table.__init__
def __init__(self, columnHeaders, rowHeaders, table, purpose, page, section)
Definition: html.py:255
html.PageSet._dqmSubFolderTranslatedToSectionName
_dqmSubFolderTranslatedToSectionName
Definition: html.py:526
html.HtmlReport
Definition: html.py:739
html.PageSet.addTable
def addTable(self, table)
Definition: html.py:576
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444