CMS 3D CMS Logo

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