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